Reputation: 615
I am trying to create a feed reader that checks for an updated version of the feed every hour or so.
My problem is that the event page seems to turn inactive after less than 20 seconds.
How do I make it last longer?
Here's some of the important parts of the code:
in manifest.json:
"background": {
"scripts": ["eventPage.js"],
"persistent": false
},
and in eventPage.js:
function testFunc () {
alert("test")
}
setInterval(testFunc, 10 * 1000) // was testing the number of seconds here
What am I doing wrong?
Thank you!
Regards,
John
Upvotes: 2
Views: 2721
Reputation: 349062
Using setInterval
to periodically run some code works fine on background pages, but not on event pages, because the event page goes inactive when the page is idle for a long while.
The correct way to schedule a periodic task on event pages is to use the chrome.alarms
API:
chrome.alarms.onAlarm.addListener(function(alarm) {
if (alarm.name == 'name-of-alarm') {
// Do something...
testFunc();
}
});
// Create the alarm:
chrome.alarms.create('name-of-alarm', {
periodInMinutes: 60
});
Upvotes: 7