Feat/patch fullscreen window getter#1094
Open
edward492626 wants to merge 2 commits into
Open
Conversation
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.
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.
npm run test通过详细描述
背景
子应用在沙箱环境中运行时,部分场景下会遭遇两个边界问题:
window/self在 Proxy 中的指向 — 当子应用代码对__WUJIE.proxy进行new Proxy()二次包装时,handler 陷阱中访问window/self会指向原始 iframe window 而非沙箱 proxy,导致this上下文不一致。全屏 API 未代理到主应用 — 子应用通过
document.fullscreenElement、document.requestFullscreen()等 API 操作全屏时,由于子应用的 document 是沙箱内的代理 document,全屏操作无法正确传递到主应用 document。变更
patchWindowGetterEffectpatchWindowEffect末尾追加调用__WUJIE.proxy外层包裹一个新的Proxy,handler 中所有陷阱(get/set/has 等 13 个)转发到原始 proxyget陷阱拦截window/self属性读取,返回 proxy 自身__windowGetterPatched__自有属性标记防止重复 patchpatchFullscreenEffectpatchDocumentEffect末尾追加调用requestFullscreen/exitFullscreen等方法(含各浏览器前缀)代理到主应用 documentfullscreenElement/fullscreenEnabled等状态属性通过 getter 重定向到主应用 document__fullscreenPatched__自有属性标记防止重复 patch测试
新增
packages/wujie-core/__test__/unit/patch.test.ts,14 个单测覆盖正常代理、vendor 前缀、防重复 patch、Symbol 属性、边界异常等场景。