Repository navigation
🐛 修复 popup 不显示仅匹配 iframe 的未启用脚本 - #1837
Merged
Merged
Conversation
子 frame 合并原先要求「本 tab 跑过 ∧ 仍匹配子 frame」,禁用脚本永远不会运行, 因此只匹配 iframe 的禁用脚本无法出现在 Popup 里被启用;刚启用、尚未运行的脚本也会 因开关切换从列表消失。改为与顶层一致,按「现在是否匹配」判定,运行记录仅用于保留 runNum 与菜单;@noframes 脚本不因子 frame 匹配而列出。
This was referenced Nov 9, 2026
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 / 描述
背景
只
@matchiframe 网址的脚本被禁用后,在包含该 iframe 的页面打开 Popup,列表里看不到它,也就没法在 Popup 里把它启用(#1808)。原因在
PopupService.mergeSubFrameRunScripts:#1687 把子 frame 脚本并回清单时,候选只取自本 tab 的运行记录(tabScript:<tabId>),条件是「本 tab 跑过 ∧ 仍匹配某个子 frame」。禁用脚本从不运行,所以永远进不了候选。顶层 frame 则只看「现在是否匹配」,禁用脚本照常列出。只给禁用脚本开例外不够:在 Popup 里把它启用后,它变成「已启用但没跑过」,又会从列表消失,直到刷新页面。
本次改动
子 frame 改为与顶层一致,按「现在是否匹配」判定(方法更名为
mergeSubFrameScripts):scriptToMenu新建,matchesTopFrame=false;@noframes脚本不会在子 frame 运行,不因子 frame 匹配而列出;实现考虑
去掉了原来的短路「运行过的脚本都已被顶层覆盖时跳过
getAllFrames」:它的前提是「只有跑过的脚本才可能来自子 frame」,正是本 bug。现在每次打开 Popup 都会调一次getAllFrames,并对每个去重后的子 frame 网址做一次匹配。对应的单测「顶层匹配已覆盖的脚本不应触发 getAllFrames 查询」属于过时约定,已替换。已知限制
main(8a1b6d12)上一起跑整个src/pages/popup目录时,usePopupData.test.ts/preload.test.ts共 17 个失败,单独运行两个文件均通过,应是测试之间的状态隔离问题,另行跟进。建议审查重点
src/app/service/service_worker/popup.ts的mergeSubFrameScripts:已在顶层清单里的 uuid 被跳过,不会被子 frame 结果覆盖matchesTopFrame/isEffective。关联
close #1808
验证
基于
origin/main8a1b6d1,head 641e632,git diff origin/main...HEAD仅包含popup.ts与popup.test.ts。enable=false;刚启用未运行的脚本不消失;@noframes不列出;同一脚本匹配多个 iframe 只列一次且任一 frame 生效即生效。前 3 个修复前失败(expected [] to have a length of 1),修复后通过;@noframes用例去掉判断后失败(反向验证)。pnpm vitest run src/app/service/service_worker:30 文件 / 729 测试全部通过。pnpm exec tsc --noEmit通过;改动文件eslint通过;pre-commit 的 typecheck + prettier 通过。node e2e/session.mjs无头会话,pnpm run build产物):本地服务提供顶层http://127.0.0.1:18808/top.html,内嵌 iframehttp://localhost:18808/frame.html;脚本@match只匹配 iframe 网址。popup 页面以非活动标签页开在目标标签页旁,getCurrentTab()取到的就是目标标签页。脚本启停这一准备步骤是通过 SW 消息script/enable完成的。main的popup.ts):脚本禁用后打开 popup,显示「当前页运行脚本 (0/0) 暂无数据」,bug 复现。对照:启用并刷新页面后显示 (1/1),控制台有 iframe 内的运行输出,说明 popup 读的确实是目标标签页。@noframes同匹配脚本,不出现在列表里。