extensions/wtf-injector-firefox/data/content-script.js
function injectScriptFunction(fn, opt_args) {
  // Format args as strings that can go in the source.
  var args = opt_args || [];
  for (var n = 0; n < args.length; n++) {
    if (args[n] === undefined) {
      args[n] = 'undefined';
    } else if (args[n] === null) {
      args[n] = 'null';
    } else if (typeof args[n] == 'string') {
      // TODO(benvanik): escape
      args[n] = '"' + args[n] + '"';
    } else if (typeof args[n] == 'object') {
      args[n] = JSON.stringify(args[n]);
    }
  }
  args = args.join(',');

  // TODO(benvanik): escape fn source
  var source = [
    '(' + String(fn) + ')(' + args + ');',
    '// Web Tracing Framework injected function: ' + fn.name,
    '//# sourceURL=x://wtf-injector/' + fn.name
  ].join('\n');

  // Create script tag.
  var script = document.createElement('script');
  script.text = source;

  // Add to page.
  injectScriptTag(script);
}
function injectScriptFunction(fn, opt_args) {
  // Format args as strings that can go in the source.
  var args = opt_args || [];
  for (var n = 0; n < args.length; n++) {
    if (args[n] === undefined) {
      args[n] = 'undefined';
    } else if (args[n] === null) {
      args[n] = 'null';
    } else if (typeof args[n] == 'string') {
      // TODO(benvanik): escape
      args[n] = '"' + args[n] + '"';
    } else if (typeof args[n] == 'object') {
      args[n] = JSON.stringify(args[n]);
    }
  }
  args = args.join(',');

  // TODO(benvanik): escape fn source
  var source = [
    '(' + String(fn) + ')(' + args + ');',
    '// Web Tracing Framework injected function: ' + fn.name,
    '//# sourceURL=x://wtf-injector/' + fn.name
  ].join('\n');

  // Create script tag.
  var script = document.createElement('script');
  script.text = source;

  // Add to page.
  injectScriptTag(script);
}
function injectScriptFunction ( fn , opt_args ) { // Format args as strings that can go in the source. var args = opt_args || [ ] ; for ( var n = 0 ; n < args . length ; n ++ ) { if ( args [ n ] === undefined ) { args [ n ] = 'undefined' ; } else if ( args [ n ] === null ) { args [ n ] = 'null' ; } else if ( typeof args [ n ] == 'string' ) { // TODO(benvanik): escape args [ n ] = '"' + args [ n ] + '"' ; } else if ( typeof args [ n ] == 'object' ) { args [ n ] = JSON . stringify ( args [ n ] ) ; } } args = args . join ( ',' ) ; // TODO(benvanik): escape fn source var source = [ '(' + String ( fn ) + ')(' + args + ');' , '// Web Tracing Framework injected function: ' + fn . name , '//# sourceURL=x://wtf-injector/' + fn . name ] . join ( '\n' ) ; // Create script tag. var script = document . createElement ( 'script' ) ; script . text = source ; // Add to page. injectScriptTag ( script ) ; }
Injects a function into the page.
@param {!Function} fn Function to inject.
@param {Array=} opt_args Arguments array. All must be string serializable.
Injects a function into the page .