I’m trying to get login code in background page to run only once on browser start. But it seems global code in bgpage runs every time on popup clicked. Also it runs in different scope. Is it possible to solve this?
// background.js
var someCustomType = new SomeCustomType();
function SomeCustomType() {
this.firstProperty;
}
function thisShouldBeCalledOnce() {
someCustomType.firstProperty = 'defined';
alert('someCustomType.firstProperty=' + someCustomType.firstProperty);
console.log('thisShouldBeCalledOnce');
}
if (true) {
// Alwase 'undefined'
alert('someCustomType.firstProperty=' + someCustomType.firstProperty);
thisShouldBeCalledOnce();
}
Simple code example:
manifest.json
popup.html: just some dummy code:
background.js:
In this case, alert was fired once, when you load your extension, when you open popup no alert will be shown. Regards.