Skip to content

fix(browser): explain local file preview restrictions - #1120

Merged
vastsa merged 4 commits into
vastsa:mainfrom
yuxino:fix/browser-local-file-feedback
Sep 27, 2026
Merged

vastsa merged 4 commits into
vastsa:mainfrom
yuxino:fix/browser-local-file-feedback

Conversation

@yuxino

@yuxino yuxino commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

真实桌面录制

同一隔离项目、同一个工作区外绝对路径。视频先展示旧版把路径改为 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。
  • 隔离的原生 Electron BrowserPane 验证通过:工作区内两种地址可打开;工作区外两种地址被拒绝,原页面 URL 不变,空白标签页不创建 guest。
  • 通用桌面启动 E2E 因当前 worktree 缺少 host-core 二进制未完成。此前完整桌面测试的结果属于旧 PR head;更新后的完整 CI 以本次推送结果为准。

本 PR 保持 Draft,只处理本地文件拒绝反馈;localhost:3000 的地址解析属于 #1095。

Refs #1094

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 vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要修改后再合并。

[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.
@yuxino
yuxino marked this pull request as ready for review September 27, 2026 06:08

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已复核当前 head c601331:原评审指出的绝对路径绕过已在构造导航目标前修复,file: 地址和绝对路径的工作区内/外路径均有回归覆盖;定向导航 11/11、地址栏文案 4/4 通过,远程 CI、文档和基线检查通过。批准合并。

@vastsa
vastsa merged commit 3705160 into vastsa:main Sep 27, 2026
4 checks passed
@vastsa

vastsa commented Sep 27, 2026

Copy link
Copy Markdown
Owner

已合并到 main(merge commit 3705160)。感谢贡献:本次修复在导航目标构造前拒绝工作区外的 file: 地址和绝对路径,同时保留工作区内文件预览;新增回归测试和中英文提示均已验证。未发现需要跟进的合并阻塞项。

@vastsa

vastsa commented Sep 27, 2026

Copy link
Copy Markdown
Owner

合并后集成验证已完成:实际 merge commit 3705160(同时包含此前已合入的 #1121 浏览器导航修复)上的浏览器导航测试 13/13、地址栏中英文反馈 4/4、桌面 lint 和文档检查均通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants