✅ 添加 Firefox MV3 E2E 自动化测试(Selenium + geckodriver)#1503
Draft
CodFrm wants to merge 1 commit into
Draft
Conversation
Collaborator
|
之前 AI搞的那个连接器好像有把 |
87f6b00 to
238062a
Compare
Member
Author
还是有很多问题,还得去查,先draft了 |
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 允许项守护)。
ffe2ca4 to
883658c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist / 检查清单
Description / 描述
新增独立的 Firefox MV3 端到端测试套件,基于当前
main,用 Selenium WebDriver + geckodriver 驱动真实 Firefox,完整跑通「安装用户脚本 → 运行 → 校验 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.mjs—dist/ext→dist/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、jsdelivr→unpkg、httpbun/@connect改指本地 mock、@match收敛到本地端口)。gm-api-sync.mjs— 用例本体:经真实安装页安装 → 打开目标页 → 自动放行权限弹窗 → 读取gm_api_sync_test.js渲染的通过/失败汇总并断言。package.json— 新增test:e2e:firefox脚本 +geckodriver/selenium-webdriver开发依赖。playwright.config.ts—testIgnore增加**/firefox/**,该套件不纳入 Playwright/CI 运行,仅由pnpm run test:e2e:firefox驱动。docs/E2E-FIREFOX.md,并在docs/DEVELOP.md、docs/DOC-MAINTENANCE.md、docs/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 }解包安装。运行 / 验证
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 差异为已知能力缺口,而非套件缺陷。