Manifest v3 background service worker seems to go stale. How to verify this is the case

Viewed 960

My goal is to make sure I have a stable process for handling extension updates. I'm about to release a new extension and have noticed that the background service worker goes stale. Here are the details:

My method of testing this lifecycle is by generating a new build artifact and drag-n-dropping it into the page chrome://extensions. I hope this is the way to test this lifecycle. But if not, I would be happy to hear the alternative.

Once I drag and drop, I open the background console to check for the correct version, but seems it lags behind. The only way to remedy this issue is by removing the extension completely and loading it back, this gives me the impression a regular user would experience the same issue.

The screenshot below describes the situation:

  1. version 0.3.33 is currently installed
  2. drag and drop new build version 0.3.34
  3. after successful drag and drop, notice version is lagging with version 0.3.31
  4. But the chrome.runtime.onInstall release accurately outputs the previous version

stale version screenshot

Furthermore, I took a look at the unpacked extension directory and the compiled code is accurate with the expected version

verification on unloaded source directory

What I've done so far to troubleshoot, was to remove the extension completely. It does successfully update after a series of manifest.version updates, but then it goes stale. To be clear, all I do is update the version property of the manifest.json file and that seems to cause this issue

Any help would be greatly appreciated. In the meantime, I'll brush up on the architecture for service workers as it relates to chrome manifest v3. Thanks!


EDIT - Sunday, August 22 2021:

The latest development: First of all, thanks woxxom for additional details to debug.

I've created an example project that demonstrates the problem with reproducible steps. Hopefully, this helps identify the problem but it does seem to point to a Chrome bug so I'll also report it on crbug.com

Github project: https://github.com/miguelespinoza/-v3-service-worker-update

Ultimately, what I've identified is that loading an iframe causes the service worker lifecycle to go "stale".

Looking at chrome://serviceworker-internals/?devtools, I've noticed that the extension includes two workers, that seems odd because I'd imagine only one should exist, the one in the background. This could mean nothing, but wanted to share that as well. one "Active worker" and one "Waiting worker"

enter image description here

Important Note: Service worker background events stop working. In my case, chrome.commands.onCommand or chrome.action.onClicked

0 Answers
Related