title: Inject javascript in XML file via content script
body: <p>I know xml shouldn't really have javascript in it but I'm making a browser extension that needs to inject some code on every page to provide the user with some interesting statistics.</p>
  
  <p>The problem is, I'm unable to get the injected code to run in XML documents as it looks like the script tag I create is treated as text?</p>
  
  <p>The same code works fine in HTML </p>
  
  <p>Here's what I have:</p>
  
  <p><strong>manifest.json</strong>:</p>
  
  <pre><code>"content_scripts": [
      {
        "matches": ["&lt;all_urls&gt;"],
          "all_frames": true,
          "match_about_blank": true,
          "run_at": "document_start",
          "js": ["scripts/content/countCalls.js"]
      }
    ]
  </code></pre>
  
  <p><strong>countCalls.js</strong>:</p>
  
  <pre><code>let injectedCode = 'console.log("Hello from injected code");';
  let script = document.createElement('script');
  script.appendChild(document.createTextNode(injectedCode));
  
  let parent = document.head || document.body || document.documentElement;
  let firstChild = (parent.childNodes &amp;&amp; (parent.childNodes.length &gt; 0)) ? parent.childNodes[0] : null;
  if (firstChild) {
    parent.insertBefore(script, firstChild);
  } else {
    parent.appendChild(script);
  }
  </code></pre>
  
  <p><strong>test.xml</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;main xmlns='http://www.w3.org/1999/xhtml'&gt;
  &lt;script&gt;
  console.log("Hello from XML");
  &lt;/script&gt;
  &lt;/main&gt;
  </code></pre>
  
  <p>When I load <code>test.xml</code> in the browser I see this:</p>
  
  <blockquote>
    <p>console.log("Hello from injected code");</p>
  </blockquote>
  
  <p>and in the console I just see this:</p>
  
  <blockquote>
    <p>Hello from XML</p>
  </blockquote>
  
  <p>So the injected code is being treated like text. Anyway around this? Otherwise intentionally adding javascript to xml will cause it to bypass the extension</p>