Search code examples
javascriptajaxfirefoxpanelfirefox-addon-sdk

How do I ajax request from panel on the Firefox addon?


I have some questions about panel on the Firefox addon. How do I ajax request from panel? And How to debug panel? Firebug can't see panel.


Solution

  • If you need to do a request to a web api from a panel, you'll need to actually make the web request in main.js, and send the result to your panel using

    panel.postMessage(results) 
    

    Some documentation you should look at:

    https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/guides/content-scripts/index.html

    The SDK uses an asynchronous event-driven system to send messages between objects such as a panel and the main addon code. The above guide to content scripts is a great backgrounder for how this system works.

    https://addons.mozilla.org/en-US/developers/docs/sdk/latest/packages/addon-kit/request.html

    The request module allows you to make requests to any web service.

    Here is an example add-on that makes a request to the twitter api and passes the results to a page-mod:

    https://builder.addons.mozilla.org/package/45866/latest/

    This implementation is similar to what you would need to do to trigger an api request from a panel.