Commit a204b64
authored
fix(frontend): Improve QR scanning reliability for dark borderless codes (#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"
/>1 parent 01ac870 commit a204b64
File tree
6 files changed
+231
-4
lines changed- src/frontend/src/lib
- components
- qr
- ui
- wallet-connect
- utils
6 files changed
+231
-4
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
0 commit comments