-
Notifications
You must be signed in to change notification settings - Fork 830
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
Updated offer page reload recipe seems to contain broken code #2430
Comments
Please also note that I am seeing other problems with the code in this recipe. Just got the following error: What I need at this point is a reference to the new service worker so I can tell it to skip waiting. The simplest thing seems to be to do as follows, but this means bypassing the public API again, which is not great. let reg = event.target.p;
let serviceWorker = (reg.installing || reg.waiting);
messageSW(serviceWorker, {type: 'SKIP_WAITING'}); |
I can confirm I have the issue here as well. Sometimes originalEvent doesn't exist. Also Safari does behave slightly differently than Chrome. |
#2489 should be what we eventually switch it to use, but that's going to land in v6. In the meantime, apologies that this is still an issue. Here's my attempt at provided something fool-proof: https://github.com/google/WebFundamentals/compare/wb-skipWaiting-update-again?expand=1 (You basically save a reference to the Can you give that a try and if you confirm it behaves as you expect, I'll merge it into the docs? |
GoogleChrome/workbox#2430 (comment) to install and activate the new SW.
@jeffposnick your suggestion worked fine for me. |
Library Affected:
https://developers.google.com/web/tools/workbox/guides/advanced-recipes#offer_a_page_reload_for_users
Browser & Platform:
N/A
Issue or Feature Request Description:
Updated recipe for offering a page reload to users when an update is found seems to contain broken code. The working code is included here with FIXME comments. Please verify.
I think it would also be handy if this recipe showed how to trigger update discovery (unless you do this somewhere else, in which case please link to that from here).
Here's my code for doing this, which I call when the user clicks a button, and from an update poller that fires once an hour:
Note: in order to tell if the call to
wb.update()
resulted in anything (so I can tell the user something) I have to look at a hidden field calledp
-- the associated registration object. Not a great solution (I suspect it may break at any time). Better would be a result of some kind (boolean would do) but thewb.update()
promise resolves toundefined
at the moment.The text was updated successfully, but these errors were encountered: