Skip to content

✅ 添加 Firefox MV3 E2E 自动化测试(Selenium + geckodriver)#1503

Draft
CodFrm wants to merge 1 commit into
mainfrom
test/firefox-e2e-automation
Draft

✅ 添加 Firefox MV3 E2E 自动化测试(Selenium + geckodriver)#1503
CodFrm wants to merge 1 commit into
mainfrom
test/firefox-e2e-automation

Conversation

@CodFrm

@CodFrm CodFrm commented Jun 12, 2026

Copy link
Copy Markdown
Member

Checklist / 检查清单

  • Fixes mentioned issues / 修复已提及的问题
  • Code reviewed by human / 代码通过人工检查
  • Changes tested / 已完成测试

Description / 描述

新增独立的 Firefox MV3 端到端测试套件,基于当前 main,用 Selenium WebDriver + geckodriver 驱动真实 Firefox,完整跑通「安装用户脚本 → 运行 → 校验 GM API」链路。

本 PR 已重写。旧实现基于 Playwright + file:// 页面级 mock,无法覆盖真实 moz-extension:// 后台/内容脚本/GM 链路;现改为 Selenium 方案后已能驱动真实扩展页与真实 GM API。

为什么不用 Playwright

Chrome E2E 套件用 Playwright + --load-extension,但 Firefox 不适用:Playwright 的 Firefox 无法渲染任何 moz-extension:// UI 页(page.goto、DNR 重定向、扩展自身 tabs.create 都停在 about:blank,见 Playwright #3792 / #2644)。没有扩展 UI 就无法驱动安装页,故 Firefox 套件改用 Selenium WebDriver + geckodriver(Marionette),可正常渲染 moz-extension:// 页面。

变更内容

  • e2e/firefox/
    • build-ext.mjsdist/extdist/firefox,套用与 scripts/pack.js 相同的清单变换(去 background.service_worker、删 sandbox、加 browser_specific_settings.gecko)。
    • driver.mjs — Selenium + geckodriver 启动;解包安装临时 add-on;固定 moz-extension UUID;预授予 userScripts / <all_urls> 权限。
    • mock-server.mjs — GM API mock 服务 + userscript 补丁(镜像 e2e/gm-api.spec.ts:剥离 integrity、jsdelivrunpkghttpbun/@connect 改指本地 mock、@match 收敛到本地端口)。
    • gm-api-sync.mjs — 用例本体:经真实安装页安装 → 打开目标页 → 自动放行权限弹窗 → 读取 gm_api_sync_test.js 渲染的 通过/失败 汇总并断言。
  • package.json — 新增 test:e2e:firefox 脚本 + geckodriver / selenium-webdriver 开发依赖。
  • playwright.config.tstestIgnore 增加 **/firefox/**,该套件不纳入 Playwright/CI 运行,仅由 pnpm run test:e2e:firefox 驱动。
  • 文档:新增 docs/E2E-FIREFOX.md,并在 docs/DEVELOP.mddocs/DOC-MAINTENANCE.mddocs/README.md 建立索引。

关键坑:必须解包安装 add-on

Selenium 的 driver.installAddon(dir, true) 会先把目录 zip 再安装。从 zip 临时 add-on 里,Firefox 内容进程无法加载 content-script 源文件 → Unable to load script: .../src/scripting.js(ScriptCat 经 chrome.scripting.registerContentScripts 注册的 ISOLATED 桥),导致 SW ↔ content ↔ inject 链路断开,每个用户脚本静默不执行。修复:改为向 geckodriver 原始端点 POST /session/{id}/moz/addon/install{ path, temporary: true } 解包安装

运行 / 验证

pnpm run build            # 产出 dist/ext(需 Firefox ≥ 136)
pnpm run test:e2e:firefox # 打 dist/firefox → 驱动 Firefox → 跑 gm_api_sync → 断言
  • 普通页(NO_CSP=1):29/29 全通过。
  • script-src 'none' CSP 页(默认目标):28/29。唯一失败 GM_addElement - 创建元素——GM_addElement("script", { textContent }) 注入的内联脚本在 Firefox 不绕过页面 CSP(Chrome 会),故 unsafeWindow.foo === "bar" 失败。该差异以 KNOWN_CSP_GAPS 允许项守护,套件保持绿色但对回归仍会失败。

已知限制

ScriptCat MV3 尚未正式支持 Firefox(scripts/pack.js 仍保持 PACK_FIREFOX = false)。本套件用于驱动 Firefox 构建跑通端到端流程并守护已可用的部分;上面的 CSP 差异为已知能力缺口,而非套件缺陷。

@cyfung1031

cyfung1031 commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

vscode-connect 理论上可以在 event page 直接搞
但我没详细测试过可行性

之前 AI搞的那个连接器好像有把 vscode-connect 放在iframe里做。没测试

@CodFrm CodFrm force-pushed the release/v1.4-agent branch 3 times, most recently from 87f6b00 to 238062a Compare June 12, 2026 13:20
@CodFrm CodFrm marked this pull request as draft June 13, 2026 13:50
@CodFrm

CodFrm commented Jun 13, 2026

Copy link
Copy Markdown
Member Author

vscode-connect 理论上可以在 event page 直接搞 但我没详细测试过可行性

之前 AI搞的那个连接器好像有把 vscode-connect 放在iframe里做。没测试

还是有很多问题,还得去查,先draft了

@CodFrm CodFrm changed the base branch from release/v1.4-agent to main July 2, 2026 16:25
Playwright 无法渲染 moz-extension:// 扩展 UI 页,故新增独立的 Firefox
MV3 E2E 套件,用 Selenium WebDriver + geckodriver 驱动真实 Firefox:

- e2e/firefox/:build-ext(dist/ext→dist/firefox 清单变换)、driver
  (解包安装临时 add-on,规避 zip 导致 content script scripting.js 加载
  失败)、mock-server(GM API mock + userscript 补丁)、gm-api-sync(经
  真实安装页安装 → 跑 gm_api_sync → 断言)。
- test:e2e:firefox 脚本 + geckodriver / selenium-webdriver 开发依赖。
- playwright.config.ts 忽略 **/firefox/**,该套件不入 Playwright 运行。
- 新增 docs/E2E-FIREFOX.md,并在 DEVELOP / DOC-MAINTENANCE / README 索引。

普通页 29/29,script-src 'none' CSP 页 28/29(GM_addElement 注入内联
script 在 Firefox 不绕过页面 CSP,以 KNOWN_CSP_GAPS 允许项守护)。
@CodFrm CodFrm force-pushed the test/firefox-e2e-automation branch from ffe2ca4 to 883658c Compare July 3, 2026 07:42
@CodFrm CodFrm changed the title ✅ 添加 Firefox E2E 自动化测试 ✅ 添加 Firefox MV3 E2E 自动化测试(Selenium + geckodriver) Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants