@@ -38,6 +38,17 @@ function canShare(data) {
3838 return true ;
3939}
4040
41+ // Shadowned class for PermissionStatus for use in shimming
42+ // eslint-disable-next-line no-redeclare
43+ class PermissionStatus extends EventTarget {
44+ constructor ( name , state ) {
45+ super ( ) ;
46+ this . name = name ;
47+ this . state = state ;
48+ this . onchange = null ; // noop
49+ }
50+ }
51+
4152/**
4253 * Clean data before sending to the Android side
4354 * @returns {ShareRequestData }
@@ -263,22 +274,44 @@ export class WebCompat extends ContentFeature {
263274 } ) ;
264275 }
265276
277+ permissionsPresentFix ( settings ) {
278+ const originalQuery = window . navigator . permissions . query ;
279+ window . navigator . permissions . query = new Proxy ( originalQuery , {
280+ apply : async ( target , thisArg , args ) => {
281+ this . addDebugFlag ( ) ;
282+
283+ // Let the original method handle validation and exceptions
284+ const query = args [ 0 ] ;
285+
286+ // Only intercept if we have settings and the permission is configured as native
287+ if ( query && query . name && settings ?. supportedPermissions ?. [ query . name ] ?. native ) {
288+ try {
289+ const response = await this . messaging . request ( MSG_PERMISSIONS_QUERY , query ) ;
290+ const returnStatus = response . state || 'prompt' ;
291+ return Promise . resolve ( new PermissionStatus ( query . name , returnStatus ) ) ;
292+ } catch ( err ) {
293+ // If messaging fails, fall through to original method
294+ return Reflect . apply ( target , thisArg , args ) ;
295+ }
296+ }
297+
298+ // Fall through to original method for all other cases
299+ return Reflect . apply ( target , thisArg , args ) ;
300+ } ,
301+ } ) ;
302+ }
303+
266304 /**
267305 * Adds missing permissions API for Android WebView.
268306 */
269307 permissionsFix ( settings ) {
270308 if ( window . navigator . permissions ) {
309+ if ( this . getFeatureSettingEnabled ( 'permissionsPresent' ) ) {
310+ this . permissionsPresentFix ( settings ) ;
311+ }
271312 return ;
272313 }
273314 const permissions = { } ;
274- class PermissionStatus extends EventTarget {
275- constructor ( name , state ) {
276- super ( ) ;
277- this . name = name ;
278- this . state = state ;
279- this . onchange = null ; // noop
280- }
281- }
282315 permissions . query = new Proxy (
283316 async ( query ) => {
284317 this . addDebugFlag ( ) ;
0 commit comments