refactor: get sandbox

This commit is contained in:
Xmader 2020-11-26 14:21:19 -05:00
parent ec4cf55696
commit 4acff224a8
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
1 changed files with 3 additions and 5 deletions

View File

@ -53,12 +53,10 @@ export const getSandboxWindowAsync = async (): Promise<Window> => {
return new Promise((resolve) => {
const targetEl = document.documentElement
const eventName = 'onmousemove'
const unsafe = getUnsafeWindow()
const id = Math.random().toString()
unsafe[id] = (iframe: HTMLIFrameElement) => {
delete unsafe[id]
targetEl[id] = (iframe: HTMLIFrameElement) => {
delete targetEl[id]
targetEl.removeAttribute(eventName)
iframe.style.display = 'none'
@ -67,7 +65,7 @@ export const getSandboxWindowAsync = async (): Promise<Window> => {
resolve(w as Window)
}
targetEl.setAttribute(eventName, `window['${id}'](document.createElement('iframe'))`)
targetEl.setAttribute(eventName, `this['${id}'](document.createElement('iframe'))`)
})
}