Coder Social home page Coder Social logo

Make sure variables are initialized when service worker restarts before onRuleMatchedDebug listener code is executed. about little-rat HOT 3 CLOSED

keithx2 avatar keithx2 commented on July 23, 2024
Make sure variables are initialized when service worker restarts before onRuleMatchedDebug listener code is executed.

from little-rat.

Comments (3)

keithx2 avatar keithx2 commented on July 23, 2024 1

Perhaps you always have the developer console open for the extension? That prevents a service worker from terminating.

Service workers have a 30 second lifecycle. Received events or extension api calls reset the timer back to 30 seconds. If the timer expires, the service worker is terminated. Make sure there is no network activity, wait at least 30 seconds, and the extension will go 'inactive'. It will restart when an event it is listening to is fired. When it restarts, all the code in service-worker.js is run again.

There is no guarantee that the code in chrome.management.getAll will run before the listener for onRuleMatchedDebug when the extension restarts because of network activity. That is why the onRuleMatchedDebug listener needs to wait until the extension is fully initialized, before it continues. I've seen this error happen in this case:

Error in event handler: TypeError: Cannot read properties of undefined (reading 'numRequests') at chrome-extension://ojeaaldfoimnikjkigkhebdbpfjdoaco/service-worker.js:35:27

I can reproduce the error with the uBlock Origin extension. I let the service worker go inactive and open the 'uBlock Dashboard'. Then after selecting 'Filter lists', 'Purge all caches', and 'Update now', the error will appear when the extension restarts. If the service worker restarts on non extension network activity, then there would be no error.

There may be other cases in your code where you need the variables fully initialized first. I only looked at where the error occurred.

Note, new extensions can also be installed when the service worker is running. And you'll get an error in that same spot. This also needs to be considered. Maybe listen to management.onInstalled.

from little-rat.

dnakov avatar dnakov commented on July 23, 2024

I haven't been able to reproduce this. If you have more info, lmk. Gonna keep it open for a few days.

from little-rat.

dnakov avatar dnakov commented on July 23, 2024

Thank you for the detailed debugging! I'm working on some fixes.

from little-rat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.