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

# 2026 年 11 月：更聪明的重载与带代码的错误

> Extension.js 2026 年 11 月更新：只在需要时重载、带稳定代码的构建诊断、按浏览器各自编译的输出，以及自带 worker 的包。

**November 2026**

December 3, 2026

11 月发布了八个版本，从 [4.1.39](https://github.com/extension-js/extension.js/releases/tag/v4.1.39) 到 [4.4.2](https://github.com/extension-js/extension.js/releases/tag/v4.4.2)，其中三个次版本在五天之内发出。大部分工作都落在同一个地方：一个每次保存做得更少、出问题时说得更多的 dev 会话。

## 只在需要时重载

从 [4.3.0](https://github.com/extension-js/extension.js/releases/tag/v4.3.0) 起，保存一个构建从未读取的文件不再重载扩展，保存一个页面只会重载正在显示它的标签页。[4.2.0](https://github.com/extension-js/extension.js/releases/tag/v4.2.0) 让它底下的循环更稳。修复了构建错误的那次保存会重新构建页面，被删除又写回的 content script 文件会被重新构建，macOS 上的 [dev](https://extension.js.org/zh-Hans/docs/commands/dev.md) 也不再漏掉一次编辑。

[4.4.0](https://github.com/extension-js/extension.js/releases/tag/v4.4.0) 让重新构建本身更快。在一个大项目上，每次重新构建都会运行的两个步骤从大约 155 毫秒降到了 30 毫秒以内，一个缺失的文件回来之后不用再保存一次就会重新构建。

## 脚本可以匹配的错误

4.2.0 给具名的构建警告和错误一个[稳定的代码](https://extension.js.org/zh-Hans/docs/contracts/error-codes.md)，`--output json` 报告它们时不带终端排版，也不带你机器上的路径。4.3.0 把这一点延伸到了会话。一次没有生效的重载会在 `--output json` 和 `events.ndjson` 里报告 `W_RELOAD_NOT_APPLIED`，一个损坏的 `package.json` 会让 `build`、`dev`、`start` 和 `preview` 以 `E_PACKAGE_JSON_INVALID` 停下。

过去会卡住的失败现在会结束。浏览器在 3 分钟内没有启动，会以 `E_BROWSER_START_TIMEOUT` 报告，而重新构建继续运行。从 4.4.0 起，解析失败的 JSON 文件按行和列报告，绝不引用它的内容。

## 每个浏览器各自构建

4.3.0 为 `firefox >= 98` 编译 Firefox 输出，为 `safari >= 15.4` 编译 Safari 输出，像 `"gecko:tabs"` 这样带前缀的权限[只留给它的浏览器](https://extension.js.org/zh-Hans/docs/features/browser-specific-fields.md)。[4.1.40](https://github.com/extension-js/extension.js/releases/tag/v4.1.40) 做了面向商店的那一半：

* Firefox 构建会[拆分大文件](https://extension.js.org/zh-Hans/docs/commands/build.md#firefox-构建会拆分大文件)，让 addons.mozilla.org 能解析每一个脚本，并点名它无法拆分的文件。
* [`icon_variants`](https://extension.js.org/zh-Hans/docs/implementation-guide/icons#图标变体) 可以为每个浏览器构建。还不读取这个键的浏览器，包括 Safari，会得到由你的变体填好的 `icons`。
* `browser` polyfill 在 [Chromium 上默认关闭](https://extension.js.org/zh-Hans/docs/features/multi-platform-builds.md#为浏览器-api-打-polyfill)，因为 Chromium 148 及之后的版本原生带有 `browser`。要为更旧的版本保留它，传入 `--polyfill`。

4.1.39 加入了 `exclude` 键，它能[让某个浏览器的构建不带某个页面或脚本](https://extension.js.org/zh-Hans/docs/features/special-folders.md#让某个浏览器不带某个文件)，还加入了一个去掉 manifest `key` 的 Edge 商店 zip，而 `dist/edge` 为你的 OAuth 重定向保留它。

## MAIN world 脚本与 content script 样式

你的 background 在运行时注册或注入到 [MAIN world](https://extension.js.org/zh-Hans/docs/implementation-guide/content-scripts.md#main-world-注意事项) 的文件现在可以在 dev 中工作。从 4.1.40 起，它会在 Chrome 和 Firefox 上加载自己的 chunk 并解析扩展 URL。使用 `polyfill: true` 时，4.2.0 不再把 `webextension-polyfill` 放进 MAIN world content script 和沙箱页面，它在那里会抛出错误。

content script 的样式得到了同样的关注。组件样式、CSS modules 和 Vue 的 `<style>` 块现在都能到达页面，样式表的编辑不用重载就会出现在打开的标签页里。

## 干净启动、立即退出的浏览器

[4.4.1](https://github.com/extension-js/extension.js/releases/tag/v4.4.1) 关心的是窗口本身。在保留的 profile 上运行的 Chrome 会话不再以扩展被关闭而结束。Edge 不再显示 "Installed theme, Undo" 提示条，Edge 和 Chromium 也都不再显示 "unsupported command-line flag" 提示条。在 `preview` 和 `start` 里按 Ctrl+C，会随着浏览器进程结束而退出，过去要五秒，现在远不到一秒。

4.4.0 覆盖了启动。一个[固定的浏览器二进制](https://extension.js.org/zh-Hans/docs/browsers/running-other-browsers.md)永远不会被忽略，所以单独的 `--gecko-binary` 就会运行一个 Gecko 浏览器，启动失败时会说出是哪个二进制以及是什么固定了它。在 Windows 上，Ctrl+C 会立即关闭浏览器，Firefox 会话会跟着浏览器度过一次自我更新。

## 自带 worker 的包

[4.4.2](https://github.com/extension-js/extension.js/releases/tag/v4.4.2) 是为那些带着 `@ffmpeg/ffmpeg` 或某个 SQLite 构建这类重型包的扩展准备的。URL 只有在运行时才知道的 `import(url)` 和 `new Worker(new URL(url, import.meta.url))` 会保持原样，过去它们会被编译成一个必定抛出错误的调用。用 `?url` 导入的模块会连同它导入的文件一起发布，对带有 `exports` 映射的包做 `?url` 导入也能解析。

按名字从文件夹导入的 service worker，例如 ``import(`./locales/${name}.js`)``，又可以构建了，这些文件会放在 worker 里面。

## 你的配置会被遵循

从 4.3.0 起，Babel 配置在 SWC 之前运行，tsconfig 的 `jsxImportSource` 和 `useDefineForClassFields` 会生效，`extension.config.js` 能看到命令的模式和浏览器。[4.1.41](https://github.com/extension-js/extension.js/releases/tag/v4.1.41) 放宽了[默认类型](https://extension.js.org/zh-Hans/docs/languages-and-frameworks/typescript.md#扩展-api-的类型)，让它接受浏览器接受的调用，例如 `chrome.tabs.sendMessage(tabId, message, callback)`，不需要 `@types/chrome`。

## 另外

从 4.2.0 起，`.env`、`.npmrc` 和 `.git` 这类私有文件永远不会被复制进构建，即使它们在 `public/` 里，生产构建会在某个公开环境变量的[名字像密钥](https://extension.js.org/zh-Hans/docs/features/environment-variables.md#密钥永远不要使用-extension_public_-前缀)时发出警告。遥测从 4.2.0 起遵守 [`DO_NOT_TRACK`](https://extension.js.org/zh-Hans/docs/features/telemetry-and-privacy#退出方式)，`extension telemetry reset` 会删除保存的 ID。Safari 构建会使用[你自己的应用图标](https://extension.js.org/zh-Hans/docs/browsers/safari.md#app-身份与打包选项)，`npx extension@latest create my-extension --template=devtools-typescript-sqlite` 会创建一个由 SQLite 支撑的 DevTools 面板。

12 月以即将到来的 4.4.3 开场。项目里没有安装框架时，`.svelte` 或 `.vue` 文件会说明该安装什么，生产构建会停下来，而不是发布未编译的 Sass。下次再细说。

Cezar Augusto\\

Creator and Lead Developer, Extension.js


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