Repository navigation
🐛 Chrome 拒绝操作时说清原因:file:// 访问开关、无效网址、书签越界、Cookie 规则与休眠标签页 - #19
Merged
Merged
Conversation
从商店安装的扩展默认关着「允许访问文件网址」,这时 Chrome 拒绝 file:// 只给出 "Cannot attach to this target."、"internal error" 或 CDP 原话,看不出原因。 Chrome 拒绝涉及 file:// 网址的操作后检查 chrome.extension.isAllowedFileSchemeAccess(), 确实是开关关着就换成说明原因与 chrome://extensions/?id=<id> 的错误,错误码沿用: - 附加调试器(page / debug / cdp send):PAGE_NOT_AUTOMATABLE - tabs.open、debugger.open、url 参数为 file:// 的 debugger.send(page goto):INVALID_REQUEST (tabs.open 原为 INTERNAL_ERROR) 开关打开时的拒绝仍带 Chrome 原话。protocol.md 与 sctl 技能的 PAGE_NOT_AUTOMATABLE 说明同步补上。
真机探测各命令在 Chrome 拒绝时的报错,修正其中吞掉原因或说错原因的几处: - tabs open / windows open:不是绝对网址时直接 INVALID_REQUEST(原先 "notaurl" 被当成相对地址, 打开扩展自己的 404 页面);Chrome 拒绝打开(javascript: 等)时带着 Chrome 原话作为 INVALID_REQUEST, 原为 INTERNAL_ERROR "internal error"。windows open 的 file:// 同样给出文件网址开关的提示,debugger.open 同理。 - bookmarks add / mkdir 不给 --folder 时越界的 --index:带 Chrome 原话作为 INVALID_REQUEST,原为 INTERNAL_ERROR。 - cookies set:SameSite no_restriction 没有 secure、domain 不覆盖 URL 的主机时说明规则, 原先只有 Chrome 的 "Failed to parse or set cookie named …"。 - 浏览器休眠(discard)的标签页上的页面命令:PAGE_UNRESPONSIVE 的说明补上休眠这一原因, 原先只猜是遗留的 JS 弹框;page reload / goto 照旧能恢复它。 三处重复的网址校验合并为 targets.requireValidUrl,errorMessage 移到 registry 共用。 protocol.md、CLI 帮助与 sctl 技能同步。
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.
背景
用户反馈 sctl 操作不了
file://页面。排查后发现,原因是从 Chrome 应用商店 / Edge 加载项安装的 sctl Browser 默认关着「允许访问文件网址」(开发者模式加载的扩展默认是开的),而报错完全看不出这一点。顺着这个问题,又在真机上批量探测了各命令被 Chrome 拒绝时的报错,修掉其中吞掉原因或说错原因的几处。改动
page */debug */cdp sendPAGE_NOT_AUTOMATABLE: Cannot attach to this target.PAGE_NOT_AUTOMATABLE,消息说明开关以及chrome://extensions/?id=<id>tabs open/windows openfile://INTERNAL_ERROR: internal errorINVALID_REQUEST,同上的提示page gotofile://INVALID_REQUEST: {"code":-32000,"message":"Navigating to local URL is not allowed"}INVALID_REQUEST,同上的提示tabs open/windows open给notaurl这类非绝对网址INVALID_REQUEST: notaurl is not a valid URL,与书签、下载、历史一致tabs open/windows open给javascript:等 Chrome 不肯打开的网址INTERNAL_ERROR: internal errorINVALID_REQUEST,带 Chrome 原话--folder时bookmarks add/mkdir的--index越界INTERNAL_ERROR: internal errorINVALID_REQUEST: Index out of bounds.cookies set --same-site no_restriction不带--secure;--domain不覆盖 URL 的主机Failed to parse or set cookie named "a".INVALID_REQUEST,说明是哪条规则PAGE_UNRESPONSIVE,只猜是遗留的 JS 弹框page reload/goto照旧能恢复extension/src/handlers/fileAccess.ts里:只在 Chrome 已经拒绝、且网址是 file:// 时才查chrome.extension.isAllowedFileSchemeAccess()。开关打开时,Chrome 拒绝仍保留原话。Page.reload来恢复,如果扩展抢先拒绝附加,page reload/goto的恢复就会失效。protocol.json不变。错误码有变化的只有tabs.open、windows.open、书签 create:从INTERNAL_ERROR变成INVALID_REQUEST。targets.requireValidUrl;errorMessage移到registry共用。docs/protocol.md、sctl debug帮助、skills/sctl(SKILL.md、references/page.md)已同步。验证
vitest643 个测试通过(新增 15 个,除 1 个对照外改前都失败),typecheck / lint / format 通过。go build、go vet通过,go test ./... -raceexit 0,golangci-lint run ./cmd/... ./internal/...0 issues。TestManagerAttachUnresponsive新增断言:报错要提到 discarded。docs/verification.md):Chrome for Testing 125,隔离配置,只加载本分支extension/dist,配对隔离 daemon(127.0.0.1:18691)。用 developerPrivate 开关文件网址访问,用chrome.tabs.discard制造休眠标签页。修复前复现了上表「原来」一列的全部报错;修复后得到「现在」一列。开关打开时,同样的 file:// 命令全部 exit 0;休眠标签页上page reload/page goto/tabs reload后命令照常成功。没改的
sctl cdp endpoint能连上,file:// 标签页不出现在页面列表里,连接不失败。view-source:页面附加失败时,Chrome 的原话是 "Extension manifest must request permission to access this host",容易误解,但仍能看出是不能访问该页面。downloads start chrome://settings当场返回成功,下载会在之后失败。