From d0c217faeb3dbcf2179d3e8dfc7f139590493dcd Mon Sep 17 00:00:00 2001 From: pkunszt Date: Mon, 28 Aug 2023 12:37:20 +0200 Subject: [PATCH] if the permission query throws, like on firefox, try with mediaDevices.getUserMedia. this works on firefox nicely. see issue #259 --- src/web.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/web.ts b/src/web.ts index 5c7e91b..f39354e 100644 --- a/src/web.ts +++ b/src/web.ts @@ -117,7 +117,16 @@ export class BarcodeScannerWeb extends WebPlugin implements BarcodeScannerPlugin unknown: true, }; } catch { - throw this.unavailable('Camera permissions are not available in this browser'); + try { + await navigator.mediaDevices.getUserMedia({video: true}); + return { granted: true }; + } catch (err) { + if ( (err as DOMException).name === 'NotAllowedError') { + return { denied: true }; + } else { + throw this.unavailable('Camera permissions are not available in this browser'); + } + } } }