fix: get sandbox
This commit is contained in:
parent
27861a802d
commit
ec4cf55696
1 changed files with 13 additions and 4 deletions
17
src/utils.ts
17
src/utils.ts
|
@ -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'))`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue