Skip to content

Commit b7f8328

Browse files
authored
Disable more permissions for Windows app (#297)
Some permissions are disabled in Windows app using DevTools protocol, however sometimes setting those permissions can result in a crash which is a transient error. To make the app more stable we added hardening to the DevTools protocol calls and disable these specific permissions in Web API as well in case those calls fail. https://app.asana.com/0/1201424400691338/1204114339745362/f
1 parent a6acfa9 commit b7f8328

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/features/windows-permission-usage.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,25 +372,43 @@ export function init () {
372372
// these permissions cannot be disabled using WebView2 or DevTools protocol
373373
const permissionsToDisable = [
374374
// @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 },
376376
// @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 },
378378
// @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 },
380380
// @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 }
383384
]
384-
for (const { name, prototype, method } of permissionsToDisable) {
385+
for (const { name, prototype, method, isPromise } of permissionsToDisable) {
385386
try {
386387
const proxy = new DDGProxy(featureName, prototype, method, {
387388
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+
}
389394
}
390395
})
391396
proxy.overload()
392397
} catch (error) {
393398
console.info(`Could not disable access to ${name} because of error`, error)
394399
}
395400
}
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+
}
396414
}

0 commit comments

Comments
 (0)