ReferenceError: browser is not defined

Viewed 39391

I am running this piece of code and the firefox is giving error

Uncaught ReferenceError: browser is not defined

const manifest = browser.runtime.getManifest();

So far I've tried using this:

var browser = browser || chrome;

Still in this, firefox is throwing a new error that is Chrome is not defined

2 Answers

The respective browser references are only defined in their respective scopes.

You might want to do something like this to remain platform independent.

if (typeof browser === "undefined") {
    var browser = chrome;
}
Related