QRScanner
The host's native full-screen QR scanner. Host-optional: the le.codes app provides it, the
generic web viewer (and other hosts) don't — always guard with QRScanner.isSupported before
offering the feature.
At a glance
if (QRScanner.isSupported) {
const scanner = new QRScanner(data => {
if (data === null) return // a camera frame with no readable code
console.log('scanned:', data)
scanner.close()
})
await scanner.open() // asks for camera permission, then opens the scanner
}API
QRScanner.isSupported: boolean // static — does this host have a scanner?
new QRScanner(onData: (data: string | null) => void) // onData fires per decoded frame
scanner.open(): Promise<void> // request camera access, open the scanner
scanner.close(): void // close the scanner, release the cameraonDatafires for every value the scanner decodes;nullmeans a frame with no readable code, so expect it repeatedly while the user is aiming. The same code can be reported more than once — debounce/close()yourself when you've got what you need.open()runs two steps in order: request camera permission, then open the native scanner. The promise resolves once the scanner is open and rejects if the user denies camera access.
Note
unlike physics (which silently no-ops when absent), open() throws an Error
on hosts without a scanner. isSupported is the guard — check it before showing a "Scan"
button at all. See host gating.
Note
lifecycle — the scanner holds the camera until close() is called. If you open it
from a screen, close it in the screen's onClose (and after a successful scan) or the camera
stays captured.
See also
- Conventions — host gating —
the other capability guards (
Physics.supported,Physics2D.supported)