Extension testingBrowser extensions

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

A service worker lifecycle strip with Active, Idle 30 s, Stopped and Event wakes it stages, above a lost global variable card and a kept chrome.storage card.

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:

  1. Global variables are lost when the worker stops. Persist values to storage instead.
  2. 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:

  1. Load the packed extension in a clean profile.
  2. Use a feature that stores something, for example saving a setting or starting a task.
  3. 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.
  4. 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.addListener or chrome.alarms.onAlarm.addListener called after an await.
  • Timers using setTimeout or setInterval for work longer than the idle window. Use chrome.alarms for 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 .pem key and dropping the new .crx over 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 key so 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.html directly.
  • 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

TagsExtension testingBrowser extensions

See your product through a new user's eyes

A real tester installs it, uses it the way your users would, and writes down every place they got stuck.

Get my reports for $79

More articles

Competitor analysis

How to Run a Competitor Analysis for Your Chrome Extension

A step-by-step competitor analysis for Chrome extension developers. Find who you really compete with, compare listings and experience, mine reviews for gaps, and turn the findings into decisions without copying anyone.

Real Tester team · · 4 min read

Permissions

Chrome Extension Permissions: Request Less, Explain More

Excess permissions cause rejections, long reviews and uninstalls at the permission prompt. How to choose the narrowest permissions, use activeTab and optional permissions, test warnings, and explain what you ask for.

Real Tester team · · 5 min read

Extension testing

Chrome Extension Testing Checklist: What to Check Before You Submit

A practical Chrome extension testing checklist covering the packed build, first run, service worker, permissions, error states and store listing, so reviewers and first users do not find the problems first.

Real Tester team · · 7 min read

Back to blog