Newer Version Available

This content describes an older version of this product. View Latest

Understand BarcodeScanner Modern and Legacy APIs

In previous versions of BarcodeScanner, scanning a single barcode in a scanning session required a different programmatic approach than scanning several barcodes in a row without requiring user intervention after each scan. Now, BarcodeScanner has new APIs to streamline the development experience for these common use cases, and new capabilities to scan large quantities of barcodes more efficiently.

Legacy APIs and Modern APIs

We use the terms legacy APIs and modern APIs here. Let’s clarify what they mean.

  • Legacy APIs refer to the functions beginCapture(), resumeCapture(), and endCapture()
  • Modern APIs refer to the functions scan() and dismiss()

The legacy APIs are supported, but will be retired in a future release–the modern APIs replace them fully. The legacy APIs support single scanning and continuous scanning modes, but not bulk scanning or multi-scanning.

The modern APIs are, as you’ve probably guessed, a newer addition to BarcodeScanner. They were created to simplify the development experience, and they support all scanning modes, including bulk scanning and multi-scanning.

If you’re adding BarcodeScanner to your LWC for the first time, use the modern APIs. There’s no advantage to using the legacy APIs, and you’ll eventually have to switch to the modern APIs anyway, when the retirement of the legacy APIs becomes official.

If you have an existing LWC that uses the legacy APIs, we encourage you to update your code to use the modern APIs as soon as possible, so you can enjoy a more streamlined development experience and also have access to the new bulk scanning and multi-scanning capabilities.

Note

The following table summarizes the relationships of the legacy APIs to the modern APIs replacing them:

Legacy API Modern API Notes
beginCapture() scan() scan() replaces both beginCapture() and resumeCapture().
resumeCapture() scan()
endCapture() dismiss()

Practical Differences Between scan() and beginCapture()

For the most part, the behavior of the modern APIs is identical to their legacy counterparts. One notable difference is how the returned promise is resolved in scan(), compared to beginCapture().

In beginCapture(), the returned Promise resolves to a single result. In scan(), the returned Promise resolves to an array of results. Because bulk scanning and multi-scanning process multiple barcodes simultaneously, only the modern scan() API supports them.