fix: get sandbox

This commit is contained in:
Xmader 2020-11-26 14:18:41 -05:00
parent 27861a802d
commit ec4cf55696
No known key found for this signature in database
GPG key ID: A20B97FB9EB730E4

View file

@ -51,14 +51,23 @@ export const getSandboxWindowAsync = async (): Promise<Window> => {
if (typeof document === 'undefined') return {} as any as Window if (typeof document === 'undefined') return {} as any as Window
return new Promise((resolve) => { return new Promise((resolve) => {
window.onmouseover = () => { const targetEl = document.documentElement
const iframe = document.createElement('iframe') 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' iframe.style.display = 'none'
document.body.append(iframe) targetEl.append(iframe)
const w = iframe.contentWindow const w = iframe.contentWindow
window.onmouseover = null
resolve(w as Window) resolve(w as Window)
} }
targetEl.setAttribute(eventName, `window['${id}'](document.createElement('iframe'))`)
}) })
} }