Skip to content
Stand with Ukraine flag

QR Code Scanner Widget

  • Widget
  • 2 installs
  • v1.0.0
  • Jul 22, 2026
  • MIT license
  • v4.2+
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.

Widget Type
  • Static
Category
  • Input Forms
  • Video & Cameras

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

SettingTypeDescription
onScanSuccessJavaScript function(qrCode, decodedResult, ctx)Required. Invoked with the decoded text whenever a QR code is scanned.
onScanFailureJavaScript function(errorMessage, ctx)Optional. Invoked on genuine scan errors (per-frame “not found” noise from the scanning library is filtered out).
supportedScanTypesSelect: Camera & Image / Camera / ImageWhich scan mode(s) are available. Selecting a single mode hides the mode toggle.
showTorchButtonIfSupportedSwitchShow the flashlight button when the active camera supports it.
showZoomSliderIfSupportedSwitchShow the zoom slider when the active camera supports it.
askBeforeScanSwitchShow 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/onScanFailure run in the widget context (ctx), so they can call ctx.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.