browser

browser 用于配置开发时自动打开并加载扩展的浏览器:可执行文件路径、user-data(profile)目录,以及是否跨启动保留 profile。

概述

  • 类型:Record<BrowserName, { path?: string; profile?: string; keepBrowserProfile?: boolean }>
  • 默认值:undefined(使用系统默认路径)
  • 是否必需:否

每个浏览器条目支持以下字段:

  • path — 浏览器可执行文件路径
  • profile — 自定义 user-data(profile)目录,相对路径相对项目根解析(默认 <outputRoot>/cache/browser-profile/<name>-user-data)
  • keepBrowserProfile — 跨启动保留该浏览器的 profile,覆盖顶层 keepBrowserProfile

Chromium 系浏览器

支持以下基于 Chromium 的浏览器:

浏览器配置键默认路径
Google Chromechrome自动检测
Chromiumchromium自动检测
Microsoft Edgeedge自动检测
Bravebrave自动检测
Vivaldivivaldi自动检测
Operaopera自动检测
Arcarc自动检测

配置示例

// addfox.config.ts
export default defineConfig({
  browser: {
    chrome: { path: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" },
    edge: { path: "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" },
  },
});

使用 CLI 启动

pnpm
npm
yarn
bun
pnpm dev -- -b chrome
pnpm dev -- -b edge
pnpm dev -- -b brave

Firefox

Firefox 使用 web-ext 工具管理扩展,路径配置方式相同:

export default defineConfig({
  browser: {
    firefox: { path: "/Applications/Firefox.app/Contents/MacOS/firefox" },
  },
});

启动 Firefox

pnpm
npm
yarn
bun
pnpm dev -- -b firefox
Info

Firefox 开发模式使用 web-ext 工具,扩展重载由 web-ext 处理而非 Addfox 的 WebSocket。

各平台示例

macOS

export default defineConfig({
  browser: {
    chrome: { path: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" },
    edge: { path: "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" },
    firefox: { path: "/Applications/Firefox.app/Contents/MacOS/firefox" },
  },
});

Windows

export default defineConfig({
  browser: {
    chrome: { path: "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" },
    edge: { path: "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe" },
  },
});

Linux

export default defineConfig({
  browser: {
    chrome: { path: "/usr/bin/google-chrome" },
    chromium: { path: "/usr/bin/chromium-browser" },
    firefox: { path: "/usr/bin/firefox" },
  },
});

已废弃:browserPath

browserPath 仍可使用,但终端会打印 deprecated 警告。请迁移到 browser

// 迁移前(已废弃)
export default defineConfig({
  browserPath: { chrome: "/path/to/chrome" },
});

// 迁移后
export default defineConfig({
  browser: { chrome: { path: "/path/to/chrome" } },
});

同一浏览器同时配置 browserPathbrowser 时,browser 优先。

相关配置