postmessage-actions.mdx
6.57 KB
-
fix(web): 新标签页改一步 open,别再"先开 about:blank 再导航" · 47c079ef
宿主加上 allow-popups 后炸了两条,都是上一版那个两步走导致的: Unsafe attempt to initiate navigation for frame with URL 'about:blank' … The frame attempting navigation is sandboxed and is trying to navigate a popup, but is not the popup's opener and is not set to propagate sandboxing to popups. Uncaught SecurityError: Failed to execute 'replace' on 'Location': The current window does not have permission to navigate the target frame to '<host url>'. 因果:**opener 一断,我们就不再是那个弹窗的 opener**,而沙箱化的 frame 只有作为 opener 才有权 导航它 → 第二步 location.replace 被拒,新标签页停在空白页。顺序反过来也不行(导航到跨源之后 再设 opener 会抛)。上一版之所以两步走,是想"手工断 opener 以等效 noopener、同时保留可检测性" —— 这个组合在沙箱下不成立。 改成一步 `window.open(url, '_blank')`: · 可检测性仍在 —— 被拦时返回 null(features 里**不写** noopener;写了成功也返回 null, 那才是分不清被拦和成功的写法) · opener 只做尽力而为的切断(跨源会抛,catch 掉)。可接受:目标是宿主管理页配好的自家地址, 不是用户输入的任意站点,tabnabbing 面本来就很窄。 三级兜底(新页 → 顶层 → 本 frame)保持不变。 交付文档补上:只给 allow-popups 时新标签页会**继承沙箱**,宿主自己的页面在里面可能功能不全, 建议连 allow-popups-to-escape-sandbox 一起加,并给出完整推荐的 sandbox 串。⚠ ️ 内嵌浏览器面板自身拦弹窗,"正常开出新标签页"这一支我这边仍证不了; 但两步导航已从结构上去掉,SecurityError 那类报错不会再有。web typecheck 通过。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>luoqi committed