Code
Browser Web APIs
Allows web applications to redirect audio output to a permitted Bluetooth headset, speakerphone, or other device.
Provides a way for browsers to better manage audio sessions and inform browsers about what kind of audio is being played.
Provides a method for managing downloads that may take a significant amount of time, running in the background if the user navigates away.
Enables web apps to defer tasks to be run in a service worker once the user has a stable network connection.
Allows scheduling of non-critical work to be performed during idle periods via requestIdleCallback.
Allows installed web apps to set a badge on the app icon to notify users of pending activity such as messages or updates.
Detects linear and two-dimensional barcodes, including QR codes, in images and video streams.
Provides information about the battery charge level of the device and notifications when the level or status changes.
Sends asynchronous, non-blocking requests to a server without expecting a response, ideal for analytics and diagnostics.
Enables simple communication between browsing contexts such as tabs, windows, and iframes sharing the same origin.
Barcode Detection API
ExperimentalDetects linear and two-dimensional barcodes in images and video streams using the platform's native barcode scanning capabilities. Supports formats including QR codes, Data Matrix, PDF417, EAN, UPC, Code 128, and more. Requires a secure context (HTTPS).
Key Interface
new BarcodeDetector(options?)— Creates a detector. Optionally pass{ formats: ['qr_code', 'ean_13'] }to restrict formats.BarcodeDetector.detect(image)— Returns aPromise<DetectedBarcode[]>. AcceptsImageBitmap,HTMLImageElement,HTMLVideoElement,HTMLCanvasElement, orBlob.BarcodeDetector.getSupportedFormats()— Static method returning aPromise<string[]>of supported barcode formats.DetectedBarcode.rawValue— The decoded string value of the barcode.DetectedBarcode.boundingBox— ADOMRectReadOnlygiving the bounding box of the detected barcode in the image.
Example — Detect barcodes in an image
const detector = new BarcodeDetector({
formats: ['qr_code', 'ean_13', 'code_128'],
});
const img = document.querySelector('img#product');
try {
const barcodes = await detector.detect(img);
for (const barcode of barcodes) {
console.log('Format:', barcode.format);
console.log('Value:', barcode.rawValue);
console.log('Bounding box:', barcode.boundingBox);
}
} catch (err) {
console.error('Detection failed:', err);
}Example — Scan from a live camera stream
Run detection on each video frame using requestAnimationFrame for a continuous scan loop.
const video = document.querySelector('video');
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
video.srcObject = stream;
await video.play();
const detector = new BarcodeDetector({ formats: ['qr_code'] });
async function scanFrame() {
const barcodes = await detector.detect(video);
if (barcodes.length > 0) {
console.log('Scanned QR:', barcodes[0].rawValue);
// stop scanning once found
return;
}
requestAnimationFrame(scanFrame);
}
requestAnimationFrame(scanFrame);Example — Query supported formats
const formats = await BarcodeDetector.getSupportedFormats();
console.log('Supported formats:', formats);
// e.g. ["aztec", "code_128", "data_matrix", "ean_13", "qr_code", ...]