@@ -372,25 +372,43 @@ export function init () {
372
372
// these permissions cannot be disabled using WebView2 or DevTools protocol
373
373
const permissionsToDisable = [
374
374
// @ts -expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
375
- { name : 'Bluetooth' , prototype : Bluetooth . prototype , method : 'requestDevice' } ,
375
+ { name : 'Bluetooth' , prototype : Bluetooth . prototype , method : 'requestDevice' , isPromise : true } ,
376
376
// @ts -expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
377
- { name : 'USB' , prototype : USB . prototype , method : 'requestDevice' } ,
377
+ { name : 'USB' , prototype : USB . prototype , method : 'requestDevice' , isPromise : true } ,
378
378
// @ts -expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
379
- { name : 'Serial' , prototype : Serial . prototype , method : 'requestPort' } ,
379
+ { name : 'Serial' , prototype : Serial . prototype , method : 'requestPort' , isPromise : true } ,
380
380
// @ts -expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
381
- { name : 'HID' , prototype : HID . prototype , method : 'requestDevice' } ,
382
- { name : 'Protocol handler' , prototype : Navigator . prototype , method : 'registerProtocolHandler' }
381
+ { name : 'HID' , prototype : HID . prototype , method : 'requestDevice' , isPromise : true } ,
382
+ { name : 'Protocol handler' , prototype : Navigator . prototype , method : 'registerProtocolHandler' , isPromise : false } ,
383
+ { name : 'MIDI' , prototype : Navigator . prototype , method : 'requestMIDIAccess' , isPromise : true }
383
384
]
384
- for ( const { name, prototype, method } of permissionsToDisable ) {
385
+ for ( const { name, prototype, method, isPromise } of permissionsToDisable ) {
385
386
try {
386
387
const proxy = new DDGProxy ( featureName , prototype , method , {
387
388
apply ( ) {
388
- return Promise . reject ( new DOMException ( 'Permission denied' ) )
389
+ if ( isPromise ) {
390
+ return Promise . reject ( new DOMException ( 'Permission denied' ) )
391
+ } else {
392
+ throw new DOMException ( 'Permission denied' )
393
+ }
389
394
}
390
395
} )
391
396
proxy . overload ( )
392
397
} catch ( error ) {
393
398
console . info ( `Could not disable access to ${ name } because of error` , error )
394
399
}
395
400
}
401
+
402
+ // these permissions can be disabled using DevTools protocol but it's not reliable and can throw exception sometimes
403
+ const permissionsToDelete = [
404
+ { name : 'Idle detection' , permission : 'IdleDetector' } ,
405
+ { name : 'NFC' , permission : 'NDEFReader' } ,
406
+ { name : 'Orientation' , permission : 'ondeviceorientation' } ,
407
+ { name : 'Motion' , permission : 'ondevicemotion' }
408
+ ]
409
+ for ( const { permission } of permissionsToDelete ) {
410
+ if ( permission in window ) {
411
+ delete window [ permission ]
412
+ }
413
+ }
396
414
}
0 commit comments