Search code examples
firefox-addonfirefox-addon-sdk

Firefox addon opens tab with content, copy/paste of the tabs url will not load page fully


I have an addon that places an ActionButton on the toolbar. When the ActionButton is clicked the code below is run.

The code opens a new tab and provides some html and js, this acts as the addon's UI.

The url of the new tab is:

resource://jid1-qljswfs6someid-at-jetpack/addon-firefox/data/html/view.html

If I copy/paste that url into another new tab manually, the html displays but the js logic is not loaded. Is there a way to do this without clicking the ActionButton? So I could maybe bookmark the addon instead of having the ActionButton take up space.

Code:

Tabs.open({
  url: require("sdk/self").data.url('html/view.html'),
  onReady: function onReady(tab) {

    worker = tab.attach({
      contentScriptFile: [
        require("sdk/self").data.url.get('lib/lib1.js'),
        require("sdk/self").data.url.get('js/lib1.js')
      ],
      onMessage: function(message) {

        console.log('stuff done');
      }
    });
  }
});

Solution

  • In order to run it whenever the site from data.url('html/view.html') is loaded you would have to use page-mod instead of manually attaching to the document to the tab.

    Your include pattern would be something like data.url('html/view.html') + "*", so it also attaches to the page if there is a hash or a query to the document.