yushulx / flutter_barcode_sdk

Build barcode QR detection apps for Windows, Linux, macOS, Android, iOS and web.
https://pub.dev/packages/flutter_barcode_sdk
MIT License
47 stars 18 forks source link

Barcode Scanner does not work as expected on web #16

Closed zeinab-sheikhi closed 3 years ago

zeinab-sheikhi commented 3 years ago

Hi, I have run example directory from your project on web, with this command: flutter run -d chrome --web-hostname 192.168.1.72 --web-port 3000 (I want to test this as PWA on ios phones, so I specified my laptop's ip address.) when I want to scan barcodes via video stream, it opens file chooser and acts like Barcode Reader. but When I run it with flutter run -d chrome, it works as expected and ask camera permission and start video streaming flutter doctor is: Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.5.1, on macOS 11.2.3 20D91 darwin-x64, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [✓] Xcode - develop for iOS and macOS [✓] Chrome - develop for the web [✓] Android Studio (version 2020.3) [✓] Connected device (1 available) • No issues found!

what is wrong with Barcode Scanner on web?

yushulx commented 3 years ago

@zeinab-sheikhi When running the example with flutter run -d chrome, you can get navigator.mediaDevices which is used to open your camera.

navigator mediaDevices

However, if you run the example with flutter run -d chrome --web-hostname 192.168.1.72 --web-port 3000, the navigator.mediaDevices is undefined.

media device undefined

There is nothing wrong with Barcode Scanner. The issue is caused by the security policy of Chrome. If you host the example with HTTPS, it should work.