Add message event listener when skipWaiting: false
See original GitHub issueWhat problem does this feature solve?
When developing PWA, the default workboxPluginMode
is generateSW
, and they set skipWaiting: false
. In this case, the generated service worker should allow our web app to trigger skipWaiting()
on demand, by using postMessage()
to communicate with our service worker.
This feature was implemented in Workbox v4.1.0, but Vue CLI 3.x can’t take advantage of it.
What does the proposed API look like?
self.addEventListener('message', (event) => {
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
});
Reference: skipWaiting
option in workbox-webpack-plugin
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:24 (3 by maintainers)
Top Results From Across the Web
active serviceWorker is not sending message to waiting ...
There a few things wrong. navigator.serviceWorker.controller.postMessage('skipWaiting');. This is sending a message from window to worker ...
Read more >ServiceWorkerGlobalScope.skipWaiting() - Web APIs | MDN
skipWaiting () from inside of an InstallEvent handler. The following example causes a newly installed service worker to progress into the ...
Read more >Handling Service Worker updates in your Vue PWA
Next up is listening for this event from within our Vue app. ... updateExists = false // Make sure we only send a...
Read more >How to Fix the Refresh Button When Using Service Workers
We start by adding code to the Service Worker's script to listen for a posted message: addEventListener('message', messageEvent => {
Read more >Service Workers - W3C
A service worker has an associated skip waiting flag . ... The following is the event handler (and its corresponding event handler event ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
this article might help you
@LinusBorg Yes, I can send a message to the SW, my code in
registerServiceWorker.js
:The problem is the ServiceWorker can’t skip waiting after posting message, because it hasn’t a listener to listen the
message
event. So the code:should be included in the
service-worker.js
, which is auto-generated. But now the code doesn’t exist inservice-worker.js
.