Skip to content

Feat/patch fullscreen window getter#1094

Open
edward492626 wants to merge 2 commits into
Tencent:masterfrom
edward492626:feat/patch-fullscreen-window-getter
Open

Feat/patch fullscreen window getter#1094
edward492626 wants to merge 2 commits into
Tencent:masterfrom
edward492626:feat/patch-fullscreen-window-getter

Conversation

@edward492626

@edward492626 edward492626 commented Jun 12, 2026

Copy link
Copy Markdown
  • 提交符合commit规范
  • 测试用例添加
  • npm run test通过

详细描述

背景

子应用在沙箱环境中运行时,部分场景下会遭遇两个边界问题:

  1. window/self 在 Proxy 中的指向 — 当子应用代码对 __WUJIE.proxy 进行 new Proxy() 二次包装时,handler 陷阱中访问 window / self 会指向原始 iframe window 而非沙箱 proxy,导致 this 上下文不一致。

  2. 全屏 API 未代理到主应用 — 子应用通过 document.fullscreenElementdocument.requestFullscreen() 等 API 操作全屏时,由于子应用的 document 是沙箱内的代理 document,全屏操作无法正确传递到主应用 document。

变更

patchWindowGetterEffect

  • patchWindowEffect 末尾追加调用
  • __WUJIE.proxy 外层包裹一个新的 Proxy,handler 中所有陷阱(get/set/has 等 13 个)转发到原始 proxy
  • get 陷阱拦截 window / self 属性读取,返回 proxy 自身
  • 通过 __windowGetterPatched__ 自有属性标记防止重复 patch

patchFullscreenEffect

  • patchDocumentEffect 末尾追加调用
  • 将 proxyDocument 上的 requestFullscreen / exitFullscreen 等方法(含各浏览器前缀)代理到主应用 document
  • fullscreenElement / fullscreenEnabled 等状态属性通过 getter 重定向到主应用 document
  • 通过 __fullscreenPatched__ 自有属性标记防止重复 patch

测试

新增 packages/wujie-core/__test__/unit/patch.test.ts,14 个单测覆盖正常代理、vendor 前缀、防重复 patch、Symbol 属性、边界异常等场景。

patchWindowGetterEffect: wrap __WUJIE.proxy so that window/self in Proxy
handler traps return the proxy itself, fixing 'this' binding in sub-apps
that wrap the sandbox proxy with their own Proxy.

patchFullscreenEffect: proxy fullscreen API (requestFullscreen, exitFullscreen,
fullscreenElement, fullscreenEnabled, with vendor prefixes) from sub-app
document to main window document, ensuring correct fullscreen state in
micro-frontend scenarios.

Both follow the _hasPatch pattern (hasOwnProperty marker check) used by
patchInstanceofAcrossRealms to prevent double-patching, and release
naturally on sandbox GC.
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.

1 participant