> ## 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.

# Special folders for pages and scripts

> Use special folders for extra pages, injected scripts, static assets, and companion extensions that do not fit in manifest.json entrypoints.

Use special folders when your extension needs entrypoints or assets that do not fit cleanly in `manifest.json`.

Handle extra pages, runtime-injected scripts, static assets with exact paths, and companion extensions for local development without splitting your project structure.

## Where special folders live

Special folders resolve from the project root, and only from there. The rule:

* The project root is the directory that contains your `package.json` (or `deno.json`).
* Put `pages/`, `scripts/`, `public/`, and `extensions/` in that directory, next to `package.json`.
* `src/scripts/` is not special. Extension.js ignores nested copies of the special folders, so files there never become entrypoints or copied assets.
* Moving `manifest.json` into `src/` does not move the project root. The scaffolded templates ship `src/manifest.json` with `package.json` one level up, and special folders belong on the `package.json` level.

The one src-rooted exception: a project with no `package.json` and no `deno.json`. There the directory that contains `manifest.json` becomes the project root. When that manifest sits in `src/`, `src/` is the root, and special folders (and `dist/`) live inside `src/`.

> [!WARNING]
>
> **My `scripts/` folder does not appear in `dist/`.** This almost always maps
> to the rule above: the folder sits under `src/` instead of next to
> `package.json`. Move it to the project root. If it is already there, check
> that the file is not a Node.js helper, which [the build leaves
> out](#the-folder-contract).

## Template examples

### `special-folders-pages`

![special-folders-pages template screenshot](https://mintcdn.com/extensionjs/VCnDd7fX2Nza24SE/images/examples/special-folders-pages/screenshot.png?fit=max\&auto=format\&n=VCnDd7fX2Nza24SE\&q=85\&s=34efd0e8532ce82108345f817c2b2b6e)

See the `pages/` special folder in action with extra HTML entrypoints.

```bash npm theme={null}
npx extension@latest create my-extension --template=special-folders-pages
```

```bash pnpm theme={null}
pnpx extension@latest create my-extension --template=special-folders-pages
```

```bash yarn 2+ theme={null}
yarn dlx extension@latest create my-extension --template=special-folders-pages
```

```bash bun theme={null}
bunx extension@latest create my-extension --template=special-folders-pages
```

```bash deno theme={null}
deno run -A npm:extension@latest create my-extension --template=special-folders-pages
```

Repository: [extension-js/templates/special-folders-pages](https://github.com/extension-js/templates/tree/main/examples/special-folders-pages)

### `special-folders-scripts`

![special-folders-scripts template screenshot](https://mintcdn.com/extensionjs/VCnDd7fX2Nza24SE/images/examples/special-folders-scripts/screenshot.png?fit=max\&auto=format\&n=VCnDd7fX2Nza24SE\&q=85\&s=5cc497256988344c504ed3c9f79dae25)

See the `scripts/` special folder in action with standalone script entrypoints.

```bash npm theme={null}
npx extension@latest create my-extension --template=special-folders-scripts
```

```bash pnpm theme={null}
pnpx extension@latest create my-extension --template=special-folders-scripts
```

```bash yarn 2+ theme={null}
yarn dlx extension@latest create my-extension --template=special-folders-scripts
```

```bash bun theme={null}
bunx extension@latest create my-extension --template=special-folders-scripts
```

```bash deno theme={null}
deno run -A npm:extension@latest create my-extension --template=special-folders-scripts
```

Repository: [extension-js/templates/special-folders-scripts](https://github.com/extension-js/templates/tree/main/examples/special-folders-scripts)

## Why this matters

The manifest does not directly declare many extension files. These include iframe pages, scripts you inject dynamically with `chrome.scripting.executeScript`, and static vendor assets. You may also need companion extensions during development. Special folders make all of these first-class in the build pipeline.

## How it works

Each special folder has a specific role:

| Folder name | Description |
| - | - |
| `pages/` | Adds HTML pages to compilation as entrypoints, even when the manifest does not list them. |
| `scripts/` | Adds every script file to compilation as an entrypoint, whether or not the manifest or your code names its path. Node.js helpers are left out. |
| `public/` | Copies static assets to the output root as-is (`public/**` → `dist/**`) without bundling or transformation. |
| `extensions/` | Provides a conventional location for load-only companion extensions in dev/preview/start workflows. |

## `pages/`: additional HTML entrypoints

Use `pages/` for extra extension pages such as sandbox iframes, diagnostics pages, or internal tools.

Extension.js treats each `.html` file in `pages/` as an entrypoint and compiles it like manifest-declared pages.

For a sandboxed iframe example, see the [Chrome Sandbox Sample](https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/api-samples/sandbox/sandbox).

## `scripts/`: standalone script entrypoints

Use `scripts/` for executable scripts that you load dynamically and that do not tie to an HTML page entry.

Extension.js compiles files in `scripts/` as entrypoints using the same extension resolution pipeline as the rest of your project.

### Root location and emitted path

Two facts trip up most `scripts/` setups.

**Location.** `scripts/` lives beside `package.json` (or `deno.json`), at the project root, not inside `src/`. This holds even when `manifest.json` lives in `src/`. The one exception is a project with no `package.json` and no `deno.json`, where the manifest directory is the root. See [where special folders live](#where-special-folders-live).

**Emitted path.** Inject the compiled file. A `scripts/foo.ts` source is compiled to `scripts/foo.js`, so `chrome.scripting.executeScript({ files })` and `chrome.scripting.registerContentScripts({ js })` must name the `.js` file. A `.ts` path builds fine and then fails with a 404 in the browser. Extension.js warns about a compiled source literal at build time. The warning names the emitted path to use.

```ts background.ts theme={null}
// Source: scripts/foo.ts
// Emitted: scripts/foo.js

chrome.scripting.executeScript({
  target: { tabId },
  files: ["scripts/foo.js"],
});

chrome.scripting.registerContentScripts([
  { id: "foo", matches: ["<all_urls>"], js: ["scripts/foo.js"] },
]);
```

In an extension page, start the path at the root, as in `/scripts/foo.js`. Firefox resolves a path with no leading slash against the page. To run the file in the page's own world, see [Inject scripts at runtime](https://extension.js.org/docs/implementation-guide/inject-scripts.md).

### The folder contract

Every file that you put in `scripts/` or `pages/` ships at a predictable output path. `scripts/foo.ts` becomes `dist/<browser>/scripts/foo.js`, and `pages/extra.html` becomes `dist/<browser>/pages/extra.html`. Nothing has to declare the file. A runtime string such as `chrome.runtime.getURL("pages/extra.html")` or `chrome.scripting.executeScript({ files: ["scripts/foo.js"] })` finds it. A file that nothing references ships too, and the build prints no warning about it. The build leaves out Node.js helpers: a file with a shebang, a Node.js import, or a path that a `package.json` script runs. To turn a folder off, set its key to `false` in `extension.config.js`:

```js extension.config.js theme={null}
export default {
  folders: {
    scripts: false,
    pages: false,
  },
};
```

See [special folder locations](https://extension.js.org/docs/features/extension-configuration.md#special-folder-locations) for the full `folders` key.

### A helper module inside `scripts/`

Every file in `scripts/` is built as an entry of its own. A helper that other files import ships as one more file that nothing loads. From the release after 4.1.39, the build prints one warning for a file that other files import and that nothing names by its output path. The warning prints the `exclude` value to paste:

```plaintext theme={null}
scripts/helper.js is built as an entry of its own because every file in scripts/ is, yet other files import it and nothing names its output path. For a helper module, add exclude: ['scripts/helper.js'] to extension.config.js. For a script the extension injects, keep it.
```

```js extension.config.js theme={null}
export default {
  exclude: ["scripts/helper.js"],
};
```

With that key, the file is no longer emitted and the warning stops. A file that your code names by its output path does not warn, because that script is injected.

### Important contract

When you use a `scripts/` entry as a content-script-like runtime entry, follow the content script initialization pattern. This is the default-export contract Extension.js expects for safe hot-reload of injected scripts:

* Export a default function.
* Perform setup inside that function.
* Optionally return a synchronous cleanup.

This matters most during development, where Extension.js remounts content-script-like entries safely instead of using full page reloads.

### Node.js scripts are not allowed in `scripts/`

Extension.js wraps every file inside `scripts/` with a browser content-script mount runtime. If you place a Node.js-only file there (for example, a CLI launcher or build helper), the wrapper breaks the file.

The shebang is no longer on line 1, and Node-only APIs are unavailable in the browser context.

Extension.js detects two Node.js indicators and leaves the file out of the build:

* A shebang (`#!/usr/bin/env node`) on line 1.
* An import from the `node:` protocol (for example, `import fs from 'node:fs'`).

> [!WARNING]
>
> If you see `scripts/ is a reserved folder in Extension.js`, move the file to a
> different folder at the project root, for example, `bin/`, `tools/`, `ops/`,
> `tasks/`, or `ci-scripts/`.

For dynamic injection examples, see the [Chrome Scripting Sample](https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/api-samples/scripting).

## Development-only entries

A page or script whose name carries `.dev.` before its extension is a development-only entry. `extension dev` compiles it like any other file in its folder. A production build (`extension build`, `extension start`) leaves it out: no HTML, no chunk, and nothing in the generated manifest names it.

```text theme={null}
pages/
├── engine.html          # ships
├── player.dev.html      # development only
└── bench/
    └── parity.dev.html  # development only
scripts/
├── content.ts           # ships
└── bench.dev.ts         # development only
```

Use it for a test harness page, a model-parity bench, or a script only a developer runs. A harness page can play local footage under the extension's overlay. During development the file keeps its folder's output path, so `chrome.runtime.getURL("pages/player.dev.html")` finds it. The page is not in the production output, so guard that reference in code that ships, for example behind `process.env.NODE_ENV !== "production"`.

* The convention reads the file name only. A folder named `dev/` is a plain folder, and `pages/dev/player.html` ships.
* `extension build --mode development` is a development compile, so it keeps these entries.
* A file that is not an entry, such as a `player.dev.css` a page imports, follows the page that imports it.
* To copy extra files into a build by mode or environment, see [`include` in extension.config.js](https://extension.js.org/docs/features/extension-configuration#extra-files-in-the-build).

## Leaving a file out of one browser

A page or script that only one browser family uses, such as an offscreen document Chromium opens while Firefox does the same work in another page, can be left out of the other browser's build with the `exclude` key in `extension.config.js`. Needs 4.1.39 or later. Each entry is a path relative to the project root. A page or script in a special folder named here gets no entry and emits nothing: no HTML, no chunk, no stylesheet. A file under `public/` named here is not copied.

```js theme={null}
// extension.config.js
export default {
  browser: {
    firefox: {
      exclude: ["pages/offscreen.html"],
    },
  },
};
```

`extension build --browser=firefox` now ships `dist/firefox/pages/` without the offscreen page, and `extension dev --browser=firefox` leaves it out too. The Chrome build is unchanged. The same key works at the top level, where it applies to every browser, and under `commands.dev`, `commands.start` or `commands.build`. The lists add up: a file named in any layer is left out.

The `.dev.` suffix decides by mode and `exclude` decides by browser. A file can use both.

* If the manifest still names an excluded file for that browser, the build stops with an error that names the file and the browser, because the manifest would point at a file the output does not hold. Scope the manifest key with a `chromium:`, `gecko:` or `safari:` prefix so the reference exists only where the file ships, or remove the file from `exclude`.
* A script that opens the page at runtime, like `chrome.offscreen.createDocument({ url: "pages/offscreen.html" })`, no longer pulls it back into the build. Guard that call so it runs only where the page ships.
* An entry that matches no file in the project produces a warning, so a typo does not ship the page silently.
* Entries are exact file paths. Folders and glob patterns are not read.

## `public/`: copy-only static assets

Use `public/` when you need stable file paths and no bundling/transformation.

Extension.js copies everything under `public/` to the output root 1:1.

From the release after 4.1.39, that copy is byte for byte in every mode. A production build does not minify or transform a file under `public/`. A vendored script keeps its license banner, its last expression, and its `sourceMappingURL` comment. A file that you declare under `include` in `extension.config.js` ships the same way, except a script. A production build minifies an included script unless you opt out, see [Extra files in the build](https://extension.js.org/docs/features/extension-configuration.md#extra-files-in-the-build).

[Extension.js: the public folder](https://www.youtube-nocookie.com/embed/ZAsyjtiUbNM?rel=0)

### Important `public/` guard

Do not place `manifest.json` at `public/manifest.json`. Extension.js prevents this to avoid overwriting the generated manifest during compilation.

## `extensions/`: companion extensions (load-only)

When you use companion extensions (for example, DevTools helpers), Extension.js supports an `extensions/` folder as a load-only source in dev/preview/start flows.

At a high level:

* Scans subfolders under `extensions/` for unpacked extension roots (`manifest.json` present).
* A subfolder named for a browser loads only for that browser family: `extensions/chrome/` for Chromium targets, `extensions/edge/` for Edge, and `extensions/firefox/` for Gecko targets. Root-level subfolders and entries you configure explicitly load everywhere.
* Extension.js loads companion extensions alongside your main extension.
* Use this folder to load companion extensions, not to build them into your main artifact.

You can also load companion extensions via the `--extensions` CLI flag or the `extensions` key in `extension.config.js`:

```bash theme={null}
# Load from a local folder
npx extension@latest dev --extensions ./path/to/companion

# Load from Chrome Web Store or Firefox Add-ons
npx extension@latest dev --extensions "https://chromewebstore.google.com/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi"
```

Extension.js automatically downloads, unpacks, and loads store URLs alongside your extension.

Accepted store links are `chromewebstore.google.com` (and the legacy `chrome.google.com/webstore` form), `microsoftedge.microsoft.com`, and `addons.mozilla.org`, with or without a scheme or a `www.` prefix. A downloaded store extension lands under `extensions/<browser>/` and loads only for that browser. A link from another host, a bare store id, or an entry that is neither a link nor a path is reported as an error instead of being dropped.

## Development behavior (watch mode)

In development watch mode, Extension.js monitors `pages/` and `scripts/` for file set changes:

* Adding supported files triggers a warning (you can keep working).
* Removing a supported file triggers a compilation error. Restart the dev server to recover.

This protects the running compilation graph from stale or broken entrypoints.

## Best practices

* **Keep shared runtime assets in `public/`**: Use it for files that must keep exact names and paths in output.
* **Use `pages/` and `scripts/` for true entrypoints**: Keep off-manifest execution paths explicit.
* **Name test harness pages `.dev.`**: A `pages/player.dev.html` runs in `extension dev` and never reaches a store build.
* **Restart dev server after entrypoint changes**: Especially after removing files under `pages/` or `scripts/`.
* **Keep companion extensions isolated**: Treat `extensions/` as load-only dependencies for local workflows.
* **Do not place `manifest.json` in `public/`**: Extension.js blocks `public/manifest.json` to protect the generated extension output.

## Next steps

* Learn more about [Page reload and hot module replacement (HMR)](https://extension.js.org/docs/features/reload-and-hmr.md).
* Understand the mount contract in [Content scripts](https://extension.js.org/docs/implementation-guide/content-scripts.md).
* Browse the [Templates](https://extension.js.org/docs/getting-started/templates.md) to scaffold your next extension.

## See the template run

[Extension.js: Special Folders Scripts template](https://www.youtube-nocookie.com/embed/P8Q8TDQqbQE?rel=0)


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