Reputation: 11984
I declare a global variable in my background.js for my Chrome extension.
I find that at various points in time it gets reset, as if background.js were run again, and sometimes it is actually NULL when I attempt to use it from within my Popup (but not always). I haven't been able to pinpoint exactly when this reset or loss occurs.
Has anyone noticed similar inconsistent behavior with global Background vars in Chrome extensions?
Upvotes: 1
Views: 1343
Reputation: 11984
The answer is that I had the following in my manifest.json:
"background": { "persistent": false }
When I changed it to TRUE, it started working. For more info, see this link provided by Rob W.: https://developer.chrome.com/extensions/event_pages
Upvotes: 3