Barcode in LWC

Scan Barcode in LWC Natively

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 responses to “Scan Barcode in LWC Natively”

  1. Aditya Sharma Avatar

    Awesome demo of the latest feature.

  2. Boubacar Sow Avatar
    Boubacar Sow

    Wonderfull things. great !!
    Many thanks

  3. Mohit Avatar

    Can we scan QR code in lwc?

Leave a Reply

Your email address will not be published. Required fields are marked *

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