I'm making a Chrome extension that receives Chrome Google Cloud Messages. I want to detect when puter wakes up from sleep/reconnects to internet, so that my application can start receiving messages again. For my specific case, I don't want GCM to throttle the pushes, so I set the ttl to 0, which is deliver now or never. (user device will never receive message while idle.)
In javascript, how do I detect when Chrome browser recovers from idle state?
More specifically, how could I do it in Chrome extension using chrome. api calls?
I'm making a Chrome extension that receives Chrome Google Cloud Messages. I want to detect when puter wakes up from sleep/reconnects to internet, so that my application can start receiving messages again. For my specific case, I don't want GCM to throttle the pushes, so I set the ttl to 0, which is deliver now or never. (user device will never receive message while idle.)
In javascript, how do I detect when Chrome browser recovers from idle state?
More specifically, how could I do it in Chrome extension using chrome. api calls?
Share Improve this question edited Nov 13, 2014 at 19:54 Keven Wang asked Nov 13, 2014 at 19:42 Keven WangKeven Wang 1,2781 gold badge19 silver badges30 bronze badges 3-
I wonder if you really need to do so. I would expect that Google manages receiving GCM for you after you've called
register
once. – Xan Commented Nov 13, 2014 at 19:44 - So you want to municate this fact to your GCM server? Using GCM? – Xan Commented Nov 13, 2014 at 19:56
- @Xan I will just do a manual fetch from my server on missed notifications. – Keven Wang Commented Nov 13, 2014 at 20:20
2 Answers
Reset to default 6Chrome has an idle API:
chrome.idle.onStateChanged(function(state) {
if (state == 'active') {
console.log('State is now active');
}
});
You can read about it here: https://developer.chrome./apps/idle
You can use idle.queryState also and put a check if state === active inside query
chrome.idle.queryState(15, function (state) {
if (state === "active"){
//Your logic
}
}