Scanner API
The Scanner API provides access to barcode and QR code scanning functionality on POS devices, allowing you to subscribe to scan events, monitor available scanner sources, and process scanned data in real-time. The API enables integration with device cameras, external scanners, and embedded scanning hardware.
Anchor to Use casesUse cases
- Barcode scanning: Implement barcode scanning for product lookup or inventory management.
- QR codes: Build QR code scanning for customer engagement or loyalty programs.
- Custom workflows: Create scanning workflows that process data and trigger business logic.
- Real-time feedback: Implement real-time scanning feedback with immediate processing.
Supported targets
Supported targets
Anchor to PropertiesProperties
The shopify global object provides barcode and QR code scanning capabilities. Access the following properties on shopify to read scan data, control the camera scanner, and detect available scanner hardware.
- Anchor to scannerDatascannerDatascannerDataScannerDataScannerDatarequiredrequired
Access current scan data and subscribe to new scan events. Use to receive real-time scan results.
- Anchor to sourcessourcessourcesScannerSourcesScannerSourcesrequiredrequired
Access available scanner sources on the device. Use to check which scanners are available (camera, external, or embedded).
ScannerData
Represents the scanner interface for accessing scan events and subscription management. Provides real-time access to scanned data through a reactive signal pattern.
- current
Current available scanner sources with subscription support. The `value` property provides current sources, and `subscribe` listens for changes. Use to monitor which scanners are available.
ReadonlySignalLike<ScannerSubscriptionResult>
ReadonlySignalLike
Represents a reactive signal interface that provides both immediate value access and subscription-based updates. Enables real-time synchronization with changing data through the observer pattern.
- subscribe
Subscribes to locale changes and calls the provided function whenever the locale updates. Returns an unsubscribe function to clean up the subscription. Use to automatically update your extension content when merchants change their language settings during POS sessions.
(fn: (value: T) => void) => () => void - value
The current value of the locale string in IETF format. For example, `"en-US"`, `"fr-CA"`, or `"de-DE"`. This property provides immediate access to the current locale without requiring subscription setup. Use for one-time locale checks or initial internationalization setup.
T
ScannerSubscriptionResult
Represents the data from a scanner event. Contains the scanned string data and the hardware source that captured the scan.
- data
The string data from the last scanner event received. Contains the scanned barcode, QR code, or other scannable data. Returns `undefined` when no scan data is available. Use to process scanned content and implement scan-based business logic.
string - source
The scanning source from which the scan event came. Returns one of the following scanner types: • `'camera'` - Built-in device camera used for scanning • `'external'` - External scanner hardware connected to the device • `'embedded'` - Embedded scanner hardware built into the device
ScannerSource
ScannerSource
The scanner source the POS device supports.
'camera' | 'external' | 'embedded'ScannerSources
Represents the available scanner hardware sources on the device. Provides reactive access to the list of scanners that can be used for scanning operations.
- current
Current available scanner sources with subscription support. The `value` property provides current sources, and `subscribe` listens for changes. Use to monitor which scanners are available.
ReadonlySignalLike<ScannerSource[]>
Anchor to Best practicesBest practices
- Handle scan events reactively: Use
subscribemethods to process scan events as they occur for immediate feedback. - Validate scanned data: Validate before processing and handle invalid codes, unsupported formats, or errors.
- Provide clear feedback: Show success confirmations, error messages, and guidance when scans fail.
- Adapt to available sources: Check available scanner sources and provide alternatives when preferred methods aren't available.
- Handle scan data processing: Scan data processing is reactive and requires proper subscription management to avoid memory leaks or unexpected behavior when components unmount.
Anchor to LimitationsLimitations
The Scanner API is only available in action (modal) targets where scanning functionality is supported and can't be used in other targets.