diff --git a/cypress/e2e/2-the-vm-sandbox/dom.spec.js b/cypress/e2e/2-the-vm-sandbox/dom.spec.js
index 8f43e40f9..c8c493276 100644
--- a/cypress/e2e/2-the-vm-sandbox/dom.spec.js
+++ b/cypress/e2e/2-the-vm-sandbox/dom.spec.js
@@ -18,6 +18,7 @@ describe('whole process vm sandbox set variable', () => {
disablePreloadApp: true,
sandbox: {
snapshot: false,
+ fixStaticResourceBaseUrl: true,
},
protectVariable: ['dynamicScriptOnloadTag', 'dynamicScriptOnerrorTag'],
},
diff --git a/cypress/e2e/2-the-vm-sandbox/set-global-variable.spec.js b/cypress/e2e/2-the-vm-sandbox/set-global-variable.spec.js
index 231b55b03..51a27157f 100644
--- a/cypress/e2e/2-the-vm-sandbox/set-global-variable.spec.js
+++ b/cypress/e2e/2-the-vm-sandbox/set-global-variable.spec.js
@@ -21,6 +21,7 @@ describe('whole process vm sandbox set variable', () => {
sandbox: {
snapshot: false,
fixBaseUrl: true,
+ fixOwnerDocument: true,
},
},
});
@@ -70,12 +71,12 @@ describe('whole process vm sandbox set variable', () => {
cy.contains('[data-test=title]', ProxyVariableTitle).then(() => {
expect(
win.document
- .querySelector('[data-test=iframe-pre-fix]')
+ .querySelector('[data-test=iframe-pre-fix-16]')
.getAttribute('src'),
).to.equal(`http:${getPublicPath('dev/react16')}iframe`);
expect(
win.document
- .querySelector('[data-test=img-pre-fix]')
+ .querySelector('[data-test=img-pre-fix-16]')
.getAttribute('src'),
).to.equal(`http:${getPublicPath('dev/react16')}img`);
});
diff --git a/dev/app-main/src/config.ts b/dev/app-main/src/config.ts
index 49c151ba1..007ca09e4 100644
--- a/dev/app-main/src/config.ts
+++ b/dev/app-main/src/config.ts
@@ -45,6 +45,8 @@ let defaultConfig: RunInfo = {
// 并且子应用的查询和添加行为仅会在 DOM 作用域内进行
strictIsolation: false,
fixBaseUrl: true,
+ fixStaticResourceBaseUrl: true,
+ fixOwnerDocument: true,
// 覆盖子应用的执行上下文,使用自定义的执行上下文,例如子应用 localStorage 使用当前主应用 localStorage
// 仅在 snapshot: false 时有效
diff --git a/dev/app-react-16/src/sandbox.tsx b/dev/app-react-16/src/sandbox.tsx
index 7dad32d37..309b88274 100644
--- a/dev/app-react-16/src/sandbox.tsx
+++ b/dev/app-react-16/src/sandbox.tsx
@@ -84,12 +84,25 @@ export default function () {
add script test onerror
-
document instanceof Document: {String(document instanceof Document)}
-
document.body.parentNode?.parentNode: {String(document === document.body.parentNode?.parentNode)}
+
+ document instanceof Document: {String(document instanceof Document)}
+
+
+ document.body.parentNode?.parentNode:{' '}
+ {String(document === document.body.parentNode?.parentNode)}
+
-
-
-
![](/img)
+
+
+
);
diff --git a/packages/browser-vm/src/dynamicNode/index.ts b/packages/browser-vm/src/dynamicNode/index.ts
index 8569635ee..9ab8000ae 100644
--- a/packages/browser-vm/src/dynamicNode/index.ts
+++ b/packages/browser-vm/src/dynamicNode/index.ts
@@ -114,7 +114,8 @@ export function makeElInjector(sandboxConfig: SandboxOptions) {
if (typeof window.Element === 'function') {
// iframe can read html container this can't point to proxyDocument has Illegal invocation error
- if (sandboxConfig.fixBaseUrl) safeWrapper(() => handleOwnerDocument());
+ if (sandboxConfig.fixOwnerDocument)
+ safeWrapper(() => handleOwnerDocument());
const rewrite = (
methods: Array,
builder: typeof injector | typeof injectorRemoveChild,
diff --git a/packages/browser-vm/src/pluginify.ts b/packages/browser-vm/src/pluginify.ts
index e2a235702..e820f81fd 100644
--- a/packages/browser-vm/src/pluginify.ts
+++ b/packages/browser-vm/src/pluginify.ts
@@ -130,6 +130,7 @@ function createOptions(Garfish: interfaces.Garfish) {
fixStaticResourceBaseUrl: Boolean(
appInfo.sandbox?.fixStaticResourceBaseUrl,
),
+ fixOwnerDocument: Boolean(appInfo.sandbox?.fixOwnerDocument),
disableWith: Boolean(appInfo.sandbox?.disableWith),
disableElementtiming: Boolean(appInfo.sandbox?.disableElementtiming),
strictIsolation: Boolean(appInfo.sandbox?.strictIsolation),
diff --git a/packages/browser-vm/src/types.ts b/packages/browser-vm/src/types.ts
index c8747d6a8..97ec5cb56 100644
--- a/packages/browser-vm/src/types.ts
+++ b/packages/browser-vm/src/types.ts
@@ -23,6 +23,7 @@ export interface SandboxOptions {
baseUrl?: string;
fixBaseUrl?: boolean;
fixStaticResourceBaseUrl?: boolean;
+ fixOwnerDocument?: boolean;
disableWith?: boolean;
strictIsolation?: boolean;
disableElementtiming?: boolean;
diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts
index 90f45398c..231f95315 100644
--- a/packages/core/src/config.ts
+++ b/packages/core/src/config.ts
@@ -114,6 +114,7 @@ export const createDefaultOptions = () => {
disableWith: false,
strictIsolation: false,
disableElementtiming: false,
+ fixOwnerDocument: false,
},
// global hooks
beforeLoad: () => {},
diff --git a/packages/core/src/interface.ts b/packages/core/src/interface.ts
index b53aa251c..0a493e5d1 100644
--- a/packages/core/src/interface.ts
+++ b/packages/core/src/interface.ts
@@ -81,6 +81,7 @@ export namespace interfaces {
disableWith?: boolean;
strictIsolation?: boolean;
disableElementtiming?: boolean;
+ fixOwnerDocument?: boolean;
}
export interface Config {
diff --git a/website/src/components/config/_sandbox.mdx b/website/src/components/config/_sandbox.mdx
index 226167cdc..17f4ecab9 100644
--- a/website/src/components/config/_sandbox.mdx
+++ b/website/src/components/config/_sandbox.mdx
@@ -18,6 +18,8 @@ interface SandboxConfig {
modules?: Array | Record;
// disableElementtiming 1.14.4 版本提供,默认值为 false,将会给子应用元素注入 elementtiming 属性,可以通过此属性获取子应用元素的加载时间
disableElementtiming?: boolean;
+ // fixOwnerDocument 1.17.0 版本提供,默认值为 false,sandbox 在针对 Element 的 ownerDocument 会发生逃逸,fixOwnerDocument 设置为 true 会避免逃逸
+ fixOwnerDocument?: boolean;
}
type Module = (sandbox: Sandbox) => OverridesData | void;