I am playing with chrome extensions, my manifest loads a background page with:
...
"background": { "scripts": ["background_page.js"], "persistent": false },
...
The .js
code looks like this:
var once = false;
window.addEventListener("load", function () {
if ( once == true ) { return; }
alert( 'test' );
once = true;
}, false);
This seems to works fine, but i want to run the background_page.js
code only once every time the browser starts.
Right now, I am not sure why, but the code is executed more than once. At first I thought it was being executed every time I open a new tab but that's not the case. The alert does appear once I start the browser, then if I open a new tab quickly the alert wont appear, but if I wait about 1 minute or so and open a new tab then the alert appears again.
How can i make sure the background_page.js
code runs only once every time the browser starts?