nuxt-community / pwa-module

Zero config PWA solution for Nuxt.js
https://pwa.nuxtjs.org
MIT License
1.24k stars 171 forks source link

workbox listener creating self.setTimeout() error #466

Open MicahDavid opened 3 years ago

MicahDavid commented 3 years ago

I have the following method to check for new service worker updates:

            async checkSWUpdate() {
                const self = this
                const workbox = await window.$workbox;
                if (workbox) {
                    workbox.addEventListener('installed', (event) => {
                            self.serviceWorkerRefresh = true
                    });

                    workbox.update()
                }
            },

The addEventListener('installed') is creating the following error:

Uncaught TypeError: self.setTimeout is not a function at ServiceWorker.r.S

This is what the compiled javascript code looks like where the error occurs:

                ,
                r.S = function(e) {
                    var t = r.m
                      , n = e.target
                      , i = n.state
                      , o = n === r.p
                      , a = o ? "external" : ""
                      , c = {
                        sw: n,
                        originalEvent: e
                    };
                    !o && r.j && (c.isUpdate = !0),
                    r.dispatchEvent(new u(a + i,c)),
                    "installed" === i ? r.A = self.setTimeout((function() {
                        "installed" === i && t.waiting === n && r.dispatchEvent(new u(a + "waiting",c))
                    }
                    ), 200) : "activating" === i && (clearTimeout(r.A),
                    o || r.u.resolve(n))
                }

Any suggestions on this error?