Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

barcode-detector-zbar

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

barcode-detector-zbar

Barcode detector polyfill using zbar.wasm

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

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());
  BarcodeDetectorPolyfill.setupPolyfill();
</script>

Simply use like the regular api (check https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API).

zbar.wasm

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()) {
    Swal.fire("You need a secure context!");
  } else {
    Swal.fire("No webcam connected!");
  }
}

You can try the demo

Running npm run start and see demo.html or https://codepen.io/lekoalabe/pen/abyrqaL (currently not working due to CORS issue loading the wasm file)

Also check out

Other

Api ref

Scanner app

Zbar

Zxing

Other libs

Other polyfills

Keywords

barcode

FAQs

Package last updated on 15 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts