Barcode Detection
Browser Support
Usage
Basic Barcode Detection from an Image
<div {{ stimulus_controller('@pwa/barcode-detection') }}>
<img id="barcode-image" src="/path/to/barcode.jpg" alt="Barcode">
<button {{ stimulus_action('@pwa/barcode-detection', 'detect', 'click', {target: '#barcode-image'}) }}>
Scan Barcode
</button>
</div>
<script>
document.addEventListener('pwa--barcode-detection:detected', (event) => {
const barcodes = event.detail;
barcodes.forEach(barcode => {
console.log('Format:', barcode.format);
console.log('Value:', barcode.rawValue);
console.log('Bounding box:', barcode.boundingBox);
});
});
document.addEventListener('pwa--barcode-detection:unsupported', () => {
alert('Barcode detection is not supported in this browser');
});
</script>Detection with Specific Formats
Detection from Video Stream
Parameters
formats Value
formats ValueActions
detect
detectTargets
Events
pwa--barcode-detection:detected
pwa--barcode-detection:detectedpwa--barcode-detection:unsupported
pwa--barcode-detection:unsupportedpwa--barcode-detection:error
pwa--barcode-detection:errorBest Practices
Common Use Cases
Product Scanner
QR Code URL Handler
Last updated
Was this helpful?