🐛 修复 Firefox 用户脚本 DOM realm 不一致 - #1697
Open
CodFrm wants to merge 1 commit into
Open
Conversation
cyfung1031
self-requested a review
August 28, 2026 11:00
Collaborator
|
跟 #1692 一样,需要实际可以重现问题的 userscript 进行确认 ( 沉浸式翻译 以外的独立脚本) |
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.
背景
Firefox 的
USER_SCRIPTworld 与页面 Window 属于不同的 JavaScript realm。ScriptCat 创建用户脚本上下文时,存在两处兼容性问题:getter is null。Node、Element、HTMLElement等构造器来自USER_SCRIPTrealm,导致instanceof判断失败。沉浸式翻译因此无法遍历正文节点,只能处理标题。修改
Reflect.get/Reflect.set转发属性访问,使 Firefox 懒加载属性始终读取已经物化后的原属性。getComputedStyle对齐到页面 Window realm。Promise、Error、JSON、Math、Number等 JavaScript intrinsic 来自USER_SCRIPTrealm。本 PR 只修改 Content 用户脚本上下文,不修改 Popup、GM XHR,也不新增或特殊处理
GM_fetch。验证
pnpm run lint:通过pnpm test:343 个测试文件、4296 个测试通过pnpm run build:通过create_context.test.ts、exec_script.test.ts,共 55 个测试通过git diff --check:通过https://example.com/实测:标题、正文段落和链接均成功生成双语节点,共检测到 8 个沉浸式翻译正文节点构建仍会输出已有的 bundle/entrypoint 体积警告,以及 Monaco
editorSimpleWorker.js动态require警告;这些警告未导致构建失败,且不属于本次改动范围。Checklist / 检查清单
未关联 GitHub Issue,因此第一项不适用。