Polyfill for BarcodeDetector, part of shape detection api
This is basically a Promise wrapper around DecoderWorker from the JOB barcode decoding library.
Note that currently this polyfill enables detection and decoding of 1D barcodes only, 2D barcodes (EG QR-code) might be added in the future using an additional library.
Install:
bower install barcode-detector-polyfill
Use:
<script>
(function () {
function loadScript(src, done) {
var $script = document.createElement('script');
$script.src = src;
$script.onload = function() {
done();
};
$script.onerror = function() {
done(new Error('Failed to load script ' + src));
};
document.head.appendChild($script);
}
if (BarcodeDetector in window) {
continueToStartTheApp();
} else {
loadScript(
"bower_components/barcode-detector-polyfill/BarcodeDetector.min.js",
continueToStartTheApp
);
}
})()
// ...
</script>
Install:
npm install --save barcode-detector-polyfill
Use:
if ('BarcodeDetector' in window) {
continueToStartTheApp();
} else {
require.ensure(['barcode-detector-polyfill'], function(require) {
const BarcodeDetector = require('barcode-detector-polyfill');
window.BarcodeDetector = BarcodeDetector;
continueToStartTheApp();
}, function(err) {
console.log('Failed to load BarcodeDetector', err);
});
}
See demo
See the examples folder, or live demo
Requires Promises (can also be polyfilled) and typed arrays which are supported in all modern browsers, down to IE11.