diff --git a/src/btn.ts b/src/btn.ts index 47b543f..c0b69e3 100644 --- a/src/btn.ts +++ b/src/btn.ts @@ -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 => { - return windowOpenAsync(await normalizeUrlInput(url)) - }) - } - export const download = (url: UrlInput, fallback?: () => Promisable, timeout?: number): BtnAction => { return process(async (): Promise => { 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) diff --git a/src/utils.ts b/src/utils.ts index fbdbee2..02e339b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -47,11 +47,10 @@ export const useTimeout = async (promise: T | Promise, ms: number): Promi }) } -export const getSandboxWindowAsync = async (): Promise => { +export const getSandboxWindowAsync = async (targetEl = document.documentElement): Promise => { 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): Promise => { - return getSandboxWindowAsync().then(w => w.open(...args)) +export const windowOpenAsync = (targetEl = document.documentElement, ...args: Parameters): Promise => { + return getSandboxWindowAsync(targetEl).then(w => w.open(...args)) } export const attachShadow = (el: Element): ShadowRoot => {