fix(frontend): Improve QR scanning reliability for dark borderless codes#12162
Merged
AntonioVentilii merged 5 commits intomainfrom Mar 25, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR replaces the existing QR scanning implementation (previously sourced from @dfinity/gix-components / html5-qrcode) with a locally vendored QRCodeReader that uses the barcode-detector ponyfill (ZXing WASM) to improve scanning reliability for inverted/dark borderless QR codes, especially on mobile.
Changes:
- Added a new local
QRCodeReader.sveltethat usesgetUserMedia+barcode-detector/ponyfillto decode QR codes from a<video>stream. - Updated WalletConnect and general QR scanning flows to use the local
QRCodeReaderinstead of@dfinity/gix-components. - Added a small
nextElementIdutility and introducedbarcode-detectoras a dependency.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/frontend/src/lib/utils/html.utils.ts | Adds an element-id helper used by the new QR code reader. |
| src/frontend/src/lib/components/wallet-connect/WalletConnectForm.svelte | Switches to the local QR code reader component. |
| src/frontend/src/lib/components/ui/QRCodeReader.svelte | New QR scanning component using getUserMedia + barcode-detector ponyfill. |
| src/frontend/src/lib/components/qr/QrCodeScanner.svelte | Switches to the local QR code reader component. |
| package.json | Adds barcode-detector dependency. |
| package-lock.json | Lockfile updates for the new dependency tree. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…-for-dark-borderless-codes
DenysKarmazynDFINITY
approved these changes
Mar 25, 2026
…-for-dark-borderless-codes
github-merge-queue bot
pushed a commit
that referenced
this pull request
Mar 25, 2026
# Motivation To use the new library from `QrCodeReader` component (PR #12162) we need to allow it in the CSP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Since the root cause is a limitation of
html5-qrcodeitself (no support for inverted QR codes), and the library is no longer maintained, this PR replaces it withbarcode-detector— a Barcode Detection API polyfill powered by ZXing C++ WebAssembly under the hood. The underlying engine natively supports inverted code detection (tryInvertis 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)html5-qrcodedependency entirely in componentQRCodeReader.QRCodeReader:navigator.mediaDevices.getUserMediaAPI, requesting the rear-facing camera (facingMode: "environment") at up to 1920×1080 resolution.<video>element.BarcodeDetectorAPI (viabarcode-detector/ponyfill). A detector instance is created withformats: ["qr_code"]anddetector.detect(videoElement)is called at ~10 fps viasetInterval(scan, 100). The polyfill accepts the<video>element directly — no intermediate<canvas>needed.isProcessingFrame) prevents overlapping decode calls..scan-overlaycontainer with a.scan-regionbox usingbox-shadowto mask the surrounding area and a border styled with the primary color. This replaces the old:global(#qr-shaded-region)overrides that targetedhtml5-qrcode's internal DOM.jsQRtobarcode-detector.barcode-detector@^3.1.1to dependencies and removedhtml5-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).