Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 适配domain修改 #310

Merged
merged 1 commit into from
Dec 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions packages/wujie-core/src/iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,16 +618,31 @@ function initIframeDom(iframeWindow: Window, wujie: WuJie, mainHostPath: string,
* 防止运行主应用的js代码,给子应用带来很多副作用
*/
// TODO 更加准确抓取停止时机
function stopIframeLoading(iframeWindow: Window, mainHostPath: string, appHostPath: string, appRoutePath: string) {
const sandbox = iframeWindow.__WUJIE;
function stopIframeLoading(
iframeWindow: Window,
mainHostPath: string,
appHostPath: string,
appRoutePath: string,
sandbox: WuJie
) {
const oldDoc = iframeWindow.document;
sandbox.iframeReady = new Promise<void>((resolve) => {
function loop() {
setTimeout(() => {
// location ready
if (iframeWindow.location.href === "about:blank") {
let newDoc = null;
try {
newDoc = iframeWindow.document;
} catch (err) {
newDoc = null;
}
// wait for document ready
if (!newDoc || newDoc == oldDoc) {
loop();
} else {
iframeWindow.stop ? iframeWindow.stop() : iframeWindow.document.execCommand("Stop");
if (!iframeWindow.__WUJIE) {
patchIframeVariable(iframeWindow, sandbox, appHostPath);
}
initIframeDom(iframeWindow, sandbox, mainHostPath, appHostPath);
/**
* 如果有同步优先同步,非同步从url读取
Expand Down Expand Up @@ -775,6 +790,6 @@ export function iframeGenerator(
const iframeWindow = iframe.contentWindow;
// 变量需要提前注入,在入口函数通过变量防止死循环
patchIframeVariable(iframeWindow, sandbox, appHostPath);
stopIframeLoading(iframeWindow, mainHostPath, appHostPath, appRoutePath);
stopIframeLoading(iframeWindow, mainHostPath, appHostPath, appRoutePath, sandbox);
return iframe;
}