Skip to content

Commit

Permalink
fix: 适配domain修改 (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xusenbiao authored Dec 27, 2022
1 parent 9c3de32 commit ac18816
Showing 1 changed file with 20 additions and 5 deletions.
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;
}

0 comments on commit ac18816

Please sign in to comment.