firefox-addonfirefox-addon-sdkjpm

Bootstrapped extension with new jpm Firefox


I'm realizing a Firefox extension using one of the last (or the last) version of jpm (1.0.5) but the extension does not call the startup() or shutdown() methods. I know that should be mandatory to declare the extension as

<em:bootstrap>true</em:bootstrap>

into the install.rdf file, but when I have created my namespace (using jpm init) there was not this file, that it is replaced from package.json. In this case how I should modify the files to use startup and shutdown methods working?


Solution

  • In my main.js I listen for load and unload like this.

    exports.main = function(options, callbacks) {
        if (options.loadReason == "install" || options.loadReason == "startup") {
            factory = new Factory(AboutDualView);
            factory = new Factory(AboutEPFViewer);
            registerRemotePages();
        }
    }
    
    exports.onUnload = function (reason) {
        if (reason == "shutdown") {
            factory.unregister();
            RemotePageManager.removeRemotePageListener("about:dualview");
            RemotePageManager.removeRemotePageListener("about:epfviewer");
        }
    };
    
    function registerRemotePages(){
        let DualViewmanager = new RemotePages("about:dualview");
        let EPFViewmanager = new RemotePages("about:epfviewer");
    }
    

    Reference https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/SDK/Tutorials/Listening_for_load_and_unload