Skip to main content

Html5QrcodeScanner

html5-qrcode / Html5QrcodeScanner

Class: Html5QrcodeScanner

End to end web based QR and Barcode Scanner.

Use this class for setting up QR scanner in your web application with few lines of codes.

  • Supports camera as well as file based scanning.
  • Depending on device supports camera selection, zoom and torch features.
  • Supports different kind of 2D and 1D codes Html5QrcodeSupportedFormats.

Table of contents​

Constructors​

Methods​

Constructors​

constructor​

• new Html5QrcodeScanner(elementId, config, verbose)

Creates instance of this class.

Parameters​

NameTypeDescription
elementIdstringId of the HTML element.
configundefined | Html5QrcodeScannerConfigExtra configurations to tune the code scanner.
verboseundefined | booleanIf true, all logs would be printed to console.

Defined in​

html5-qrcode-scanner.ts:208

Methods​

applyVideoConstraints​

▸ applyVideoConstraints(videoConstaints): Promise<void>

Apply a video constraints on running video track from camera.

Note: Should only be called if () returns SCANNING or PAUSED.

Throws

error if the scanning is not in running state.

Parameters​

NameType
videoConstaintsMediaTrackConstraints

Returns​

Promise<void>

a Promise which succeeds if the passed constraints are applied, fails otherwise.

Defined in​

html5-qrcode-scanner.ts:428


clear​

▸ clear(): Promise<void>

Removes the QR Code scanner UI.

Returns​

Promise<void>

Promise which succeeds if the cleanup is complete successfully, fails otherwise.

Defined in​

html5-qrcode-scanner.ts:335


getRunningTrackCapabilities​

▸ getRunningTrackCapabilities(): MediaTrackCapabilities

Returns the capabilities of the running video track.

Read more: https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/getConstraints

Note: Should only be called if () returns SCANNING or PAUSED.

Throws

error if the scanning is not in running state.

Returns​

MediaTrackCapabilities

the capabilities of a running video track.

Defined in​

html5-qrcode-scanner.ts:393


getRunningTrackSettings​

▸ getRunningTrackSettings(): MediaTrackSettings

Returns the object containing the current values of each constrainable property of the running video track.

Read more: https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/getSettings

Note: Should only be called if () returns SCANNING or PAUSED.

Throws

error if the scanning is not in running state.

Returns​

MediaTrackSettings

the supported settings of the running video track.

Defined in​

html5-qrcode-scanner.ts:410


getState​

▸ getState(): Html5QrcodeScannerState

Gets state of the camera scan.

Returns​

Html5QrcodeScannerState

state of type Html5QrcodeScannerState.

Defined in​

html5-qrcode-scanner.ts:325


pause​

▸ pause(shouldPauseVideo?): void

Pauses the ongoing scan.

Notes:

  • Should only be called if camera scan is ongoing.

Throws

error if method is called when scanner is not in scanning state.

Parameters​

NameTypeDescription
shouldPauseVideo?boolean(Optional, default = false) If true the video will be paused.

Returns​

void

Defined in​

html5-qrcode-scanner.ts:294


render​

▸ render(qrCodeSuccessCallback, qrCodeErrorCallback): void

Renders the User Interface.

Parameters​

NameTypeDescription
qrCodeSuccessCallbackQrcodeSuccessCallbackCallback called when an instance of a QR code or any other supported bar code is found.
qrCodeErrorCallbackundefined | QrcodeErrorCallbackoptional, callback called in cases where no instance of QR code or any other supported bar code is found.

Returns​

void

Defined in​

html5-qrcode-scanner.ts:241


resume​

▸ resume(): void

Resumes the paused scan.

If the video was previously paused by setting shouldPauseVideo to true in (shouldPauseVideo), calling this method will resume the video.

Notes:

  • Should only be called if camera scan is ongoing.
  • With this caller will start getting results in success and error callbacks.

Throws

error if method is called when scanner is not in paused state.

Returns​

void

Defined in​

html5-qrcode-scanner.ts:316