Chrome Extension - event page inactive after less than 20 seconds

前端 未结 1 1772
深忆病人
深忆病人 2020-12-22 02:13

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

相关标签:
1条回答
  • 2020-12-22 02:52

    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
    });
    
    0 讨论(0)
提交回复
热议问题