fix(browser): explain local file preview restrictions - #1120
Conversation
Rejected local file addresses used the generic invalid URL state, which gave no actionable explanation and could leave a blank tab without a pane state. Publish a scoped error before loading and show the workspace limit in both supported locales. Cover existing and blank tabs, preserve the file boundary, and document the user path. Refs vastsa#1094
vastsa
left a comment
There was a problem hiding this comment.
需要修改后再合并。
[P1] 绝对路径仍未被拒绝
apps/desktop/electron/main/browser-view.ts:174-181 先对 raw 调用 normalizeUrl(),只有 target 为空时才设置 LOCAL_FILE_NOT_ALLOWED。因此在 macOS 上输入项目外绝对路径 /tmp/demo.html 时,resolveLocalFile() 虽然返回 null,但 normalizeUrl() 会把它转换成 http://tmp/demo.html,随后仍交给 Electron 的 loadURL(),不会显示本 PR 新增的工作区限制提示。
我在 PR head 上复现到的 pending load URL 是 http://tmp/demo.html。这也与本 PR 更新的 UX spec(绝对路径应在加载前拒绝)不一致。建议在构造 target 前先识别绝对路径;若不是工作区内已存在文件,直接返回 LOCAL_FILE_NOT_ALLOWED,并补充绝对路径回归测试。
另外,当前 PR head 仍落后最新 origin/main 3 个提交,修复后请先刷新基线。
An absolute path outside the workspace fell through to URL normalization and reached Electron as an HTTP request. Classify local inputs before constructing a navigation target so rejected paths keep the file boundary message while existing workspace paths still preview normally. Cover the denied and allowed absolute paths in pane and address bar tests, and keep the English and Chinese browser scenarios aligned. Refs vastsa#1094
The pull request branch had fallen behind the upstream integration base. Merge current main without rewriting the already published fix commits so the browser change can be validated against the code that would land.
Refresh the draft fix onto the latest main before recording and PR validation. Keep the already published history intact.
|
已合并到 main(merge commit |
|
合并后集成验证已完成:实际 merge commit |
真实桌面录制
同一隔离项目、同一个工作区外绝对路径。视频先展示旧版把路径改为 HTTP 地址并给出通用错误,再展示本 PR 保留原路径并说明工作区限制。画面来自原生应用,仅添加英文阶段标签。
browser-local-file-before-after-1080p.mp4
问题与修复
内置浏览器输入工作区外的
file:地址时原先只显示通用网址错误;输入/tmp/demo.html等绝对路径时,normalizeUrl()还会把它变成http://tmp/demo.html并交给 Electron 加载。现在先识别本地输入:工作区内已存在的文件仍可打开,其他file:地址和绝对路径在加载前返回LOCAL_FILE_NOT_ALLOWED,地址栏以中英文说明工作区限制。空白标签页也会保留可显示的错误状态。验证
file:地址和绝对路径,以及中英文地址栏提示。修复前新增的绝对路径用例失败,修复后 37 项定向测试通过。pnpm build:js、桌面typecheck、pnpm lint、pnpm docs:check和pnpm check:pr-base通过;已合入验证时的最新上游main。本 PR 保持 Draft,只处理本地文件拒绝反馈;
localhost:3000的地址解析属于 #1095。Refs #1094