Rob--W / browser-action-jplib

Jetpack module to add a Browser action badge to the toolbar, using the chrome.browserAction syntax from Chromium
21 stars 9 forks source link

Cannot Pass Variables to Popup #17

Open anthonycl opened 9 years ago

anthonycl commented 9 years ago

I may have missed this, but I can't seem to figure out how to pass variables to the popup. Basically what I would like to do is pass in a list of Cookies using nsICookieManager2. I want to display this list in the popup.html. Or, within the popup I would like to grab that list but I can't seem to "require("chrome")" from the popup.html.

Any ideas are appreciated, thank you!

Rob--W commented 9 years ago

In your background/main script:

browserAction.sendMessage( ... some JSON-serializable object  ... );
// or, if you want to get a reply:
browserAction.sendMessage( ... some JSON-serializable object  ... , function(response) {
    // Do something with the response
});

In your popup script, use:

extension.onMessage.addListener(function(message, sender, sendResponse) {
    // Do something with the received object
    // If you want to send a reply, call sendResponse.
    // If you want to call sendResponse asynchronously, use "return true;"
});

These APIs are modeled after Chrome's extension messaging APIs.

I recommend to use one of the Addon SDK's button ui modules if you develop a Firefox addon from scratch though, because in either case you have to learn a new API (so you'd better learn the API that is used by the SDK platform).