Skip to content

🐛 过滤 Chromium 不支持的 @match scheme - #1772

Open
cyfung1031 wants to merge 9 commits into
mainfrom
fix/invalid-match-scheme-1771
Open

cyfung1031 wants to merge 9 commits into
mainfrom
fix/invalid-match-scheme-1771

Conversation

@cyfung1031

@cyfung1031 cyfung1031 commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Checklist / 检查清单

背景

#1771 的 RED 用例确认:ScriptCat 会把 notsupported://*/* 与有效的 https/http 一起放进 Chromium chrome.userScripts 的 match-pattern 数组,单个不受支持的 scheme 因而使整条 userscript 注册失败。

根因不是 MV3 本身,而是 ScriptCat 在进入浏览器原生 match-pattern API 前没有做 Chromium scheme 约束。

本次改动

修复放在 ScriptCat → 浏览器 API 边界,不收窄 ScriptCat 自己的 URL matcher:

  • Chromium 原生 matches / excludeMatches 只保留当前支持的 *httphttpsfile;Firefox 不套用 Chromium 白名单。
  • 新构建的 userscript 注册、全局黑名单原生排除、以及已有 CompiledResource 的启动恢复路径统一经过同一过滤函数。
  • 旧缓存混有有效/无效 scheme 时保留有效项;如果过滤后没有任何可注册 match,则不创建无效的原生注册项。
  • ScriptCat 内部 matcher 仍保留原规则,因此这次修复不会把“浏览器 API 能否注册”错误地变成“ScriptCat 是否能解析/展示该规则”。

这是本次的 Pareto 范围:覆盖会重新把坏 pattern 送入浏览器的高影响入口与升级缓存路径;编辑器诊断、注册状态 UX 和更广泛 matcher 重构不混入这个 bug-fix PR。

实现考虑

静态 scheme 过滤只解决已经确认的 Chromium API 契约;不把 Chromium 的集合强加给 Firefox,避免未经验证地缩窄 Firefox 现有行为。

同时没有通过失败后逐项试注册来“探测”坏 pattern:先在无副作用的 API 投影层过滤,注册流程保持单次、确定性。

建议审查重点

  • 混合 https/http/notsupported 时最终 RegisteredUserScript.matches 只剩有效项。
  • excludeMatches、全局 blacklist 和旧 CompiledResource 不会绕过同一 scheme 过滤。
  • 过滤只影响原生注册投影,不影响 ScriptCat 内部 URL 匹配。

关联

Fixes #1771

验证

  • TDD RED: commit 2f4d5edb5e8ce309abb7efe9e223e4c596e8e6de,GitHub Actions run 35743071085 明确失败于新增断言:实际结果多出 notsupported://*/*
  • 中间实现 head 049576d1bdc2e61101382f529646060678c3a6de 的完整 GitHub Actions run 35774571203 已通过。
  • 最终 head 007533fffac2256cd1d850f58a162ead748847e1:GitHub Actions run 35774779814 完整通过(pnpm lint:ci、2 个 Vitest coverage shards + merge、4 个 Playwright E2E shards);License Compliance 也为 success。
  • 本地容器无法解析 github.com,因此未伪称本地 pnpm 结果;可执行验证以 GitHub Actions 为准。

@cyfung1031
cyfung1031 marked this pull request as ready for review September 22, 2026 19:38
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.

[BUG] Unsupported @match scheme invalidates the whole userscript registration

1 participant