Skip to content

Commit e23c10b

Browse files
committed
Blog: add post about the QR scanner demo
1 parent fd6e23c commit e23c10b

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
slug: qr-scanner-demo
3+
title: "A QR scanner in the browser: live demo of @codeuctivity/qr-scanner"
4+
authors: [stesee]
5+
tags: [qr code, pwa, javascript, react, npm]
6+
---
7+
8+
[qr-scanner.codeuctivity.cloud](https://qr-scanner.codeuctivity.cloud/) is a small live demo of our npm package [`@codeuctivity/qr-scanner`](https://www.npmjs.com/package/@codeuctivity/qr-scanner). Point a camera at a QR code and the decoded value lands in a list - no app store, no account, no backend.
9+
10+
*This post contains one affiliate link, marked as such.*
11+
12+
<!-- truncate -->
13+
14+
## What the demo does
15+
16+
- **Scans with the device camera.** On a phone it picks the rear camera on its own; any other camera can be chosen from a dropdown. Zoom and torch are offered where the browser and the camera support them.
17+
- **Keeps a history.** Every decoded value is added to a table with its timestamp. Tap a row to see the full value - binary content is shown as base64.
18+
- **Ignores accidental repeats.** A code that stays in front of the camera is logged once, not dozens of times. Scan it again a few seconds later and it is logged again.
19+
- **Exports to Excel.** The history can be downloaded as an `.xlsx` file.
20+
- **Gives feedback.** A beep and a vibration on a successful scan, both switchable in the settings.
21+
- **Light and dark theme**, or whatever the system prefers.
22+
- **Installable as a PWA** and usable offline once it has been loaded.
23+
24+
## Where the data goes
25+
26+
Nowhere. Decoding happens in the browser, and the history is kept in the browser's `localStorage`. There is no server-side part that sees the camera image or the scanned values. Deleting an entry or clearing the list removes it for good.
27+
28+
The camera needs a secure context, so the page is served over HTTPS, and the browser asks for camera permission on the first visit.
29+
30+
## Using it on a desktop
31+
32+
Phones bring a good camera along. On a desktop PC or a laptop with a weak built-in camera, scanning a code from a sheet of paper or a parcel label gets easier with an external webcam that has a decent resolution and can be pointed at the desk - for example the [Anker PowerConf C200 2K webcam](https://amzn.to/4wLNgjb) (affiliate link). The demo lists it in the camera dropdown like any other video device.
33+
34+
## The package behind it
35+
36+
The demo is intentionally thin - the work is done by `@codeuctivity/qr-scanner`, our maintained fork of Nimiq's `qr-scanner`.
37+
38+
```bash
39+
npm install @codeuctivity/qr-scanner
40+
```
41+
42+
```js
43+
import QrScanner from "@codeuctivity/qr-scanner";
44+
45+
const video = document.querySelector("video");
46+
47+
const scanner = new QrScanner(
48+
video,
49+
(result) => console.log("decoded:", result.data),
50+
{ returnDetailedScanResult: true },
51+
);
52+
53+
await scanner.start();
54+
55+
// later
56+
scanner.stop();
57+
scanner.destroy();
58+
```
59+
60+
`QrScanner.listCameras(true)` returns the available cameras for a device picker.
61+
62+
The demo itself is a React app built with Vite, served as static files by nginx.
63+
64+
## Try it
65+
66+
Open [qr-scanner.codeuctivity.cloud](https://qr-scanner.codeuctivity.cloud/), allow camera access and hold a QR code in front of it.
67+
68+
## Affiliate disclosure
69+
70+
The webcam link above is an Amazon affiliate link. As an Amazon Associate we earn from qualifying purchases; the price for you stays the same.
71+
72+
For questions or feedback, contact us at [Codeuctivity@gmail.com](mailto:Codeuctivity@gmail.com).

0 commit comments

Comments
 (0)