QR Code Scanner Widget
Scans QR codes using the device camera or an uploaded image, with support for switching between multiple cameras, flashlight and zoom controls, and custom JavaScript handlers for scan results.
A static ThingsBoard widget that scans QR codes using the device camera or an uploaded image, with support for switching between multiple cameras, flashlight and zoom controls, and custom JavaScript handlers for scan results.
Features
- Camera mode - live scanning via the device/browser camera, with:
- Camera selection (auto-prefers a rear/back/environment-facing camera)
- Start/Stop controls and a scanning status indicator
- Flashlight (torch) toggle, when supported by the active camera
- Zoom slider, when supported by the active camera
- Image mode - upload an image file and scan it for a QR code
- Optional “Ask user to start scan” prestart screen (camera/permissions aren’t requested until the user opts in)
- Pause/resume after a successful scan
- In-widget camera selector to switch cameras without stopping the widget
Settings
| Setting | Type | Description |
|---|---|---|
onScanSuccess | JavaScript function(qrCode, decodedResult, ctx) | Required. Invoked with the decoded text whenever a QR code is scanned. |
onScanFailure | JavaScript function(errorMessage, ctx) | Optional. Invoked on genuine scan errors (per-frame “not found” noise from the scanning library is filtered out). |
supportedScanTypes | Select: Camera & Image / Camera / Image | Which scan mode(s) are available. Selecting a single mode hides the mode toggle. |
showTorchButtonIfSupported | Switch | Show the flashlight button when the active camera supports it. |
showZoomSliderIfSupported | Switch | Show the zoom slider when the active camera supports it. |
askBeforeScan | Switch | Show a “Start scanning” button instead of requesting camera access immediately on load. |
Usage notes
- Camera access requires a secure context (HTTPS or
localhost) and browser permission grants. onScanSuccess/onScanFailurerun in the widget context (ctx), so they can callctx.showToast(...), update attributes/telemetry, trigger RPCs, etc.- The widget exposes a small internal API (
ctx._qr) for listing cameras and switching the active one; by default no header button action uses it, but a dashboard-level custom action could be wired to it if needed.
Share Your Widget with the Community
Built a custom widget? Export it as a JSON from ThingsBoard and publish it to the IoT Hub through a simple 4-step wizard (Upload, Listing, Readme, Review & Submit). Share it with thousands of ThingsBoard developers worldwide and get featured in the catalog.