How I can alter reCAPTCHA script tag in html_head The reCaptcha module adds a Javascript with hook_captcha(). I want to add another attribute &quot;type&quot; to this script tag. I can't find a hook to achieve this.
Here is the code from the recaptcha.module (line 118):
$captcha['form']['recaptcha_widget'] = [
        '#markup' =&gt; '&lt;div' . new Attribute($attributes) . '&gt;&lt;/div&gt;',
        '#suffix' =&gt; $noscript,
        '#attached' =&gt; [
          'html_head' =&gt; [
            [
              [
                '#tag' =&gt; 'script',
                '#attributes' =&gt; [
                  'src' =&gt; Url::fromUri($recaptcha_src, ['query' =&gt; ['hl' =&gt; \Drupal::service('language_manager')-&gt;getCurrentLanguage()-&gt;getId()], 'absolute' =&gt; TRUE])-&gt;toString(),
                  'async' =&gt; TRUE,
                  'defer' =&gt; TRUE,
                ],
              ],
              'recaptcha_api',
            ],
          ],
        ],
      ];

When I try to access the script tag with e.g. hook_page_attachments_alter() or any other hook_preprocess_xxxx() it is missing. I also tried to increase my module weight.
I would suggest using a #process callback and avoid code duplication.
This is what such a solution could look like:
/**
 * Implements hook_element_info_alter().
 */
function my_module_element_info_alter(array &amp;$element) {
  if (isset($element['captcha'])) {
    $element['captcha']['#process'][] = '_custom_recaptcha_process';
  }
}

/**
 * Add type attribute to recaptcha form element.
 *
 * @return array
 *   The processed element.
 *
 * @see captcha_element_info()
 * @see image_captcha_element_info_alter()
 */
function _custom_recaptcha_process($element) {
  $recatchaWidgetHtmlHead = &amp;$element['captcha_widgets']['recaptcha_widget']['#attached']['html_head'] ?? [];
  array_walk($recatchaWidgetHtmlHead, function(&amp;$captcha_widget) { 
    if ($captcha_widget[1] === 'recaptcha_api') {
      $captcha_widget[0]['#attributes']['type'] = 'value';
    }
  });
  return $element;
}

and this would be the output:

Good luck!