Reputation: 15672
I have an alarm that triggers at midnight every day. It seems to me that if the user has quit chrome, the alarm will not trigger. Is there a way to trigger the alarm as soon as chrome is boot up (if the alarm didn't fire at midnight)? So to be clear, I only want to trigger on bootup if the alarm didn't fire at midnight. Here is what I have:
chrome.alarms.create("alarm_test", {delayInMinutes: startMins, periodInMinutes: 1440} );
chrome.alarms.onAlarm.addListener(function(alarm) {
//do stuff
});
Upvotes: 2
Views: 433
Reputation: 77482
The logic is pretty obvious here: you should record (in, say, chrome.storage.local
) the timestamp of last successful alarm execution.
Then, on extension initialization, see if the timestamp is over 1 day old. In that case, an alarm was missed and you should execute whatever it was supposed to run.
Upvotes: 3