Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use service workers with background sync to send analytics data #163

Closed
adriaanvanrossum opened this issue Nov 18, 2019 · 1 comment
Closed

Comments

@adriaanvanrossum
Copy link
Contributor

@adriaanvanrossum adriaanvanrossum commented Nov 18, 2019

Like push messaging, it uses a service worker as the event target, which enables it to work when the page isn’t open. To begin, register for a sync from a page:

// Register your service worker:
navigator.serviceWorker.register('/sw.js');

// Then later, request a one-off sync:
navigator.serviceWorker.ready.then(function(swRegistration) {
  return swRegistration.sync.register('myFirstSync');
});

Then listen for the event in /sw.js:

self.addEventListener('sync', function(event) {
  if (event.tag == 'myFirstSync') {
    event.waitUntil(doSomeStuff());
  }
});

https://developers.google.com/web/updates/2015/12/background-sync

@adriaanvanrossum adriaanvanrossum added this to Features & bugs in Public roadmap via automation Nov 18, 2019
@adriaanvanrossum

This comment has been minimized.

Copy link
Contributor Author

@adriaanvanrossum adriaanvanrossum commented Dec 8, 2019

Service workers don't work on non-origin domains.

Public roadmap automation moved this from Features & bugs to Implemented Dec 8, 2019
@adriaanvanrossum adriaanvanrossum moved this from Implemented to Trash in Public roadmap Dec 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Public roadmap
  
Trash
1 participant
You can’t perform that action at this time.