service worker sync will not fire on case in android chrome
WHAT IM MISSING ???
Same thing in here: JavaScript Background Sync Stops Working if Page is Loaded/Refreshed while offline
- unplug usb cable for development (for chrome dev tool)
- push android home button
- push power button for sleep (black screen)
- then i wait 5 minutes (at least)
- then i push power button for awake
- then i push myapp to wake app (app is not closed but set to sleep)
- then i blug in usb cable for debugging
- then i click some button to fire sync after that i see ---
in console "REGISTER" but "SYNC" event not fired
if i click power button again (black screen)
and then i click power button again - then it will wake up
or i turn off wifi and then turn on wifi - then it will wake up
AND then is see in console "REGISTER" and "SYNC"
IF i wate 30 minutes then registered sync is deleted
CLIENT SIDE JS
var id = 'background-sync-' + (new Date()).getTime() + $.uniqid(6);
let postData = {
'type': 'background-sync',
'uuid': id,
};
registration.active.postMessage(postData);
SERVICE WORKER SIDE
self.addEventListener('message', function (event) {
//console.log('message=' + event.data.type);
if (event.data.type === 'background-sync') {
registerSync(event.data.uuid, event.data);
}
});
self.addEventListener('sync', function (event) {
console.log('SYNC');
//event.waitUntil(syncIt(event.tag));
});
function registerSync(uuid, data) {
if (data != undefined && data != null) {
let id = data.id;
//append data to storage
syncStore[id] = data;
//this is important
syncStore[id]['sending'] = false;
}
console.log('REGISTER');
//console.log(data);
//console.log(self.registration.sync.getTags());
self.registration.sync.register(uuid)
.then(function () {
})
.catch(function (err) {
return err;
});
}
question from:
https://stackoverflow.com/questions/65942049/javascript-background-sync-android-power-button 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…