From ec4cf55696f516bf2fc34030f22a7d158b8d4ef3 Mon Sep 17 00:00:00 2001 From: Xmader Date: Thu, 26 Nov 2020 14:18:41 -0500 Subject: [PATCH] fix: get sandbox --- src/utils.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 5fdaf79..c044702 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -51,14 +51,23 @@ export const getSandboxWindowAsync = async (): Promise => { if (typeof document === 'undefined') return {} as any as Window return new Promise((resolve) => { - window.onmouseover = () => { - const iframe = document.createElement('iframe') + const targetEl = document.documentElement + const eventName = 'onmousemove' + + const unsafe = getUnsafeWindow() + const id = Math.random().toString() + + unsafe[id] = (iframe: HTMLIFrameElement) => { + delete unsafe[id] + targetEl.removeAttribute(eventName) + iframe.style.display = 'none' - document.body.append(iframe) + targetEl.append(iframe) const w = iframe.contentWindow - window.onmouseover = null resolve(w as Window) } + + targetEl.setAttribute(eventName, `window['${id}'](document.createElement('iframe'))`) }) }