extensions/wtf-injector-firefox/lib/main.js
function enableInjectionForUrl(url) {
  var url = getCanonicalUrl(url);
  if (activePageMods[url]) {
    return;
  }

  // Enable injection.
  setPagePreference(url, 'enabled', true);

  // Grab current options. Note that if they change we need to re-enable
  // injection to update the pagemod.
  var pagePrefs = getPagePreferences(url);
  var storedOptions = {};
  try {
    storedOptions = JSON.parse(pagePrefs.options);
  } catch (e) {
  }
  // Override defaults with specified values.
  // Except for a few that we don't want to track across session.
  var pageOptions = {
    // The presence of this indicates that the options come from the injector.
    'wtf.injector': true,

    // Larger buffers mean less waste when doing recordings with a large amount
    // of data (like WebGL captures).
    'wtf.trace.session.bufferSize': 6 * 1024 * 1024,

    // This is pretty excessive, but keeps us from truncating WebGL traces.
    // After this limit the file likely won't load due to v8 memory limits
    // anyway.
    'wtf.trace.session.maximumMemoryUsage': 512 * 1024 * 1024,

    // TODO(benvanik): endpoints
    // 'wtf.hud.app.mode': '',
    // 'wtf.hud.app.endpoint': '',

    'wtf.trace.provider.firefoxDebug.present': true,

    // Turn on embed remote images by default.
    // When we have the UI in the extension and can fetch non-origin URLs this
    // won't be required. Note that we allow the page to override this setting.
    'wtf.trace.provider.webgl.embedRemoteImages': true
  };
  for (var key in storedOptions) {
    switch (key) {
      case 'wtf.injector':
      case 'wtf.hud.app.mode':
      case 'wtf.hud.app.endpoint':
      case 'wtf.addons':
      case 'wtf.trace.provider.firefoxDebug.present':
        continue;
    }
    pageOptions[key] = storedOptions[key];
  }

  // Create a page mod for the given URLs.
  var mod = pageMod.PageMod({
    include: [
      url,
      url + '#*'
    ],
    contentScriptFile: self.data.url('content-script.js'),
    contentScriptWhen: 'start',
    contentScriptOptions: {
      // Accessible as self.options in the content script.
      wtfScriptContents: wtfScriptContents,
      wtfOptions: pageOptions
    },
    attachTo: 'top',
    onAttach: function(worker) {
      var injectedTab = new InjectedTab(url, worker);
      injectedTabs.push(injectedTab);
      console.log('added worker for ' + url);

      worker.port.on('page-event', function(data) {
        injectedTab.dispatchEvent(JSON.parse(data));
      });

      worker.on('detach', function() {
        console.log('detached worker for ' + url);
        injectedTab.dispose();
        for (var n = 0; n < injectedTabs.length; n++) {
          if (injectedTabs[n].worker == worker) {
            injectedTabs.splice(n, 1);
            break;
          }
        }

      });
    }
  });
  activePageMods[url] = mod;

  // Find tabs with the URL and reload.
  reloadTabsMatchingUrl(url);
}
function enableInjectionForUrl(url) {
  var url = getCanonicalUrl(url);
  if (activePageMods[url]) {
    return;
  }

  // Enable injection.
  setPagePreference(url, 'enabled', true);

  // Grab current options. Note that if they change we need to re-enable
  // injection to update the pagemod.
  var pagePrefs = getPagePreferences(url);
  var storedOptions = {};
  try {
    storedOptions = JSON.parse(pagePrefs.options);
  } catch (e) {
  }
  // Override defaults with specified values.
  // Except for a few that we don't want to track across session.
  var pageOptions = {
    // The presence of this indicates that the options come from the injector.
    'wtf.injector': true,

    // Larger buffers mean less waste when doing recordings with a large amount
    // of data (like WebGL captures).
    'wtf.trace.session.bufferSize': 6 * 1024 * 1024,

    // This is pretty excessive, but keeps us from truncating WebGL traces.
    // After this limit the file likely won't load due to v8 memory limits
    // anyway.
    'wtf.trace.session.maximumMemoryUsage': 512 * 1024 * 1024,

    // TODO(benvanik): endpoints
    // 'wtf.hud.app.mode': '',
    // 'wtf.hud.app.endpoint': '',

    'wtf.trace.provider.firefoxDebug.present': true,

    // Turn on embed remote images by default.
    // When we have the UI in the extension and can fetch non-origin URLs this
    // won't be required. Note that we allow the page to override this setting.
    'wtf.trace.provider.webgl.embedRemoteImages': true
  };
  for (var key in storedOptions) {
    switch (key) {
      case 'wtf.injector':
      case 'wtf.hud.app.mode':
      case 'wtf.hud.app.endpoint':
      case 'wtf.addons':
      case 'wtf.trace.provider.firefoxDebug.present':
        continue;
    }
    pageOptions[key] = storedOptions[key];
  }

  // Create a page mod for the given URLs.
  var mod = pageMod.PageMod({
    include: [
      url,
      url + '#*'
    ],
    contentScriptFile: self.data.url('content-script.js'),
    contentScriptWhen: 'start',
    contentScriptOptions: {
      // Accessible as self.options in the content script.
      wtfScriptContents: wtfScriptContents,
      wtfOptions: pageOptions
    },
    attachTo: 'top',
    onAttach: function(worker) {
      var injectedTab = new InjectedTab(url, worker);
      injectedTabs.push(injectedTab);
      console.log('added worker for ' + url);

      worker.port.on('page-event', function(data) {
        injectedTab.dispatchEvent(JSON.parse(data));
      });

      worker.on('detach', function() {
        console.log('detached worker for ' + url);
        injectedTab.dispose();
        for (var n = 0; n < injectedTabs.length; n++) {
          if (injectedTabs[n].worker == worker) {
            injectedTabs.splice(n, 1);
            break;
          }
        }

      });
    }
  });
  activePageMods[url] = mod;

  // Find tabs with the URL and reload.
  reloadTabsMatchingUrl(url);
}
function enableInjectionForUrl ( url ) { var url = getCanonicalUrl ( url ) ; if ( activePageMods [ url ] ) { return ; } // Enable injection. setPagePreference ( url , 'enabled' , true ) ; // Grab current options. Note that if they change we need to re-enable // injection to update the pagemod. var pagePrefs = getPagePreferences ( url ) ; var storedOptions = { } ; try { storedOptions = JSON . parse ( pagePrefs . options ) ; } catch ( e ) { } // Override defaults with specified values. // Except for a few that we don't want to track across session. var pageOptions = { // The presence of this indicates that the options come from the injector. 'wtf.injector' : true , // Larger buffers mean less waste when doing recordings with a large amount // of data (like WebGL captures). 'wtf.trace.session.bufferSize' : 6 * 1024 * 1024 , // This is pretty excessive, but keeps us from truncating WebGL traces. // After this limit the file likely won't load due to v8 memory limits // anyway. 'wtf.trace.session.maximumMemoryUsage' : 512 * 1024 * 1024 , // TODO(benvanik): endpoints // 'wtf.hud.app.mode': '', // 'wtf.hud.app.endpoint': '', 'wtf.trace.provider.firefoxDebug.present' : true , // Turn on embed remote images by default. // When we have the UI in the extension and can fetch non-origin URLs this // won't be required. Note that we allow the page to override this setting. 'wtf.trace.provider.webgl.embedRemoteImages' : true } ; for ( var key in storedOptions ) { switch ( key ) { case 'wtf.injector' : case 'wtf.hud.app.mode' : case 'wtf.hud.app.endpoint' : case 'wtf.addons' : case 'wtf.trace.provider.firefoxDebug.present' : continue ; } pageOptions [ key ] = storedOptions [ key ] ; } // Create a page mod for the given URLs. var mod = pageMod . PageMod ( { include : [ url , url + '#*' ] , contentScriptFile : self . data . url ( 'content-script.js' ) , contentScriptWhen : 'start' , contentScriptOptions : { // Accessible as self.options in the content script. wtfScriptContents : wtfScriptContents , wtfOptions : pageOptions } , attachTo : 'top' , onAttach : function ( worker ) { var injectedTab = new InjectedTab ( url , worker ) ; injectedTabs . push ( injectedTab ) ; console . log ( 'added worker for ' + url ) ; worker . port . on ( 'page-event' , function ( data ) { injectedTab . dispatchEvent ( JSON . parse ( data ) ) ; } ) ; worker . on ( 'detach' , function ( ) { console . log ( 'detached worker for ' + url ) ; injectedTab . dispose ( ) ; for ( var n = 0 ; n < injectedTabs . length ; n ++ ) { if ( injectedTabs [ n ] . worker == worker ) { injectedTabs . splice ( n , 1 ) ; break ; } } } ) ; } } ) ; activePageMods [ url ] = mod ; // Find tabs with the URL and reload. reloadTabsMatchingUrl ( url ) ; }
Enables injection for a URL and reloads tabs with that URL.
@param {string} url URL to activate on.
Enables injection for a URL and reloads tabs with that URL .