2

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?

hasmet
  • 758
  • 3
  • 13
  • 32
  • When using jpm don't modify bootstrap.js follow this guide here - https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Getting_Started_%28jpm%29 – Noitidart Apr 19 '16 at 15:08
  • Sorry but I don't understand your comment....I'm not talking about bootstrap.js (that it is not generate from the last version of jpm) but how to make "bootstrable" the extension – hasmet Apr 20 '16 at 10:14
  • What is "bootstrapable"? Using twitter bootstrap? You are using jpm, so you should not have to think about the install.rdf or bootstrap.js ever. By bootstrapble do you mean twitter bootstrap.js/bootstrap.css? – Noitidart Apr 25 '16 at 11:34
  • I'm talking about the type of extension inserted here https://developer.mozilla.org/en-US/Add-ons/Bootstrapped_extensions – hasmet Apr 26 '16 at 12:10
  • 1
    Oh I think see now. You stated in the first like you are using latest jpm. But then you are trying to trigger startup and shutdown events. Your addon has a bootstrap.js but it is not something you should deal with at all - force yourself not to think about it, it will confuse you. That bootstrapj.s is something totally different. If you want startup/shutdown events in jpm you should follow this guide - https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload – Noitidart Apr 26 '16 at 15:57
  • The last version of jpm create a main.js, that is the default entry point of my addon (but can be changed from package.json file). The actual problem is that I would not like to export my main.js file, but I would like to understand if I can use startup and/or shutdown methods directly in main.js file or not. And, in case of not, how I can use these methods. Thanks :) – hasmet Apr 27 '16 at 14:43
  • 1
    Yes you can create startup/shutdown events from main.js as per that article in my previous comment. Try it out it will work for sure. I did it in the past. – Noitidart Apr 27 '16 at 16:20

2 Answers2

1

What type of add-on do you have?

Sounds like an XUL/Overlay add-on using the legacy API. If that is the case, then you must create your own bootstrap.js file. Have you gone through all the steps to convert an overlay extension to restartless?

jpm init will create the bootstrap code only when using the Addons-SDK. I'm not sure of any benefit to using jpm unless you are creating an add-on using the new Addons-SDK API, except perhaps the ability to package and submit the add-on to AMO from the command line. The debugging/validation checks of jpm just don't seem to catch many problems, almost none in XUL/Overlay API based add-ons.

Perhaps you have looked here already? Bootstrapped extensions, which links to a documented skeleton bootstrap.js.

Note, though, that in the chrome.manifest, the overlay instruction is not supported in bootstrapped extensions.

These and other topics are also covered in the "convert" document, referenced above.

  • In my case the addon is not XUL/overlay but is already a restartless addon. Infact, my entry point is "main.js" (autocreated using jpm init). If I create a new addon using jpm init, inserting the code from developer.mozilla.org/en-US/docs/Extensions/bootstrap.js into my entry point file and importing all the necessary elements, I can not handle the startup and shutdown methods – hasmet Apr 26 '16 at 12:46
1

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

Paul Heil
  • 295
  • 1
  • 9