WittCode💻

A Common Bug in Chrome Extensions

By

Learn about a common bug that developers introduce into their chrome extensions without even knowing it.

Table of Contents 📖

Service Workers Going Idle

Service workers go idle after 30 seconds of inactivity. Specifically, they are unloaded if they do not receive any events in a 30 second window. When they do receive an event, this 30 second window is reset.

Service Workers Inspection

However, when inspecting a service worker (having the developer tool window open) the service worker will be permanently active. It is common for developers to have this window open when working with a service worker to check logs, step through code, etc. This creates an environment that is specific to development. Out in production, this development window cannot be opened.

ERROR: Not to mention that even if it was possible the likelihood of users manually opening this window and keeping it open is very unlikely.

Image

What does this Mean?

As service workers shut down, this means that global variables in the service worker will be lost, connections to content scripts or popups will be shut down, etc. However, if the developer tool window is open, the service worker will be active and none of these issues will occur.

What to do?

To fix this issue, ensure that before publishing the extension, the service worker development tool window is closed. This way the behavior of the extension in a production environment can be demonstrated.

A Common Bug in Chrome Extensions