Chrome extensions / Manifest V3

When an MV3 service worker goes quiet.

Manifest V3 background code runs in an event-driven service worker. It can stop and restart, so a global variable is not durable state. Debug the lifecycle and the data boundary together.

1. Inspect the worker that is actually loaded

Open chrome://extensions, enable Developer mode, find the extension, and open its service worker inspection link. Reproduce one action while watching the console. Confirm the loaded manifest points at the file you edited and that the worker has not stopped on an earlier exception.

After a code change, reload the extension and close stale DevTools windows. A background console from an old version can make a correct fix look ineffective.

2. Treat globals as a cache, not a database

Because the worker may restart, read durable state from chrome.storage inside the event that needs it. Validate the result before dereferencing it and return a useful response when setup has not happened yet.

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  if (message?.type !== 'OPEN_PROJECT') return;
  chrome.storage.local.get('activeProject').then(({ activeProject }) => {
    if (!activeProject?.id) {
      sendResponse({ ok: false, code: 'PROJECT_NOT_SELECTED' });
      return;
    }
    sendResponse({ ok: true, id: activeProject.id });
  });
  return true; // keep the channel open for the async response
});

3. Check permissions and message contracts

Use DebugSmith

Have the manifest, console error, and message handler?

Paste the smallest relevant pieces for a focused repair packet. DebugSmith never executes an extension or changes your files.

Run a free scan

Further reading: Chrome extension service workers and Chrome extension messaging.