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.

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().

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.

  • When a barcode is successfully scanned, the result is returned via a fulfilled promise. Handle successful results in a then clause.
  • When a barcode scan fails, the error is returned via a rejected promise. Handle errors in a catch clause.
  • When the user clicks the Cancel button during a scan, the promise is rejected with a BarcodeScannerFailure.code value of userDismissedScanner.
  • The mobile OS scanner interface remains displayed after a successful scan or an error. To close the scanner interface and return to your component’s interface, call endCapture().
  • Handle any final cleanup, such as calling endCapture(), in a finally clause.

See Also