Scan Barcode in LWC Natively

Barcode in LWC
Barcode in LWC

Around 7 years back I have written this post which shows how Barcode scan can be supported in Visualforce and in aura component with the help of an external javascript library quagga.

Salesforce recently released a new Barcode API which now supports barcode scanning natively on LWC for mobile devices. As it’s supported natively, we don’t need to worry about maintaining 3rd party Javascripts, Locker services, performance issues, etc.

At the time of writing this blog post, around 10 different types of barcodes are supported.

Below source code demonstrate how simple it is to use in LWC.

  • import lightning/mobileCapabilities
  • initiate scanner variable using method getBarcodeScanner()
  • set configuration suggesting which barcodes are supported
  • use begineCapture() method top launch mobile camera
  • read the result or handle error

Resources :

3 comments

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.