I developed a Chrome extension which get's data from the server (like rss reader) and because the data always updatable I want to get the data periodically so I set the files as below:
manifest.json:
"permissions": [
"alarms",
,
,
,
],
"background": {
"scripts": ["scripts/lib/jquery-1.9.1.min.js", "scripts/app/eventPage.js"],
"persistent": false
},
eventPage.js :
var url = ".....=?";
function getJSONData() {
$.getJSON(this.url, function (data) {
var newItems = [];
newItems = data.query.results.item;
localStorage.setItem("savedJSONData", JSON.stringify(newItems));
});
}
chrome.alarms.onAlarm.addListener(function (alarm) {
if (alarm.name == 'getNewJobs') {
getJSONData();
}
});
// Create the alarm:
chrome.alarms.create('getNewJobs', {
periodInMinutes: 30
});
After I get the new data from the server I store them in localStorage and in the popup I read from localStorage.
The problem is that the event page become inactive after 20 seconds or so, and the alarms doesn't fire.
Any suggestions,
我找到了答案:将chrome.alarms添加到pageEvent.js,即使后台处于非活动状态,它也会在警报时间到来时运行警报功能。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.