import { constructRequestPermissionURL } from '../../popups' ; export async function requestExtensionPermission ( permission ) { if ( await browser . permissions . contains ( permission ) ) return true ; try { return await browser . permissions . request ( permission ) ; } catch { } const popup = await browser . windows . create ( { height : 600 , width : 350 , type : 'popup' , url : constructRequestPermissionURL ( permission ) , } ) ; return new Promise ( ( resolve ) => { browser . windows . onRemoved . addListener ( function listener ( windowID ) { if ( windowID !== popup . id ) return ; resolve ( browser . permissions . contains ( permission ) ) ; browser . windows . onRemoved . removeListener ( listener ) ; } ) ; } ) ; } export function queryExtensionPermission ( permission ) { return browser . permissions . contains ( permission ) ; }