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

fix: #9127, scope service worker to relative_path for the forum #9239

Merged
merged 1 commit into from
Feb 2, 2021

Conversation

oplik0
Copy link
Contributor

@oplik0 oplik0 commented Feb 1, 2021

Adds a Service-Worker-Allowed header set to forum url (nconf.get('relative_path')) on assets/src/service-worker.js URL and uses scope option during its registration to ensure the service worker is correctly scoped to the entire forum and only the forum.

This is the implementation of what I described in #9127 (comment) - sorry it took so long, had some other stuff to do and I was actually kinda afraid I'll waste my time as someone will do it a bit faster than me (well, I had it happen here once with a pretty simple fix that I wasn't fast enough to make into a PR before one of the maintainers managed it and here I basically described all changes :)

Should fix #9127 and this issue was also mentioned in #9193. I found it thanks to this thread on the community forum

I can confirm that Chrome now asks user to install the page (on the desktop it's in the right part of the address bar) with these changes, when it didn't do so before. Haven't tested with other/mobile browsers though, but I'd be very surprised if it was different.

Adds a `Service-Worker-Allowed` header on `assets/src/service-worker.js` URL and uses `scope` option during registration to ensure the service worker is correctly scoped to the entire forum and only the forum.
@barisusakli
Copy link
Member

Thanks @oplik0

@barisusakli barisusakli merged commit 2bc74cf into NodeBB:master Feb 2, 2021
@oplik0 oplik0 deleted the fix-service-worker-scope branch February 2, 2021 07:48
@barisusakli
Copy link
Member

barisusakli commented Feb 8, 2021

@oplik0 I pushed these changes to https://community.nodebb.org/ and started getting the following message.

ServiceWorker registration failed:  DOMException: Failed to register a ServiceWorker 
for scope ('https://community.nodebb.org/') with script ('https://community.nodebb.org/assets/src/service-worker.js'): 
The path of the provided scope ('/') is not under the max scope allowed ('/assets/src/'). 
Adjust the scope, move the Service Worker script, or use the Service-Worker-Allowed HTTP header to allow the scope.

Not sure why the Service-Worker-Allowed header isn't working

@pitaj
Copy link
Contributor

pitaj commented Feb 8, 2021

Could it not be forwarded by nginx?

@oplik0
Copy link
Contributor Author

oplik0 commented Feb 8, 2021

I forgot that in some installations /asstes/* paths will be served by reverse proxy, so setting a cookie for it in NodeBB won't work.

I'm not sure where to move the route though - maybe going back to just relative_path/service-worker.js (so just /service-worker.js in routes/meta.js) would work fine?

@barisusakli
Copy link
Member

Yeah I think that's how it was initially before getting moved to /assets/src.

@oplik0 oplik0 restored the fix-service-worker-scope branch February 8, 2021 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

service-worker.js not respecting forum path
3 participants