Firefox console ReferenceError: browser is not defined
Asked Answered
T

1

14

I am trying to learn WebExtension development for Firefox. I find the window debugging tools EXTREMELY useful as I can interactively evaluate javascript code in the window context.

For the Webextension APIs at the browser level, I have been totally unsuccessful when trying to similarly use the browser console. For example trying to use the tabs API

Click on menu->developer->browser console

In the console command line enter any expression beginning with browser and I get

"ReferenceError: browser not defined"

I have tried in chrome and got same error (read article about chrome.* vs browser.*)

For example trying to find all tabs:

var querying=browser.tabs.query(queryInfo)

or

chrome.tabs.query()

Returns browser or chrome as not defined

Please help

Typewritten answered 6/11, 2017 at 18:31 Comment(0)
S
12

As described at [1] WebExtension APIs are present in pages contained inside a WebExtension. The browser console gives you access to the javascript environment used to implement the main browser user interface which is a very different environment.

To experiment with the WebExtensions APIs interactively, your best bet is probably to create a very simple WebExtension with an empty background page, then attach to it with the debugger [2]

[1] https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API

[2] https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Debugging

Showboat answered 7/11, 2017 at 1:37 Comment(2)
Thanks for taking the time to respond. This makes perfect since. I will try it later today. Again ThanksTypewritten
So how does one load the WebExtension stuff into the JavaScript console?Broth

© 2022 - 2024 — McMap. All rights reserved.