@@ -452,13 +452,25 @@ export class CRBrowserContext extends BrowserContext<CREventsMap> {
452452 [ 'local-fonts' , 'localFonts' ] ,
453453 [ 'local-network-access' , [ 'localNetworkAccess' , 'localNetwork' , 'loopbackNetwork' ] ] ,
454454 ] ) ;
455- const filtered = permissions . flatMap ( permission => {
456- const protocolPermission = webPermissionToProtocol . get ( permission ) ;
457- if ( ! protocolPermission )
458- throw new Error ( 'Unknown permission: ' + permission ) ;
459- return typeof protocolPermission === 'string' ? [ protocolPermission ] : protocolPermission ;
460- } ) ;
461- await this . _browser . _session . send ( 'Browser.grantPermissions' , { origin : origin === '*' ? undefined : origin , browserContextId : this . _browserContextId , permissions : filtered } ) ;
455+
456+ const grantPermissions = async ( mapping : Map < string , Protocol . Browser . PermissionType | Protocol . Browser . PermissionType [ ] > ) => {
457+ const filtered = permissions . flatMap ( permission => {
458+ const protocolPermission = mapping . get ( permission ) ;
459+ if ( ! protocolPermission )
460+ throw new Error ( 'Unknown permission: ' + permission ) ;
461+ return typeof protocolPermission === 'string' ? [ protocolPermission ] : protocolPermission ;
462+ } ) ;
463+ await this . _browser . _session . send ( 'Browser.grantPermissions' , { origin : origin === '*' ? undefined : origin , browserContextId : this . _browserContextId , permissions : filtered } ) ;
464+ } ;
465+
466+ try {
467+ await grantPermissions ( webPermissionToProtocol ) ;
468+ } catch ( e ) {
469+ // Old stable browsers dislike the new permission name, so we use the fallback mapping.
470+ const fallbackMapping = new Map ( webPermissionToProtocol ) ;
471+ fallbackMapping . set ( 'local-network-access' , [ 'localNetworkAccess' ] ) ;
472+ await grantPermissions ( fallbackMapping ) ;
473+ }
462474 }
463475
464476 async doClearPermissions ( ) {
0 commit comments