e01.org

BarcodeDetector: BarcodeDetector() constructor

Barcode Detector API

Barcode Detector API

The **`BarcodeDetector()`** constructor creates
a new BarcodeDetector object which detects linear and two-dimensional
barcodes in images.

## Syntax

```js-nolint
new BarcodeDetector()
new BarcodeDetector(options)
```

### Parameters

- `options`
- : An options object containing a series of `BarcodeFormats` to search for
in the subsequent detect() calls. The
options are:
- `formats`
- : An Array of barcode formats as strings.
If not provided, `detect()` calls search for all supported formats.
Limiting to specific formats is therefore recommended for performance reasons.
To see a full list of supported formats see the [supported barcode format](/docs/Web/API/Barcode_Detection_API#supported_barcode_formats).

### Exceptions

- TypeError
- : Thrown if the `formats` is specified and the parameter is empty or contains `unknown`.

## Examples

This example creates a new barcode detector object, with specified supported formats
and tests for browser compatibility.

```js
// 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"],
});
}
```

## Specifications

## Browser compatibility

source: MDN Web Docs mirror · page

Cite this

"BarcodeDetector: BarcodeDetector() constructor". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/BarcodeDetector/BarcodeDetector

JSON record · API collection · citation policy