Develop Secure Code
BarcodeScanner Constants
BarcodeScanner Data Types
getBarcodeScanner()
isAvailable()
scan(options)
dismiss()
beginCapture(options) (Legacy)
resumeCapture() (Legacy)
endCapture() (Legacy)
beginCapture(options) (Legacy)Use this function to start a new scanning session.
We recommend using the modern scan() and dismiss() APIs in your LWC’s scanning code to streamline your development experience. The legacy APIs beginCapture(), resumeCapture(), and endCapture() are still available, but will be retired in a future release.
Note
1import { getBarcodeScanner } from 'lightning/mobileCapabilities';
2beginCapture(options: BarcodeScannerOptions): Promise<Object>options—(Required) A BarcodeScannerOptions object to configure the scanning session.A Promise object that resolves as a Barcode with the scanned barcode details.
A rejected promise returns a BarcodeScannerFailure.
This function allocates scanner resources. To release the resources when scanning is complete, pair it with endCapture().
1myScanner
2 .beginCapture(scanningOptions)
3 .then((result) => {
4 // Do something with the result of the scan
5 console.log(result);
6 this.scannedBarcode = result.value;
7 })
8 .catch((error) => {
9 // Handle cancellation and scanning errors here
10 console.error(error);
11 })
12 .finally(() => {
13 myScanner.endCapture();
14 });When this function is called, a mobile OS scanning user interface is displayed on the mobile device. The user can point their camera at a barcode and wait for the barcode to be recognized.
then clause.catch clause.BarcodeScannerFailure.code value of userDismissedScanner.endCapture().endCapture(), in a finally clause.See Also