This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The BarcodeDetector interface of the Barcode Detection API allows detection of linear and two dimensional barcodes in images.
BarcodeDetector.BarcodeDetector() Experimental
Creates and returns a BarcodeDetector object, with optional BarcodeDetectorOptions.
getSupportedFormats() Experimental
Returns a Promise which fulfills with an Array of supported barcode format types.
detect() Experimental
Returns a Promise which fulfills with an array of DetectedBarcode objects with the following properties:
boundingBox: A DOMRectReadOnly, which returns the dimensions of a rectangle representing the extent of a detected barcode, aligned with the image.cornerPoints: The x and y co-ordinates of the four corner points of the detected barcode relative to the image, starting with the top left and working clockwise. This may not be square due to perspective distortions within the image.format: The detected barcode format. (For a full list of formats, consult the supported barcode format) list.rawValue: A string decoded from the barcode data.This example creates a new barcode detector object, with specified supported formats and tests for browser compatibility.
// check compatibility
if (!("BarcodeDetector" in globalThis)) {
console.log("Barcode Detector is not supported by this browser.");
} else {
console.log("Barcode Detector supported!");
// create new detector
const barcodeDetector = new BarcodeDetector({
formats: ["code_39", "codabar", "ean_13"],
});
}
The following example calls the getSupportFormat() static method and logs the results to the console.
// check supported types
BarcodeDetector.getSupportedFormats().then((supportedFormats) => {
supportedFormats.forEach((format) => console.log(format));
});
This example uses the detect() method to detect the barcodes within the given image. These are iterated over and the barcode data is logged to the console.
barcodeDetector
.detect(imageEl)
.then((barcodes) => {
barcodes.forEach((barcode) => console.log(barcode.rawValue));
})
.catch((err) => {
console.log(err);
});
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
BarcodeDetector |
88Supported on ChromeOS and macOS only.83–88Supported on macOS only. |
83Supported on macOS only. |
No | 69Supported on macOS only. |
17 | 83 | No | 59 | 17 | 13.0 | 83 | No |
BarcodeDetector |
88["Supported on ChromeOS and macOS only.", "Before Chrome 113, on macOS Ventura (13) and above, this interface silently failed. See bug 40245611."]83–88Supported on macOS only. |
83["Supported on macOS only.", "Before Chrome 113, on macOS Ventura (13) and above, this interface silently failed. See bug 40245611."] |
No | 69["Supported on macOS only.", "Before Chrome 113, on macOS Ventura (13) and above, this interface silently failed. See bug 40245611."] |
17 | 83 | No | 59 | 17 | 13.0 | 83 | No |
detect |
88Supported on ChromeOS and macOS only.83–88Supported on macOS only. |
83Supported on macOS only. |
No | 69Supported on macOS only. |
17 | 83 | No | 59 | 17 | 13.0 | 83 | No |
getSupportedFormats_static |
88Supported on ChromeOS and macOS only.83–88Supported on macOS only. |
83Supported on macOS only. |
No | 69Supported on macOS only. |
17 | 83 | No | 59 | 17 | 13.0 | 83 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/BarcodeDetector