Barcode detector polyfill using zbar.wasm

Usage no npm install needed!

<script type="module">
  import barcodeDetectorZbar from '';


Barcode Detector Api Polyfill using zbar.wasm

NPM Downloads

How to use

This is a very simple polyfill using zbar.wasm under the hood written in plain ES6.

You can install the polyfill with BarcodeDetectorPolyfill.setupPolyfill().

<script type="module">
  import BarcodeDetectorPolyfill from "./BarcodeDetectorPolyfill.min.js";

  console.log("Native api support", BarcodeDetectorPolyfill.checkBarcodeDetectorSupport());

Simply use like the regular api (check


This polyfill uses zbar.wasm and therefore needs to load a ~200kb bin file in order to work. The polyfill itself is 9.5kb.

Checking secure context

Webcam is only available in a secure context. Here is some sample code to help you (using Swal to show an error message).

if (!BarcodeDetectorPolyfill.checkWebcamSupport()) {
  if (!BarcodeDetectorPolyfill.checkSecureContext()) {"You need a secure context!");
  } else {"No webcam connected!");

You can try the demo

Running npm run start and see demo.html or (currently not working due to CORS issue loading the wasm file)

Also check out


Api ref

Scanner app



Other libs

Other polyfills