Opening a new tab in multiprocess Firefox?

192 Views Asked by At

I am trying to port my existing firefox addon code to the new multiprocess architecture. In my existing code I am able to launch a new tab on the addon install event using the code below:

function install(data, aReason) {
    if (aReason == ADDON_INSTALL) {
        var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
            .getService(Components.interfaces.nsIWindowMediator);
        var mainWindow = wm.getMostRecentWindow("navigator:browser");
        mainWindow.gBrowser.addTab('http://www.mywebsite.org/install-success-page.html');

    }

    if (aReason == ADDON_UPGRADE) {

        var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
            .getService(Components.interfaces.nsIWindowMediator);
        var mainWindow = wm.getMostRecentWindow("navigator:browser");
        mainWindow.gBrowser.addTab('http://www.mywebsite.org/update-success-page.html');
    }

}

After making the changes to bootstrap.js to become multiprocess firefox compatible (using help from other extension's code) the addon loads and functions as expected but the above code fails to load a new tab and no error gets displayed in console !!!

1

There are 1 best solutions below

0
On

This should work:

var Cu = Components.utils;
var { require } = Cu.import(resource://gre/modules/Services.jsm", {});
const tabs = require("sdk/tabs");
tabs.open(url);

Also this is less likely to break in the future than any platform code.