> ## Documentation Index
> Fetch the complete documentation index at: https://extension.js.org/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Extension.js needs Node.js 22.12 or newer; Node.js 18 and 20 do not work. It also runs on Deno 2.5+ and Bun 1.2+.
> The default browser target is chromium and a build lands in dist/<browser>, so dist/chromium by default. extension build writes a zip only when --zip is passed.
> Prefix a manifest key with a browser name when browsers differ. chromium: covers every Chromium-family target and Safari builds read it too. Since 4.1.19 chrome: means Chrome alone and edge: means Edge alone.
> Write one background.service_worker in manifest.json instead of hand-writing per-browser background keys; Extension.js converts it for each browser.
> package.json or deno.json marks the project root, not manifest.json. A config file is optional, and only extension.config.js, .mjs and .cjs are loaded, never .ts.
> The bundler is Rspack, extended through the config hook in extension.config.js. A project needs no separate bundler config file.
> Use --no-browser to skip the browser launch; --no-runner no longer exists and --no-open still launches the browser. Use --output for machine output; --format and --wait-format are deprecated.

# CI templates for extension builds

> Automate lint, build, and E2E checks for browser extensions with ready-to-use CI templates for GitHub Actions and other platforms with Extension.js.

Automate lint, build, and end-to-end (E2E) checks so extension changes stay releasable.

Use continuous integration (CI) to run the same quality gates on every pull request and release branch.

> [!NOTE]
>
> [extension.dev](https://docs.extension.dev?utm_source=extension-js-org\&utm_medium=sponsor\&utm_campaign=docs-callout-ci-templates),
> the sponsor of Extension.js, handles publishing, store submission, and sharing
> from the same project. Its docs cover the steps after `extension build`.

## CI capabilities

| Capability | What it gives you |
| - | - |
| Quality gates | Enforce lint, build, and test checks before merge |
| Browser-target confidence | Build and validate multiple browser targets consistently |
| Reproducible environments | Lock toolchain versions across local and CI runs |
| Debuggable failures | Publish test reports and artifacts for investigation |

## Core pipeline stages

1. Install dependencies
2. Run lint/check commands
3. Build browser targets
4. Run automated tests (including Playwright where applicable)
5. Upload artifacts/reports

## Minimal GitHub Actions example

```yaml theme={null}
name: ci

on:
  pull_request:
  push:
    branches: [main]

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: pnpm
      - run: pnpm install --frozen-lockfile
      - run: pnpm lint
      - run: pnpm extension build --browser=chromium
```

## Build matrix example

```yaml theme={null}
strategy:
  matrix:
    browser: [chromium, firefox]
steps:
  - run: pnpm extension build --browser=${{ matrix.browser }}
```

## Playwright in CI

* Install browsers in CI job (`playwright install` or equivalent).
* Keep retries slightly higher on CI than local.
* Publish Playwright reports/artifacts for failed runs.
* Use `dist/extension-js/<browser>/ready.json` as readiness contract before launching Playwright.
* Avoid parsing human-readable logs in CI automation scripts.
* Prefer the built-in wait commands: `extension dev --wait --browser=<browser>` (watch/dev) or `extension start --wait --browser=<browser>` (production/start).
* For scripts or CI automation, prefer `--output json`. The older `--wait-format` alias still works but warns on stderr.
* Under machine output, human copy moves to stderr, so stdout carries exactly one parseable JSON document.
* For teardown, read `browserPid` from `ready.json` and signal that process. It is the supported handle for reaping the browser.

### Example readiness gate

```bash theme={null}
pnpm extension start --wait --browser=chromium --wait-timeout=60000 --output json
```

## Test handlers without a browser UI

You don't always need Playwright. For event handlers (the toolbar action, keyboard commands), Extension.js can fire them directly against a dev session and you assert on the side effect. It's deterministic and headless, so it's a reliable gate.

```yaml theme={null}
- run: |
    pnpm extension dev --browser=chromium --allow-control &
    pnpm extension dev --browser=chromium --wait --output json
    pnpm extension open action --browser=chromium --output json
    pnpm extension storage get --key lastClickedAt --browser=chromium --output json \
      | node -e 'process.exit(JSON.parse(require("fs").readFileSync(0)).value?.lastClickedAt ? 0 : 1)'
```

The first line boots the session, the second gates on its ready contract. `--wait` only waits,
it does not launch a session, so both belong in the same `run:` step.

The same approach replays keyboard commands (`extension open command --name <cmd>`). See [Trigger actions and commands](https://extension.js.org/docs/debugging/trigger-actions-and-commands.md) for the result payloads and the one caveat (replay carries no user gesture, so `activeTab` is not granted).

## Docker and container CI

When CI runs inside Docker or a dev container, pass `--host 0.0.0.0` so external processes can reach the dev server. If another process already occupies the default port, use `--port 0` for automatic port assignment.

```bash theme={null}
pnpm extension dev --host 0.0.0.0 --port 0 --no-browser
```

For slow or resource-constrained containers, increase browser transport timeouts via environment variables (see [browser transport tuning variables](https://extension.js.org/docs/features/environment-variables.md#browser-transport-tuning-variables)).

## Common pitfalls

* CI scripts diverging from local scripts over time
* Building only one browser target while shipping to multiple engines
* Missing artifact upload for failed E2E jobs
* Mixing unpinned Node/package manager versions across workflows

`create` does not scaffold a CI workflow. For a complete example to copy, read the one Extension.js runs on itself:

* [`.github/workflows/e2e.yml`](https://github.com/extension-js/extension.js/blob/main/.github/workflows/e2e.yml)

## Best practices

* Keep CI commands close to local scripts to reduce drift.
* Fail fast on lint/config errors before expensive browser jobs.
* Cache dependencies and browser binaries when possible.
* Version lock CI Node and package manager versions for reproducibility.

## Next steps

* Add or refine [Playwright E2E tests](https://extension.js.org/docs/workflows/playwright-e2e.md).
* Review [commands reference](https://extension.js.org/docs/commands/dev.md) for script alignment.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.