zxing-js / browser

ZXing for JS's browser layer with decoding implementations for browser.
MIT License
219 stars 43 forks source link

BrowserCodeReader.listVideoInputDevices() doesn't ask for Camera permission on MacOS and iOS #97

Open andrijavulicevic opened 2 years ago

andrijavulicevic commented 2 years ago

Hello, I am using this library to implement a QR Code Scanner on a web page. And I have encountered strange behavior on MacOS and iOS browsers.

Method BrowserCodeReader.listVideoInputDevices() does not ask for permission to access Camera on mentioned OSes and code simply doesn't work at all, unless a user goes to Google Chrome settings and manually enables camera permission, and only after that this method works properly.

Here is a demo to test the bug: https://replit.com/@AndrijaVulicevi/QR-code-scanner#src/App.jsx

Reproducible on:

obo-spi commented 2 years ago

I made this before listing

      const camera = await navigator?.mediaDevices
        ?.getUserMedia({ video: true })
        .catch(() => showWarning(t('captureModal.cameraUnavailable')))

      if (camera) {
          const videoInputDevices = await BrowserCodeReader.listVideoInputDevices()
...
systemutvecklare commented 1 year ago

I made this before listing

      const camera = await navigator?.mediaDevices
        ?.getUserMedia({ video: true })
        .catch(() => showWarning(t('captureModal.cameraUnavailable')))

      if (camera) {
          const videoInputDevices = await BrowserCodeReader.listVideoInputDevices()
...

This one worked for me when we had problems in both Edge and Chrome (116.0.5845.141). This should be handled by listVideoInputDevices