This module is no longer maintained, and non-functional as of Firefox 38. Use the sdk/ui module instead.
If you are interested in using Chrome extension APIs in Firefox, follow the following bug and its linked bugs: https://bugzilla.mozilla.org/show_bug.cgi?id=1161828
This Jetpack module provides an API which is almost identical to Google Chrome's chrome.browserAction
API for creating badges on the toolbar.
Identical in terms of API, identical in terms of appearance!
If you're familiar with the chrome.browserAction
API, using this module is a breeze.
To add a browser action button to your Firefox add-on, copy-paste the browser_action
section from your
Chrome extension's manifest file to your add-ons background page. After running the following code, a
browser action button will appear at the right of the location bar.
var badge = require('browserAction').BrowserAction({
default_icon: 'images/icon19.png', // optional
default_title: 'Badge title', // optional; shown in tooltip
default_popup: 'popup.html' // optional
});
chrome.browserAction.
methods have been implemented.chrome.browserAction
API.destroy
method makes it possible to remove the browser action at any time.sendMessage
and onMessage
have been added to ease the communication with the popup.
This API allows for messages with callbacks, and are modelled after the Chrome messaging API.setIcon
method does not take an imageData
object (there's no DOM, thus no <canvas>
in the background page).You can add the module globally (in the packages
directory under the SDK root), to make it available to all of your Jetpack projects,
or add it to a single project (in the packages
directory under your add-on's root).
The official documentation contains a tutorial on installing third-party modules,
which suggests to download and extract an archive.
I strongly recommend to use git for this purpose, because it makes package management a lot easier. For example:
# Go to the packages directory of the SDK's root.
cd /opt/addon-sdk/packages
# Clone the repository (creates a directory "browser-action-jplib")
git clone git://github.com/Rob--W/browser-action-jplib.git
# Done! You may want to update and view the documentation...
addon-sdk && cfx sdocs
# Later, when you want to update the package to the latest version...
cd /opt/addon-sdk/packages/browser-action-jplib
git pull
After installing the module, declare the dependency in package.json:
...
"dependencies": ["browser-action"],
...
The only external dependency is the toolbarwidget
Jetpack module.
faviconUrl
property because Firefox has deprecated synchronous access to this information (#7).toolbarwidget
dependency to v1.3 or higher.browserAction.onClicked
event receives an argument that closely follows the
format of Chrome's tab.Tab
.Created by Rob Wu gwnRob@gmail.com.
Released under a MIT license.