How to make extension code run in the web console?

I’m creating my first Firefox extension, and since I don’t quite know how the API works, I’d like to test out a few things in the web console.

For example, I have “browser.tabs.query()” in my code and I want to see what it returns (after fulfilling the promise). Unfortunately, the web console doesn’t resolve “browser.tabs.query” or “tabs.query”.

Is there a special root element I need to use in the console instead or before “browser”?

The browser namespace works only the in the context of the extension (addon).
So on normal web-pages it won’t work.

But if you open some extension page (the addressbar should show moz-extension:// protocol), for example some Options page of any of the addons you have installed (like uBlock), then in the console you will be able to use browser API.

To run API from the background script, open:
And click “Inspect” for any of your addons.

Plus, make sure to read as much MDN as possible :slight_smile:, starting with:

Thank you very much for your explanation. I’ll do as you suggested!