Shape Detection: BarcodeDetector
Finds and reads barcodes and QR codes in an image or camera frame.
In one line
Can find barcodes and QR codes in a picture or camera view
Finds and reads barcodes and QR codes in an image or camera frame.
Turns pixels into decoded strings (product codes, URLs, tickets). Runs on-device with no prompt, once the page has the image.
What it can and can't do
What the user does: You tap Scan QR code and allow your camera, or you pick a photo.
It can
- Find a barcode or QR code in a photo
- Scan live from your camera, once you allow it
- Tell the page what the code says
It cannot
- Use your camera without its own camera permission
- Scan in Firefox or in Safari without a special setting
- Always find codes in a blurry or tilted image
- See the rest of your camera roll
How it differs between platforms: Chrome, Edge and Android Chrome support it, though not on every device. Safari and Firefox lack full support.
Browser support
| Browser | Status | First version | Released | Note |
|---|---|---|---|---|
| Chrome | Supported | 88 | 2021-01-19 | Android 83; desktop 88 |
| Edge | Partial | 83 | 2020-05-21 | Supported on macOS only. Before Chrome 113, on macOS Ventura (13) and above, this interface silently failed. See <a href="https://crbug.com/40245611">bug 402456 |
| Firefox | Not supported | Not available | Not listed | None |
| Safari | Behind a flag | 17 | Not listed | Behind flag |
| Safari on iPhone | Behind a flag | 17 | Not listed | Behind flag |
| Chrome on Android | Supported | 83 | 2020-05-19 | None |
| Samsung Internet | Supported | 13.0 | 2020-12-02 | None |
How a site asks for it
| API | new BarcodeDetector({formats}).detect(imageBitmap) |
| Browser compat keys | api.BarcodeDetector |
| How access is granted | none |
| What the user sees | None for the API; camera needs getUserMedia prompt |
| Needs a secure context (HTTPS) | Yes |
| Needs a user gesture | No |
| How long it lasts | Per origin |
| How to take it back | Site settings |
| Inside an iframe | Same as top level; cross-origin iframes need a permissions policy where listed |
Typical flow
- Call the API
- Browser applies its access rules
- Page receives the result
Data you get
What comes back: Finds and reads barcodes and QR codes in an image or camera frame.
Shape: object
How often: on demand
| Field | Type | Unit | Range | Precision |
|---|---|---|---|---|
rawValue | string | None | decoded text | Not listed |
format | enum | None | qr_code, ean_13, code_128, aztec, pdf417, data_matrix and more (about 14) | Not listed |
boundingBox | object | pixels | image rect | Not listed |
cornerPoints | list | pixels | 4 points | Not listed |
Technical limits
- Chrome only in practice
- Format list varies by OS (Android, ChromeOS, macOS; Windows partial)
- FaceDetector and TextDetector exist only behind flags
The story
What it is
A page can read barcodes and QR codes from a picture or the camera.
For you
You hold your camera to a QR code or barcode and the page reads it in a flash. The camera still asks permission first.
For makers
Makers can scan tickets, products and payments without a native app, using the camera you already approved. The reading runs on your device so images do not need to leave it.
Where you see it
| Type | Example | Apps |
|---|---|---|
| shopping | A store site scans a barcode to look up a product in the aisle. | None named |
| live | An event site scans tickets at the door with a phone. | Eventbrite |
| payments | A payments site scans a QR code to pay. | None named |
| travel | An airline site reads a boarding pass code. | None named |
| enterprise | A warehouse web tool scans shelf labels and counts stock. | None named |
| security | A phisher puts a fake QR code on a flyer that leads to a bad site. | None named |
Risks
- Fake QR codes
- Limited browser support
What the platform says
- Google: Shape Detection API. Chrome's docs describe the API as a way to detect barcodes, faces and text in images.
Good uses and abuse
Legitimate uses
- Ticket and product scanning
- QR sign in
Known abuse
- Reading codes from photos silently
Scores
| Score | Value | Meaning |
|---|---|---|
| Sensitivity | 2 of 5 | How revealing the data is |
| Utility | 4 of 5 | How useful it is to honest apps |
| Friction | 0 of 5 | How much the user has to do |
| Fingerprint bits | Not rated | Rough identifying entropy, when known |
History
- 2019-02, Chrome 83: Android first (desktop 88)
- 2023-09, Safari 17: Behind a flag in Safari
Sources
How well checked: Checked against real behavior.