Conversation
|
I'm using this version to be able to scan inverted QR codes and it works on my mac but it doesn't work in iOS on my iPhone. Any ideas why this is and how to get it working? Normal QR codes work. |
Hi @joncon62, |
|
@fante90 it's supported on Safari, but there is a bug reported here |
|
@ROBERT-MCDOWELL from what I understand is not supported, it's not a bug, see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/filter |
|
@fante90 yes it's a bug, click on browser compatibility table -> safari -> https://bugs.webkit.org/show_bug.cgi?id=198416 |
|
@ROBERT-MCDOWELL keep calm, we are here to talk. |
|
@fante90 I'm calm, I just can't stand people not believing what I'm saying, it's waste of time for me... |
|
@ROBERT-MCDOWELL have you ever heard of polyfill? https://github.com/davidenke/context-filter-polyfill |
|
if you want to add a full polyfill js file on top of html5-qrcode just for one function so do it. |
|
@ROBERT-MCDOWELL I simply took the invert function from that polyfill and it works. thank you |
|
@fante90 did you create a new html5-qrcode.min.js ? I can see you modified html5-qrcode.ts but I don't know what to do with that, sorry! |
|
@joncon62 if you see my commits, I’ve ever commit only html5-qrcode.ts never the files in dist folder. In order to obtain the js file checkout my branch and follow this instructions https://github.com/mebjas/html5-qrcode?tab=readme-ov-file#how-to-modify-and-build |
|
I managed to build the .js file and tested it out. I can't get inverted QR codes to work on my iPhone in either Safari or Chrome browsers. Normal QR codes do work. |
Can you share your QR code? |
|
Here are the normal and dark codes: Now I see them together I just noticed that the dark one is not inverted, it just has a dark border. This was created by putting the phone into 'dark mode' - any idea how I can get this to be recognised? Also, both codes are recognised if I scan them on a mac with this code, the 'dark' one doesn't work on an iPhone. |
|
@joncon62 html5-qrcode (and probably most of qr-code scanners) need this white border to clearly differentiate the black squares which are data. if the border is dark and touching these black square so indeed it won't gues if it's data or the border. |
|
create an image batch automation with photoshop or maybe on line tool |
|
Unfortunately the QR codes are in customer emails already sent out so I can't change them. This is only a problem for people who choose to use dark mode and we can always ask them to turn light mode back on - but it's a bit of a hassle and many don't even know how to do that! Is there a way to scan a QR code without a quiet zone? Can a pseudo quiet zone be added to the canvas? |
|
what you can do is before the scanner capture function make a new function that capture one frame from the canvas then manipulate the image adding a white square around then provide this frame to the html5-qrcode scanner function |
|
@joncon62 this is out of the scope of the PR. Please open an issue if you need to support QR codes without border, this PR is about inverted colours (black background). |
…des (#12162) # Note This PR is a fork of dfinity/gix-components#759. Awaiting that review, we simply copy the components in our repo and add it to the next release, since it is a time-sensitive issue. # Motivation The QR code reader was using `html5-qrcode`, which has a known issue with inverted (dark-themed, borderless) QR codes on mobile — they simply cannot be scanned. The library is also unmaintained. Known upstream issues: - mebjas/html5-qrcode#766 - mebjas/html5-qrcode#468 - mebjas/html5-qrcode#94 Since the root cause is a limitation of `html5-qrcode` itself (no support for inverted QR codes), and the library is no longer maintained, this PR replaces it with [`barcode-detector`](https://www.npmjs.com/package/barcode-detector) — a [Barcode Detection API](https://developer.mozilla.org/en-US/docs/Web/API/BarcodeDetector) polyfill powered by ZXing C++ WebAssembly under the hood. The underlying engine natively supports inverted code detection (`tryInvert` is enabled by default). We tested it manually on a mobile device and dark borderless QR codes are now successfully scanned. Thanks to @sea-snake for the tip! # Changes (copied from gix-components's `QRCodeReader`) - Removed the `html5-qrcode` dependency entirely in component `QRCodeReader`. - In component `QRCodeReader`: - Camera access is now handled directly via the browser `navigator.mediaDevices.getUserMedia` API, requesting the rear-facing camera (`facingMode: "environment"`) at up to 1920×1080 resolution. - The video feed is rendered in a native `<video>` element. - QR decoding uses the standard `BarcodeDetector` API (via `barcode-detector/ponyfill`). A detector instance is created with `formats: ["qr_code"]` and `detector.detect(videoElement)` is called at ~10 fps via `setInterval(scan, 100)`. The polyfill accepts the `<video>` element directly — no intermediate `<canvas>` needed. - A frame-processing guard (`isProcessingFrame`) prevents overlapping decode calls. - Cleanup on destroy properly clears the scan interval and stops all media tracks. - The scan overlay is now implemented with a `.scan-overlay` container with a `.scan-region` box using `box-shadow` to mask the surrounding area and a border styled with the primary color. This replaces the old `:global(#qr-shaded-region)` overrides that targeted `html5-qrcode`'s internal DOM. - Updated the library reference in the QR code reader docs page from `jsQR` to `barcode-detector`. - Added `barcode-detector@^3.1.1` to dependencies and removed `html5-qrcode`. # Tests Manual testing on mobile: dark borderless QR codes are now successfully scanned (this was the main validation, as the core issue only reproduced on real mobile devices). <img width="1071" height="1428" alt="IMG_5315" src="https://github.com/user-attachments/assets/f25cbe60-3d92-472c-917e-ffdfb5f1b343" /> <img width="1179" height="2556" alt="IMG_5314" src="https://github.com/user-attachments/assets/6fd3d30d-2080-4464-8263-80ce3d544698" />


Hi @mebjas
I'm using your library and I caught in the same problem of #94 and I tried to solve the issue.
My code tries to scan the QR Code in the four possible cases:
I did some tests in various color combinations always getting a positive result when the contrast between background and foreground is quite clear.
If you had some time to have a look, I would be happy to have your opinion.
Regards
@fante90