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

Make use of Workbox window to register service worker and provide access to registration #204

Closed
westonruter opened this issue Aug 1, 2019 · 1 comment · Fixed by #578

Comments

@westonruter
Copy link
Collaborator

Workbox now makes available a workbox-window module:

The `workbox-window` package is a set of modules that are intended to run in the window context, which is to say, inside of your web pages. They're a complement to the other workbox packages that run in the service worker.

The key features/goals of workbox-window are:

  • To simplify the process of service worker registration and updates by helping
    developers identify the most critical moments in the service worker lifecycle, and making it easier to respond to those moments.
  • To help prevent developers from making the most common mistakes.
  • To enable easier communication between code running in the service worker and code running in the window.

We should be using this as opposed to registering it directly:

https://github.com/xwp/pwa-wp/blob/eb4fcc12945acd7b7afbd10cfb0d91d0b3749c22/wp-includes/service-workers.php#L161-L163

The Workbox instance can then be stored in a wp.serviceWorker global. This will then allow plugins to make use of the getSW() method, with a goal to provide a reliable way for themes and plugins to access the service worker controlling the page once it is registered and active.

See reference docs.

@pooja-muchandikar
Copy link

QA Passed ✅
getSW() method is returning the service worker which has been registered using the workbox-window module.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants