Testing a Manifest V3 Extension: Service Workers, Storage and Updates
Manifest V3 extensions run on a service worker that Chrome stops when idle. How to test for lost state, missed events, remote code and permission updates, and what Puppeteer, Playwright and Selenium can and cannot do for you.
Real Tester team · · 6 min read

The biggest change Manifest V3 made for extension testing is the background context. A persistent background page is gone. In its place is an extension service worker that Chrome starts when it is needed and stops when it is not. Code that relied on staying alive, or on variables staying set, works in a quick manual test and fails for real users.
This guide covers what to test because of that, and how to do it.
What Chrome does to your service worker
From Chrome's lifecycle documentation, an extension service worker is normally terminated when:
- it has been inactive for 30 seconds. Receiving an event or calling an extension API resets the timer;
- a single request, such as an event or API call, takes longer than 5 minutes to process;
- a
fetch()response takes more than 30 seconds to arrive.
Chrome's advice is to design the worker to be resilient to unexpected termination. Two consequences follow:
- Global variables are lost when the worker stops. Persist values to storage instead.
- The worker has to be woken by events. Listeners must be registered synchronously at the top level, so they exist when Chrome starts the worker to deliver an event.
Some behavior depends on the Chrome version, so check the minimum version you declare. For example, active WebSocket connections extend worker lifetime from Chrome 116, extension API calls reset the idle timer from Chrome 110, and the minimum period for alarms is 30 seconds from Chrome 120.
Test 1: the idle gap
The simplest and most useful test:
- Load the packed extension in a clean profile.
- Use a feature that stores something, for example saving a setting or starting a task.
- Leave the browser alone for longer than 30 seconds. To force the issue, open the extension's service worker link on
chrome://extensions, go to the Application panel in DevTools and stop the worker there. Close DevTools afterward, since an open inspector can keep the worker running. - Use the feature again.
What should happen: the second action works exactly like the first, with the state you saved. What often happens: a counter is back to zero, a cached token is undefined, an in-memory queue is empty, or a message gets no reply because the listener was registered inside an async callback.
Look for these in code review as well:
let something = ...at the top of the service worker that holds state.chrome.runtime.onMessage.addListenerorchrome.alarms.onAlarm.addListenercalled after anawait.- Timers using
setTimeoutorsetIntervalfor work longer than the idle window. Usechrome.alarmsfor scheduled work, remembering the 30-second minimum.
Test 2: storage
Pick the right store and test its edges.
| API | Survives worker restart | Survives browser restart | Notes |
|---|---|---|---|
| Global variable | No | No | Gone when the worker stops |
chrome.storage.session |
Yes | No | In-memory for the session |
chrome.storage.local |
Yes | Yes | Not removed when the user clears the web cache |
chrome.storage.sync |
Yes | Yes | Synced across the user's browsers; has quotas |
| IndexedDB | Yes | Yes | Good for larger structured data |
localStorage / sessionStorage |
n/a | n/a | Web Storage is not available in extension service workers |
Check that the storage permission is declared if you use chrome.storage, and that you do not declare it only for localStorage or IndexedDB, which do not need it. That is a classic Purple Potassium trigger. See what the violation IDs mean.
Test 3: install, startup and update paths
The documentation lists the order of events on installation: the service worker install event, then runtime.onInstalled, then activate. onInstalled also fires when the extension is updated and when Chrome is updated, so guard one-time work with details.reason.
On profile startup, runtime.onStartup fires but no service worker events are invoked. If your code needs to re-create state at startup, test that it does.
Checks:
- Fresh install creates context menus and default settings once, not twice.
- Update from the previous published version keeps the user's data. Install the old version first, save some data, then update to the new one.
- A new permission with a warning disables the extension until the user accepts it. Chrome documents two ways to test it: the Extension Update Testing Tool, or manually packing with the same
.pemkey and dropping the new.crxover the old install. Do this before shipping any version that adds a warning permission, or a share of your users will find the extension disabled.
Test 4: no remote code
Manifest V3 requires that the full functionality of the extension is discernible from the submitted code. Violations show up as Blue Argon. Look for:
<script src="https://...">in extension pages.eval(),new Function()or similar on strings fetched at runtime.- An interpreter that runs commands delivered by a server, even as "data".
Fetching data and configuration is fine as long as it contains no logic. Search your bundle for external URLs before every release, including those added by third-party SDKs.
Test 5: packed vs unpacked
Chrome notes unpacked and packed extensions can behave differently. Test the packed .crx and the zip you will upload. Include:
- All icons, popup and options files present.
- No case-sensitivity mismatches in file names.
- The extension ID: if your code or your backend depends on a fixed ID, set the manifest
keyso the ID is stable between builds.
Automating what can be automated
Chrome's end-to-end testing guide lists the supported tools: Puppeteer and Playwright, Selenium (load the extension with ChromeOptions) and WebdriverIO. Notes worth knowing:
- Use Chrome's new headless mode (
--headless=new) when running in CI, because the old headless mode did not support loading extensions. - Set a fixed extension ID so tests can open
chrome-extension://<id>/popup.htmldirectly. - To test a popup, either open it with
action.openPopup()where the tool supports it, or load the popup URL in a tab and pass the tab ID explicitly. - Prefer testing visible behavior to reading internal state. If you must inspect state, Puppeteer can attach to the service worker target; Selenium cannot, so execute code from an extension page instead.
- Service worker termination needs special handling. With Selenium, ChromeDriver attaches a debugger to all service workers, which keeps them from stopping, so idle-gap bugs will not show up. Chrome has a guide for testing termination with Puppeteer.
That last point matters: a green end-to-end run can mean the worker was never stopped. Keep the manual idle-gap test in your release routine.
Where automation stops
Scripts verify that a flow completes. They do not tell you that a new user would not find the button, that the permission prompt is confusing, or that the error message blames the user. We cover that split in manual vs automated testing for Chrome extensions. A human pass on the packed build, on a clean profile, with the worker allowed to go idle, is the cheapest way to find what automated runs miss.
Sources
- Chrome for Developers, Extension service worker lifecycle
- Chrome for Developers, End-to-end testing for extensions
- Chrome for Developers, Permission warnings
- Chrome for Developers, Troubleshooting Chrome Web Store violations


