Repository navigation
Conversation
Collaborator
|
看起来应该行吧 |
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 / 检查清单
背景
360 X 浏览器里,从网页上的「安装脚本」按钮安装会失败,安装页报
Invalid context type provided.(#1816)。实机复现后确认,触发条件是网页以
noopener新开的标签被 DNR 重定向到安装页。这时页面拿到的扩展 API 不完整:chrome.tabs、chrome.permissions、chrome.runtime.getContexts都是undefined,安装页准备脚本时一读chrome.storage.local就报错。同一个链接不带noopener打开则一切正常,和开发者模式无关。360 X 为什么这样给页面分类还不清楚。在本页刷新、或者让原标签重新导航都恢复不了,只有由 SW 用tabs.create新开的安装页才正常。本次改动
安装页入口在渲染前做一次检测:如果
chrome.tabs不存在,且 URL 带?url=(只有 DNR 拦截才会产生这种入口),就location.replace到文档站现成的安装中间页docs.scriptcat.org/docs/script_installation/#url=<脚本地址>。SW 现有的
webNavigation.onBeforeNavigate监听会接住这次导航,备好脚本后通过openInCurrentTab(tabs.create)新开?uuid=安装页,新标签拿到的是完整上下文。这条中间页链路是现成的,访问不了文档站时也能触发(#705)。实现考虑
Repo是现有的正常写法(脚本编辑器、导入页、favicon 都这么做),所以不存在需要修正的架构问题。而且BackgroundPrompt里的chrome.permissions.request必须在页面里、带用户手势调用,挪不走。为一个浏览器的问题重构,改不全,以后也容易再坏。chrome.tabs一定存在,所以其他浏览器不会进这个分支。?url=入口会跳转,SW 新建的是?uuid=入口,不会再落回这里。url=之后的整段原样转交,和安装页读取?url=的方式一致,脚本地址自带的查询串不会被截断。已知限制
goBack)。这和现在从文档站中间页安装的表现一致。验证
pnpm exec vitest run --no-coverage src/pages/install/context_fallback.test.ts:3 passed。先在模块不存在时确认失败,再写实现。pnpm run typecheck,以及改动文件的 eslint 和 prettier 检查:通过。提交钩子里的 typecheck、prettier 检查也通过。pnpm exec vitest run --no-coverage src/pages/install:每次有 3 个用例失败,但每次失败的不是同一批(一次是compat_docs,另一次是BackgroundPrompt和PermissionCard)。去掉本次改动在 main 上跑,同样失败 3 个;三个文件单独跑全部通过(3/3、5/5、31/31)。本次改动的文件没有被这些测试引用,判断是既有的并行不稳定用例。pnpm run build产物,通过 CDP 发送真实鼠标事件驱动):origin/main构建):点击 scriptcat.org 详情页的「安装脚本」,install.html?url=...里chrome.tabs、chrome.permissions都是undefined,页面报Invalid context type provided.,复现了问题。install.html?uuid=...,chrome.tabs、chrome.permissions都是object,安装内容正常显示。点击「安装」后,从 SW 读取chrome.storage.local,能看到该脚本的记录(status 1),安装页随后自动关闭。.user.js链接测试,带rel=noopener时自动恢复,不带时停在原?url=安装页,没有跳转。noopener对照覆盖。git diff 79f2a99f...ea6675f8只涉及src/pages/install/{context_fallback.ts,context_fallback.test.ts,main.tsx}。关联
fix #1816
Screenshots / 截图
以下截图均为 360 X 实机上用 CDP 截取的页面视口(不含地址栏),URL 和 API 状态见上方「验证」。
修复前:从网页按钮进入的安装页
修复后:自动新开的
?uuid=安装页正常加载修复后:点击「安装」后的成功状态(随后页面自动关闭)
修复后:原标签停在文档站安装中间页