How can I fix invalid injected HTML elements in the head

Hello, greetings to the community. I'm hoping anyone can help me. In Sitebull, when I run the audit, I get a critical error: What is this? URLs where the <head> element contains invalid DOM elements. Valid elements that can be used within the <head> element are <title>, <meta>, <base>, <link>, <script>, <noscript>, <style>, and <template>. Including invalid elements can cause the HTML document to not be parsed correctly, as the presence of other elements corrupts the <head> element, which can cause important tags (e.g., meta robots) to be overlooked.

Discovering by analyzing the code that it is an injection of invalid code is this: <iframe src="https://www.googletagmanager.com/ns.html?id=GT-EXAMPLE" height="0" width="0" style="display:none;visibility:hidden"></iframe> how could I reverse this critical error and pass the injection to the BODY
1 Like

Hi @JoseRP , can you please share your website url?

Also let me know if you have added google tag manager code manually in theme files or have you used app for that?

Hello @JoseRP

Step 1: Identify Where the Injection Happens
Since the invalid

Hi @goldi07

3.Injected via Third-Party Apps:

This is my case, the GOOGLE & YOUTUBE app is the one that is automatically injecting me into the HEAD, I contacted Google and they did not help me. Create this code with artificial intelligence that places it at the beginning of the HEAD

<script>  document.addEventListener('DOMContentLoaded', function() {
    // 1. Seleccionar SOLO los <noscript> del <head> que contengan elementos inválidos
    const invalidElements = ['iframe', 'img', 'div', 'h1', 'h2', 'h3']; // Elementos prohibidos
    const headNoscripts = document.head.querySelectorAll('noscript');

    headNoscripts.forEach(noscript => {
      // 2. Verificar si el <noscript> contiene elementos prohibidos
      const hasInvalidElement = invalidElements.some(tag => 
        noscript.innerHTML.toLowerCase().includes(`<${tag}`)
      );

      // 3. Mover solo si encuentra elementos inválidos
      if (hasInvalidElement) {
        document.body.appendChild(noscript);
        console.log('Elemento <noscript> inválido movido al <body>:', noscript.innerHTML);
      }
    });
  });
</script>
Now I test if it works, thank you very much for your support, really.

Hi @abdulmoeed37 https://www.motivecase.com/ It’s injected. I haven’t included the code, and it’s not in the theme editors. I only see it when I browse the site in developer mode. I just added some code to the top of the HEAD, but I haven’t run an audit yet to see if it’s fixed or if that code generated another error. Thank you very much for your help.