feat: add sandbox iframe under btn

This commit is contained in:
Xmader 2020-11-27 02:51:23 -05:00
parent f6536114ae
commit 935b56e4d2
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
2 changed files with 5 additions and 12 deletions

View File

@ -148,7 +148,7 @@ export class BtnList {
case BtnListMode.ExtWindow: {
const div = this._commit()
const w = await windowOpenAsync('', undefined, 'resizable,width=230,height=270')
const w = await windowOpenAsync(undefined, '', undefined, 'resizable,width=230,height=270')
// eslint-disable-next-line no-unused-expressions
w?.document.body.append(div)
window.addEventListener('unload', () => w?.close())
@ -174,12 +174,6 @@ export namespace BtnAction {
else return url
}
export const openUrl = (url: UrlInput): BtnAction => {
return process(async (): Promise<any> => {
return windowOpenAsync(await normalizeUrlInput(url))
})
}
export const download = (url: UrlInput, fallback?: () => Promisable<void>, timeout?: number): BtnAction => {
return process(async (): Promise<void> => {
const _url = await normalizeUrlInput(url)
@ -195,7 +189,7 @@ export namespace BtnAction {
btn.onclick = null
setText(i18n('PROCESSING')())
const w = await windowOpenAsync('') as Window
const w = await windowOpenAsync(btn, '') as Window
const txt = document.createTextNode(i18n('PROCESSING')())
w.document.body.append(txt)

View File

@ -47,11 +47,10 @@ export const useTimeout = async <T> (promise: T | Promise<T>, ms: number): Promi
})
}
export const getSandboxWindowAsync = async (): Promise<Window> => {
export const getSandboxWindowAsync = async (targetEl = document.documentElement): Promise<Window> => {
if (typeof document === 'undefined') return {} as any as Window
return new Promise((resolve) => {
const targetEl = document.documentElement
const eventName = 'onmousemove'
const id = Math.random().toString()
@ -76,8 +75,8 @@ export const getUnsafeWindow = (): Window => {
export const console: Console = (window || global).console // Object.is(window.console, unsafeWindow.console) == false
export const windowOpenAsync = (...args: Parameters<Window['open']>): Promise<Window | null> => {
return getSandboxWindowAsync().then(w => w.open(...args))
export const windowOpenAsync = (targetEl = document.documentElement, ...args: Parameters<Window['open']>): Promise<Window | null> => {
return getSandboxWindowAsync(targetEl).then(w => w.open(...args))
}
export const attachShadow = (el: Element): ShadowRoot => {