← Blog 6 min read

Barcode Detection API: What QR Scanners Read

Barcode Detection API: What QR Scanners Read

A web page can identify a QR code from a camera frame, uploaded image, canvas, or video without asking a user to install a separate scanning app. The Barcode Detection API gives supporting browsers a common interface for that job.

Detection sounds mechanical, but the result can contain a login link, payment destination, contact card, Wi-Fi credential, boarding pass, or product identifier. Reading the pattern is only the first step. Deciding what to do with its contents requires a second, visible choice.

Barcode Detection API reads codes from images

The API creates a BarcodeDetector for one or more supported formats, then passes an image source to detect(). That source can be an image element, video frame, canvas, bitmap, blob, or raw image data.

The browser returns detected codes with their format, location, corner points, and decoded value. MDN's Barcode Detection API guide lists formats including QR Code, Data Matrix, Aztec, EAN, UPC, Code 39, and Code 128.

Support is limited and experimental. The API requires a secure context in supporting browsers, and developers should call getSupportedFormats() rather than assuming every device recognizes every symbol.

Detection does not automatically open the result

A decoded QR code may contain a URL, but the detector's job is to return text. It does not need to navigate, submit a payment, join a network, add a contact, or sign in.

That separation is a useful safety boundary. The page should display the result in a review screen, identify its type, and ask for another deliberate action before doing anything consequential. A scanner that opens every URL immediately gives a printed pattern too much authority.

Users should read the full destination, not only the large button beside it. Look for misspelled domains, unexpected URL shorteners, unusual schemes, or a request that does not match the physical context.

The image source determines the privacy risk

Detecting a code in an uploaded image does not inherently require camera access. The page already has the file the user selected. A live scanner, however, usually obtains frames from a camera stream, which is governed by the browser's separate media permission model.

The detector does not grant camera permission by itself. Our guide to browser camera permissions explains how capture starts, how indicators work, and how access can be revoked.

A careful scanner asks for the rear camera only after the user chooses “Scan.” It keeps the preview visible, stops the stream after a result or cancellation, and offers file upload as a lower-access alternative.

Decoded values can be sensitive

Barcodes are containers, not merely links. A code can embed a ticket number, shipment reference, membership identifier, contact details, or a token that grants access. Displaying or logging that raw value can expose more than the visible label suggests.

Developers should process results locally when possible and avoid sending every scan to analytics. Error reports should describe the failure without copying the decoded payload. If a backend lookup is required, transmit only what the service genuinely needs and explain that network step.

Do not store scan history by default. When history is useful, make it opt-in, clearly labelled, and easy to clear. The same principle applies to screenshots and uploaded images: discard them after detection unless the user chooses to save them.

QR codes deserve the same suspicion as links

A QR code can hide a long destination behind a tidy square. That makes visual inspection harder than with an ordinary link. Attackers can place a sticker over a legitimate code or reproduce the surrounding design while changing the payload.

Show the decoded hostname prominently before navigation. Expand shortened URLs when it is safe to do so, distinguish HTTPS from other schemes, and warn when a code requests a download or opens an application. Our guide to pop-ups and redirects explains a related principle: one clear action should cause one understandable transition.

A browser's phishing protections still matter after navigation, but they cannot confirm that the code belongs to the poster, menu, ticket machine, or parcel in front of you. Physical context remains part of the security decision.

Product codes need careful interpretation

Linear retail barcodes often identify a product record rather than a unique physical item. Scanning a UPC or EAN may support price comparison or inventory lookup, but it does not prove authenticity, ownership, condition, or origin.

Applications should label the source of any product data they add after detection. The barcode supplies an identifier; a retailer or catalogue supplies the description, price, and availability. Mixing those steps can make database errors look like scanner errors.

For tickets and boarding passes, the stakes are different. Avoid showing the full raw value in screenshots or support messages. A readable barcode may function like a credential even when it looks like an ordinary image.

Fallbacks keep scanners usable

Because support is uneven, a production scanner needs a fallback. A JavaScript decoding library can process the selected image, or the site can offer manual entry when detection fails. Any server-side fallback should clearly state that the image will be uploaded.

Do not repeatedly request camera permission after a denial. Explain how to use file upload or manual input instead. The API can also run in a Web Worker in supporting environments, helping keep the interface responsive during image processing.

Our guide to the File System Access API covers a different relationship with local files. Barcode detection reads the image object it receives; it does not grant broad access to folders or nearby documents.

How to scan with more control

Use a scanner you trust, frame only the code you intend to read, and stop the camera when the result appears. Review the decoded hostname or action before continuing. Treat tickets, access codes, Wi-Fi credentials, and sign-in links as sensitive.

Developers should separate detection from action, minimize retention, avoid raw-value analytics, and make camera use unmistakable. The Barcode Detection API can remove friction without removing judgment. A code may be machine-readable; its intent still needs a human check.

Browse with more intention

Noorani brings prayer times, Qibla, tracker blocking, and privacy into one calm desktop browser built for how Muslims live online.

Download Noorani