mdn/webextensions-examples

browser is not defined in firefox

dumpster-of-things opened this issue · 3 comments

#194

I have read discussion at the referenced issue, which has been marked "closed."
I do not see a solution for, nor explanation of why browser is undefined in firefox.

I am on version: 106.0.5 (64-bit) (Mozilla Firefox Snap for Ubuntu canonical-002 - 1.0)

My goal is to get a list of urls for open tabs.
I am following along with examples on MDN, running code verbatim in devtools>console.
The various related examples all use methods of the browser.tab construct.
There does not seem to be any documentation for broswer on MDN and so I am opening this issue.

I'm new to web development, but not to programming/scripting; and so
on the one hand: I'm probably missing something relatively pedestrian,
on the other hand: This seems like something too fundamental to not be documented;
and so perhaps this is an opportunity to make said documentation more complete.

The tabs documentation ( https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs ) is part of the documentation of APIs for WebExtensions. That includes tutorials to run extension code

Are you able to find answers to your questions at:
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions

The (Tabs API) examples featured in the documentation you linked to use the following syntax:
browser.tab ...
But it never mentions how to set browser and there does not appear to be any documentation on MDN about the predicate browser variable.

Can the Tabs API be interacted with directly through the console, or will I need to author [and publish?] a browser extension?

@dumpster-of-things I suspect your problem is that you need Toolbox for browser to be defined when you run snippets in the console. To do this, open about:debugging then This Firefox, click Inspect against any installed or temporary extension, and open Console. You can then paste and run the example code in the console.