function injectScriptElement(targetWindow, doc) {
  var Node = targetWindow.Node;
  var HTMLDocument = targetWindow.HTMLDocument;
  var HTMLScriptElement = targetWindow.HTMLScriptElement;
  var proto = HTMLScriptElement.prototype;

  // Listen for sets on innerText.
  // Listen for sets on src.
  // Track when added to DOM via appendChild.

  // Replace appendChild/etc so that we can watch for script adds.
  var originalAppendChild = Node.prototype.appendChild;
  Node.prototype.appendChild = function appendChild(newChild) {
    if (newChild instanceof HTMLScriptElement && !newChild['__wtfi__']) {
      // appendChild(<script>)
      log('appendChild of script', newChild);
      var baseUrl = arguments.callee.caller ?
          arguments.callee.caller['__src'] : null;
      var processedChild = processScript(newChild, false, baseUrl);
      return originalAppendChild.call(this, processedChild);
    } else {
      return originalAppendChild.apply(this, arguments);
    }
  };
  var originalInsertBefore = Node.prototype.insertBefore;
  Node.prototype.insertBefore = function insertBefore(newChild, refChild) {
    if (newChild instanceof HTMLScriptElement && !newChild['__wtfi__']) {
      // insertBefore(<script>, ...)
      log('insertBefore of script', newChild);
      var baseUrl = arguments.callee.caller ?
          arguments.callee.caller['__src'] : null;
      var processedChild = processScript(newChild, false, baseUrl);
      return originalInsertBefore.call(this, processedChild, refChild);
    } else {
      return originalInsertBefore.apply(this, arguments);
    }
  };
  var originalReplaceChild = Node.prototype.replaceChild;
  Node.prototype.replaceChild = function replaceChild(
      newChild, oldChild) {
    if (newChild instanceof HTMLScriptElement && !newChild['__wtfi__']) {
      // replaceChild(<script>, ...)
      log('insertBefore of script', newChild);
      var baseUrl = arguments.callee.caller ?
          arguments.callee.caller['__src'] : null;
      var processedChild = processScript(newChild, false, baseUrl);
      return originalReplaceChild.call(this, processedChild, oldChild);
    } else {
      return originalReplaceChild.apply(this, arguments);
    }
  };

  // Replace document.createElement so we can hook new script elements.
  // var originalCreateElement = HTMLDocument.prototype.createElement;
  // HTMLDocument.prototype.createElement = function createElement(tagName) {
  //   if (tagName.toLowerCase() == 'script') {
  //     // <script>.
  //     var result = originalCreateElement.apply(this, arguments);
  //     log('could instrument <script>', result);
  //     return result;
  //   } else {
  //     return originalCreateElement.apply(this, arguments);
  //   }
  // };
}
Replaces the <script> tag with our own instrumented version.
@param {!Document} doc Target document object.
@param {!Window} targetWindow Window.