🐛 跨浏览器过滤 userScripts 不支持的 @match scheme - #1772
Open
cyfung1031 wants to merge 10 commits into
Open
cyfung1031 wants to merge 10 commits into
cyfung1031 wants to merge 10 commits into
Conversation
cyfung1031
marked this pull request as ready for review
September 22, 2026 19:38
CodFrm
reviewed
Sep 23, 2026
|
|
||
| export function filterUserScriptApiPatternsByScheme(patterns: readonly string[]): string[] { | ||
| // Firefox 的 match-pattern scheme 集合与 Chromium 不同;这里只在已验证的 Chromium API 边界收紧。 | ||
| if (isFirefox()) return [...patterns]; |
Collaborator
Author
There was a problem hiding this comment.
好像是。应该不用分 firefox 和 chromium. Agent 的处理比较保守
避免未经验证地缩窄 Firefox 现有行为。
E2E 沒 Firefox, Agent 不敢改
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 / 检查清单
背景
#1771 的 RED 用例确认:ScriptCat 会把
notsupported://*/*与有效的https/http一起放进浏览器原生userScripts的 match-pattern 数组,单个不受支持的 scheme 因而使整条 userscript 注册失败。根因不是 MV3 本身,而是 ScriptCat 在进入浏览器原生 match-pattern API 前没有按浏览器 API 契约过滤 scheme。
本次改动
修复位于 ScriptCat 到浏览器原生
userScriptsAPI 的边界,不收窄 ScriptCat 自己的 URL matcher:matches/excludeMatches只保留当前支持的*、http、https、file;Firefox 额外保留其支持的ws、wss、ftp。CompiledResource的启动恢复路径共用同一过滤函数。实现考虑
过滤集合跟随各浏览器的
userScriptsMatch Patterns 契约:Chromium 只接受*、http、https、file;Firefox 的 MV3userScriptsschema 另外接受ws、wss、ftp。因此这次修复同时覆盖两个浏览器,又不会误删 Firefox 支持的 scheme。同时没有通过失败后逐项试注册来“探测”坏 pattern:先在无副作用的 API 投影层按浏览器契约过滤,注册流程保持单次、确定性。
建议审查重点
https/http/notsupported时最终RegisteredUserScript.matches只剩当前浏览器支持的有效项。ws、wss、ftp不会被错误过滤。excludeMatches、全局 blacklist 和旧CompiledResource不会绕过同一过滤;内部 URL 匹配不受影响。关联
Fixes #1771
验证
pnpm exec vitest run src/app/service/service_worker/utils.match-scheme.test.ts src/app/service/service_worker/utils.test.ts src/app/service/service_worker/runtime.test.ts,3 files、85 tests passed。pnpm exec tsc --noEmit --incremental false、Prettier 与 changed-file ESLint 均通过。pnpm exec vitest run:373 files 中 372 passed、1 failed;唯一失败是既有的src/app/service/service_worker/trash_event_partition.test.ts,happy-dom 不支持加载chrome-extension://iframe,与本次改动无关。a0be9f1c3d5372757dd1204733f1ea846cbdabf2的 CI 结果以 GitHub Actions 为准。