Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

Opening scoped (subdirectory) page on notification click #118

Open
piotrekwitkowski opened this issue Oct 25, 2019 · 0 comments
Open

Opening scoped (subdirectory) page on notification click #118

piotrekwitkowski opened this issue Oct 25, 2019 · 0 comments

Comments

@piotrekwitkowski
Copy link

cc @gauntface

Type of Issue

Is this an issue with the demos, the content or is this a content request?

Content Request / Content Issue

Details....

If a bug with the demo What was the expected outcome vs actual outcome
and what browsers are affect, please include versions.

I am opening (or refocusing) page on notification click as described here.

If the service worker is registered at the domain root, the Jeff Posnick's method does the trick:

const urlToOpen = new URL('/page', self.location.origin).href;` 

However, if the service worker is scoped, the new URL will omit the subdirectory completly, because its second argument is base

new URL('/page', 'https://domain.com/sub/').href; => https://domain.com/page

It can be solved by gluing self.registration.scope already available in the service worker and page:

self.registration.scope + 'page' => https://domain.com/sub/page

Can such information be useful in the context of the web push book? Should I issue a PR?

Thanks for great tutorials @gauntface!

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

No branches or pull requests

1 participant