@@ -38,6 +38,17 @@ function canShare(data) {
38
38
return true ;
39
39
}
40
40
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
+
41
52
/**
42
53
* Clean data before sending to the Android side
43
54
* @returns {ShareRequestData }
@@ -263,22 +274,44 @@ export class WebCompat extends ContentFeature {
263
274
} ) ;
264
275
}
265
276
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
+
266
304
/**
267
305
* Adds missing permissions API for Android WebView.
268
306
*/
269
307
permissionsFix ( settings ) {
270
308
if ( window . navigator . permissions ) {
309
+ if ( this . getFeatureSettingEnabled ( 'permissionsPresent' ) ) {
310
+ this . permissionsPresentFix ( settings ) ;
311
+ }
271
312
return ;
272
313
}
273
314
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
- }
282
315
permissions . query = new Proxy (
283
316
async ( query ) => {
284
317
this . addDebugFlag ( ) ;
0 commit comments