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
1 changed files with 13 additions and 4 deletions

View File

@ -51,14 +51,23 @@ export const getSandboxWindowAsync = async (): Promise<Window> => {
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'))`)
})
}