ampproject / ampproject/amphtml
Improve scope documentation for amp-install-serviceworker and amp-web-push scopes
- Dominant language
- JavaScript
- Stars
- 14.9k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
## What's the issue?
Normally when wanting to install a service worker, the way to do so is to use the aptly-named [`amp-install-serviceworker`](https://amp.dev/documentation/components/amp-install-serviceworker) component.
However, if wanting to then add push notifications, the [`amp-web-push`](https://amp.dev/documentation/components/amp-web-push/) component needs to be used.
This introduces a problem because the `amp-web-push` component _also_ takes the responsibility of installing a service worker (apparently). Because only one service worker can be active on a given page, this introduces a conflict.
This being said, in testing if I add both components to the page, it doesn't seem to result in the service worker attempting to be installed twice. In fact, only the service worker referenced in `amp-install-serviceworker` is being added, even when I put `` _before_ ``. I'm not seeing `` install any service worker at all, so maybe I am not correctly understanding how it is supposed to work. However, if it is supposed to install a service worker it could create major confusions when a user tries to supply a service worker script that is specific to push notifications on `` but another script entirely for ``. This should get raised by the component as a user error.
Also, ideally the `amp-web-push` component would allow omission of the `service-worker-url` attribute if there is an `` element on the page. This would also allow `amp-web-push` to take advantage of the capabilities of `amp-install-serviceworker`, such as installing the origin service worker while accessing a page loaded from an AMP Cache.
All of this to say, I am not clear if there is actually a conflict. But since the documentation for the components does not refer to each other, it is not clear if they can work together. If not, they should. And the docs should be updated to clarify.
## How do we reproduce the issue?
Include both `amp-service-worker` and `amp-web-push` on a page.
Contributor guide
Assessment
This issue has not been assessed yet.