what's the best way to test a firefox extension when making code changes? I've been trying various approaches: Tried Jest but ran into to many mocking and JSDOM limitations and was having to write tons of new code and modify existing working code to accomodate, not worth it. Tried Playwright but I had issues loading the extension into the tests in a clean and automated way, maybe "playwright-webextext" can fix this issue, I also tried a selenia/jest combo with selenia doing the testing to avoid the JSDOM and mocking issues and then using jest for interpreting but I couldn't get the code to work. So far nothing has worked. I am ready to re-approach all possible solutions and also consider playwright-webextext and the playwright VS Extension as well, this may solve a lot of the issues. What do you think?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
You're clearly in the thick of trying to test a Firefox extension and have already gone through several common approaches, each with its own limitations. Let's break down your options, clarify what works best for extension testing, and then I'll give you a recommendation based on modern tooling and real-world effectiveness.
🧪 What You've Tried So Far
1. Jest + JSDOM
Pros: Fast unit tests, familiar syntax.
Cons:
JSDOM doesn't support browser APIs (browser.*, chrome.*), which are essential in extensions.
Requires heavy mocking.
Forces you to refactor working code just for tests → not ideal.
✅ Good for pure logic functions, but not for full extension behavior.
2. Playwright (without proper ext support)
Pros: Powerful E2E testing, headless mode, fast.
Cons:
Standard Playwright doesn’t load unpacked extensions easily.
No native support for background scripts or content scripts in context of extension environment.
❌ Without proper setup, this won’t work well for extension testing.
3. Selenium + Jest
Pros: Real browser automation.
Cons:
Setup is clunky.
Loading extensions into Selenium is possible but requires extra steps.
Poor integration with modern JS workflows.
🛠️ Possible but not streamlined unless you know all the flags and configs.
✅ The Right Tools for Testing Firefox Extensions
To test an extension effectively, especially during development when making frequent changes, you want:
A way to load the extension into a real browser (or close enough).
The ability to test both UI and background logic.
Support for content scripts, background pages, and extension APIs.
This is a custom launcher that lets you load unpacked extensions into Chromium or Firefox using Playwright. It’s specifically designed for extension testing and solves most of the issues you mentioned.
Why This Works Well:
Loads your extension as if it were installed normally.
Supports:
Content scripts
Background pages
Extension APIs (browser.*)
Integrates seamlessly with Playwright Test, which has better UX than Jest for E2E/browser testing.
💡 How to Use playwright-webext
Step-by-step:
1. Install dependencies
bash
npm install playwright playwright-webext
2. Create a webext.config.ts
ts
import { defineConfig } from 'playwright-webext';
export default defineConfig({
// Path to your manifest.json file
manifestPath: './dist/manifest.json',
// Output directory for built extension
buildPath: './dist',
});
3. Write a test
ts
// example.spec.ts
import { test, expect } from '@playwright/test';
test('popup should show correct title', async ({ page }) => {
await page.goto('web-extension://popup.html');
const title = await page.textContent('h1');
expect(title).toBe('My Extension Popup');
});
4. Run tests
bash
npx playwright-webext test
🚀 Bonus: Live Reload & Dev Mode
If you're actively developing the extension, combine playwright-webext with a watcher like:
vite-plugin-webext (for hot reloading)
web-ext (Mozilla’s dev tool)
Or even custom chokidar scripts
Example command:
bash
npx playwright-webext test --watch
Some versions of playwright-webext support watch mode — check docs for latest.