No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    [SOLVED] Chrome (but not FF nor Safari) randomly fails PWA update

    Framework
    5
    43
    395
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ssuess
      ssuess last edited by ssuess

      I seriously think I have discovered a bug in chrome or possibly workbox (but that only happens in chrome) or possibly even with register service worker package. After painstakingly dissecting the actions in my register-service-worker.js file, I have found that the error with reload in chrome (again only when console is closed!) is related to making an axios (or fetch, I tried both) call in the updated hook. If I leave out that call, it updates fine, even when console is closed. Here is an always working updated hook:

      updated (registration) {
          console.log('New content is available; please refresh.')
          const r = confirm('There is a new version available. Your version will be updated, alright? ')
          if (r === true) {
            localforage.clear().then(function () {
              // Run this code once the database has been entirely deleted.
              console.log('Database is now empty. so there now.')
              location.reload(true)
            }).catch(function (err) {
              // This code runs if there were any errors
              console.log(err)
            })
          } else {
            console.log('You pressed Cancel!')
          }
        },
      

      And here is one that WONT work (in chrome with devtools closed):

      updated (registration) {
          console.log('New content is available; please refresh.')
          fetch('https://pwatest.mydomain.com/av.json?t=' + Date.now())
            .then(response => {
              response.json().then(function (data) {
                const r = confirm('There is a new version (' + data.version + ') available. Your version will be updated, alright? ' + data.message)
                if (r === true) {
                  if (data.clearStorage === true) {
                    localforage.clear().then(function () {
                      // Run this code once the database has been entirely deleted.
                      console.log('Database is now empty. so there now.')
                      location.reload(true)
                    }).catch(function (err) {
                      // This code runs if there were any errors
                      console.log(err)
                    })
                  }
                } else {
                  console.log('You pressed Cancel!')
                }
              })
              console.log('response:', response)
            })
            .catch(error => {
              console.error(error)
            })
        }
      

      And just so we are crystal clear: the fetch works fine, and the alert contains the data from the fetch. But whenever using fetch (or axios) in ANY way in the service worker file in the updated hook, it causes a reload failure (in chrome only with devtools window closed).

      1 Reply Last reply Reply Quote 0
      • ssuess
        ssuess last edited by

        well, I reported this as a bug to both the workbox team and the register service worker team, hoping to hear something back.

        dobbel 1 Reply Last reply Reply Quote 0
        • dobbel
          dobbel @ssuess last edited by

          @ssuess

          Did you solve this / any progress?

          1 Reply Last reply Reply Quote 0
          • ssuess
            ssuess last edited by

            I have been playing around with a few different versions of axios and fetch, with various options. Also have tried moving this to the updatefound hook (over the updated), which MAY have worked, but I am still testing. Will report back soon.

            1 Reply Last reply Reply Quote 0
            • ssuess
              ssuess last edited by

              I am cautiously optimistic that moving my fetch and update dialog and reload code to the updatefound hook has fixed it! But I still need more testing

              1 Reply Last reply Reply Quote 1
              • ssuess
                ssuess last edited by

                I really think moving it to updatefound fixes it!!!

                dobbel 1 Reply Last reply Reply Quote 0
                • dobbel
                  dobbel @ssuess last edited by

                  @ssuess

                  Sounds promising! The code/flow stays the same if using updatefound instead of updated?

                  1 Reply Last reply Reply Quote 0
                  • ssuess
                    ssuess last edited by

                    yes everything else is the same. Since the service worker itself is updating the code regardless of what I am doing (updating local version string and clearing localstorage) I can do what I need earlier in the process and reload which works great! So happy to have found this solution it was really a vexing problem (that only showed up in Chrome for some reason)

                    dobbel 1 Reply Last reply Reply Quote 0
                    • dobbel
                      dobbel @ssuess last edited by

                      @ssuess

                      Hope this ‘workaround’ won’t be trashed in the next Chrome update 😉

                      1 Reply Last reply Reply Quote 0
                      • ssuess
                        ssuess last edited by ssuess

                        UGH, I REALLY hate to have to revisit this, but wouldn’t you know it, this fix made all the OTHER browsers break! I ended up having to do this in the end, which really sucks:

                         updatefound (registration) { // registration -> a ServiceWorkerRegistration instance
                            console.log('New content is downloading.')
                            /* eslint-disable no-extra-boolean-cast */
                            if (!!window.chrome) {
                              // all my checking and clearing localstorage stuff here for stupid chrome browsers (Chrome, Edge, etc)
                            }
                          },
                          updated (registration) { // registration -> a ServiceWorkerRegistration instance
                            console.log('New content is available; please refresh.')
                            if (!window.chrome) {
                              // all my checking and clearing localstorage stuff here for non chrome browsers (FF, Safari)
                              }
                            }
                          },
                        
                        dobbel 1 Reply Last reply Reply Quote 0
                        • dobbel
                          dobbel @ssuess last edited by

                          @ssuess

                          What a mess…

                          btw Did you get any response from the Workbox devs about this?

                          1 Reply Last reply Reply Quote 0
                          • ssuess
                            ssuess last edited by

                            @dobbel no they were not very helpful at all, other than to say they didn’t know: https://github.com/GoogleChrome/workbox/issues/2652

                            dobbel 1 Reply Last reply Reply Quote 0
                            • dobbel
                              dobbel @ssuess last edited by

                              @ssuess

                              Here’s someone that unregisters the service worker before reload:

                              https://forum.quasar-framework.org/topic/7175/hook-in-register-service-worker-update-and-display-notification-in-app/3

                              1 Reply Last reply Reply Quote 0
                              • ssuess
                                ssuess last edited by

                                @dobbel thanks I took a look, but for now my workaround seems to be working so I think I will leave it. Still, this is good info and I might try it later, thanks for the heads up!

                                1 Reply Last reply Reply Quote 0
                                • tlloyduk
                                  tlloyduk last edited by tlloyduk

                                  I’ve suddenly started to get this after upgrading Quasar to latest - wondered if anyone had come up with a reliable solution since the last post ?

                                  
                                  Operating System - Windows_NT(10.0.19041) - win32/x64                                                                                                          
                                  NodeJs - 12.16.1                                                                                                                                               
                                                                                                                                                                                                 
                                  Global packages                                                                                                                                                
                                    NPM - 3.10.6                                                                                                                                                 
                                    yarn - 1.22.4                                                                                                                                                
                                    @quasar/cli - 1.1.3                                                                                                                                          
                                    @quasar/icongenie - Not installed                                                                                                                            
                                    cordova - Not installed                                                                                                                                      
                                                                                                                                                                                                 
                                  Important local packages                                                                                                                                       
                                    quasar - 1.15.10 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time                                          
                                    @quasar/app - 2.2.4 -- Quasar Framework local CLI                                                                                                            
                                    @quasar/extras - 1.10.2 -- Quasar Framework fonts, icons and animations                                                                                      
                                    eslint-plugin-quasar - Not installed                                                                                                                         
                                    vue - 2.6.12 -- Reactive, component-oriented view layer for modern web interfaces.                                                                           
                                    vue-router - 3.2.0 -- Official router for Vue.js 2                                                                                                           
                                    vuex - 3.6.0 -- state management for Vue.js                                                                                                                  
                                    electron - Not installed                                                                                                                                     
                                    electron-packager - Not installed                                                                                                                            
                                    electron-builder - Not installed                                                                                                                             
                                    @babel/core - 7.13.8 -- Babel compiler core.                                                                                                                 
                                    webpack - 4.44.2 -- Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support l
                                   stuff.                                                                                                                                                        
                                    webpack-dev-server - 3.11.0 -- Serves a webpack app. Updates the browser on changes.                                                                         
                                    workbox-webpack-plugin - 6.1.2 -- A plugin for your Webpack build process, helping you generate a manifest of local files that workbox-sw should precache.   
                                    register-service-worker - 1.7.1 -- Script for registering service worker, with hooks                                                                         
                                    typescript - 4.2.2 -- TypeScript is a language for application scale JavaScript development                                                                  
                                    @capacitor/core - Not installed                                                                                                                              
                                    @capacitor/cli - Not installed                                                                                                                               
                                    @capacitor/android - Not installed                                                                                                                           
                                    @capacitor/ios - Not installed                                                                                                                               
                                                                                                                                                                                                 
                                  Quasar App Extensions                                                                                                                                          
                                    @quasar/quasar-app-extension-dotenv - 1.1.0 -- Load .env variables into your quasar project                                                                  ```
                                  dobbel 1 Reply Last reply Reply Quote 0
                                  • dobbel
                                    dobbel @tlloyduk last edited by

                                    @tlloyduk

                                    I would ask this on the new forum where the Quasar team now gives support.

                                    https://github.com/quasarframework/quasar/discussions

                                    1 Reply Last reply Reply Quote 0
                                    • First post
                                      Last post