Questions tagged [firefox-addon-bootstrap]

Firefox Bootstrapped extensions

Note: All extensions created using the are bootstrapped! All the bootstrapping code is generated for you, so you don't really need to think about it

Traditional extensions include overlays, wherein the application can load up from the extension's package and automatically apply it atop its own UI. While this makes creating extensions that add to the application's user interface relatively easy, it means that updating, installing, or disabling an extension requires an application restart.

(Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) introduces bootstrapped extensions. These are special extensions that, instead of using overlays to apply their user interface to the application, programmatically insert themselves into the application. This is done using a special script file that's included in the extension that contains functions the browser calls to command the extension to install, uninstall, startup, and shutdown.

All the application does is call into this script file; the extension is responsible for adding and removing its user interface and handling any other setup and shutdown tasks it requires.

The startup and shutdown process

A key feature of bootstrapped extensions is that they must be able to be started up and shut down on demand by the application. When the extension's startup() function is called, it must manually inject its user interface and other behavior into the application. Similarly, when its shutdown() function is called, it must remove anything it's added to the application, as well as all references to any of its objects.


Creating a bootstrapped extension

To mark an extension as bootstrappable, you need to add the following element to its install manifest:

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

Then you need to add a bootstrap.js file that contains the required functions; this should be alongside the install.rdf file in the extension's package.

Bootstrap entry points:

aData A bootstrap data structure {id, version, installPath, resourceURI, ...}.

aReason One of the reason constants APP_STARTUP, ADDON_ENABLE, ADDON_INSTALL, ...

startup

Called when the extension needs to start itself up. This happens at application launch time or when the extension is enabled after being disabled (or after it has been shut down in order to install an update. As such, this can be called many times during the lifetime of the application.

This is when your add-on should inject its UI, start up any tasks it may need running, and so forth:

function startup(aData, aReason) { }

shutdown

Called when the extension needs to shut itself down, such as when the application is quitting or when the extension is about to be upgraded or disabled. Any user interface that has been injected must be removed, tasks shut down, and objects disposed of.

function shutdown(aData, aReason) { }

install

Your bootstrap script must include an install() function, which the application calls before the first call to startup() after the extension is installed, upgraded, or downgraded.

function install(aData, aReason) { }

uninstall

This function is called after the last call to shutdown() before a particular version of an extension is uninstalled.

function uninstall(aData, aReason) { }

Check more about The bootstrap.js scope

13 questions
3
votes
1 answer

Firefox Addon: bootstrap.js mit sdk/page-mod for versions < 38.0

tl;dr: We created a firefox addon using the Addon SDK. Since compiling the addon is one step in a larger build system (we also compile for chrome), our build system packages the xpi manually and does not use jpm. However, we used the contents of a…
3
votes
1 answer

Importing Javascript module in Firefox extension

I am developing a simple Firefox extension but am having trouble importing my custom Javascript module file. The bootstrap.js file is at the root and test.jsm is inside the content folder. test.jsm exports 2 symbols foo and bar…
2
votes
2 answers

Do I need to create an .xpi file to test my Firefox extension?

I have a Firefox extension. When I change the source code, every time I have to create the zip file including the source code and then make it as a .xpi file. Can I avoid this making *.xpi file steps?
2
votes
1 answer

Open Tab in a Specific Position by Firefox extension

Say, there are 10 tabs in Firefox browser window. How can I add a tab in after 2nd tab by a Firefox extension code? gBrowser.addTab method only appends to the tab list.
2
votes
0 answers

Show blank page in new private browsing window of Firefox

In Firefox 42, when a new private browsing window is opened, it shows the information about Tracking Protection. How to show a blank page instead? I know it can be done via override directive in chrome.manifest but I am looking for a way to do it in…
2
votes
1 answer

Firefox extension: about PopupNotifications.jsm in

I've made a small (bootstrapped) extension to notify me about for some changes on a site. Everything has done, except of displaying notifications. As I understand HTML5 Notification is not accessible from extensions. Then I found another way with…
Vitaly
  • 611
  • 1
  • 7
  • 21
2
votes
2 answers

Using loadFrameScript, how can inject file before the page's script execution?

I'm currently using this in the bootstrap.js file. Is used to edit the client's JavaScript code in my case I'm using recentBrowserWindow.messageManager.loadFrameScript(file, true): const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} =…
1
vote
1 answer

maxVersion of Firefox Add-on is not enforced?

I have a Firefox add-on (not distributed via AOD) that was supposed to be active (in that version) only with Firefox up to version 50, cf. This snippet is from my install.rdf:
1
vote
1 answer

Firefox 52 "New File" changes and error

I have been using new File(file.path); in bootstrapped privileged code from Firefox 17.* to 51.*. file is an nsIFile. As of Firefox 52, it now gives an error: TypeError: Not enough arguments to File. ref: Firefox 52 for developers The File and…
erosman
  • 7,094
  • 7
  • 27
  • 46
1
vote
1 answer

Is using a while loop a good waiting strategy in a Firefox Restartless Extension?

I have a bootstrapped extension which interacts with the chrome part of Firefox (i.e. even before the content loads), and needs to query an SQLite database for some check. I would prefer a sync call. But, since a sync call is bad in terms of…
1
vote
0 answers

Access nsIDOMChromeWindow from Services.jsm or similar, for XUL to Add-ons-SDK migration

Migrating an old Add-on from XUL to Add-ons-SDK in preparation for WebExtensions. Would still like to support some older browsers with this add-on, so that is why I am not jumping right to WebExtensions. What I'd like to do is control minimize,…
1
vote
1 answer

Calling add-on from web page in new multiprocess Firefox

dear all. We have crypto signing extensions implemented for few browsers in our application, everything went fine, but now we faced problem with new Mozilla's multiprocess API migration (E10S aka Electrolysis). Our web part interacts with extension…
1
vote
1 answer

Download and open Firefox

I am a new user of Firefox's plugin system. I wanted to create a plugin that will download multiple files in a que, and then open them for practice. My question is if there is a way to download a file from the Internet in the plugin. I am aware of…