diff --git a/src/sandbox/iframe/element.ts b/src/sandbox/iframe/element.ts index 31e26879..bb1d434d 100644 --- a/src/sandbox/iframe/element.ts +++ b/src/sandbox/iframe/element.ts @@ -13,6 +13,7 @@ import { isNode, isMicroAppBody, throttleDeferForSetAppName, + isFunction, } from '../../libs/utils' import { updateElementInfo, @@ -164,6 +165,12 @@ function patchIframeNode ( configurable: true, enumerable: true, get () { + if (isFunction(microApp.options.beforeHijackOwnerDocument)) { + const nodeRawOwnerDocument = rawOwnerDocumentDesc.get!.call(this) + if (microApp.options.beforeHijackOwnerDocument?.({ node: this, ownerDocument: nodeRawOwnerDocument, appName })) { + return nodeRawOwnerDocument + } + } return this.__PURE_ELEMENT__ || this === microDocument ? rawOwnerDocumentDesc.get!.call(this) : microDocument diff --git a/typings/global.d.ts b/typings/global.d.ts index 8be122fd..43effc93 100644 --- a/typings/global.d.ts +++ b/typings/global.d.ts @@ -359,6 +359,30 @@ declare module '@micro-app/types' { fetch?: fetchType globalAssets?: globalAssetsType, excludeAssetFilter?: (assetUrl: string) => boolean + /** + * The operation before hijacking the ownerdocument of the node + * true returns the ownerdocument of the node, false performs the next step + * + * Scenes: + * 1. tinymce editor + * + * Issue: https://github.com/micro-zoe/micro-app/issues/916 + * + * @example + * ```js + * microApp.start({ + * beforeHijackOwnerDocument({ node, ownerDocument, appName }) { + * return ownerDocument?.body?.id === 'tinymce' + * } + * }) + * ``` + * + * @param params + * @param params.node - current node + * @param params.ownerDocument - node raw ownerDocument + * @param params.appName - current appName + */ + beforeHijackOwnerDocument?: (params: { node: Node, ownerDocument: Document, appName: AppName }) => boolean getRootElementParentNode?: (node: Node, appName: AppName) => void customProxyDocumentProps?: Map void> }