Cara menggunakan html qr code scanner

Use this lightweight library to easily / quickly integrate QR code, bar code, and other common code scanning capabilities to your web application.

Key highlights

  • 🔲Support scanning .

  • 🖥Supports be it Android, IOS, MacOs, Windows or Linux

  • 🌐Supports like Chrome, Firefox, Safari, Edge, Opera ...

  • 📷Supports scanning with camera as well as local files

  • ➡️Comes with an as well as a .

  • 🔦Supports customisations like , zooming etc.

Supports two kinds of APIs

  • <script src="https://unpkg.com/html5-qrcode" type="text/javascript">
    5 — End-to-end scanner with UI, integrate with less than ten lines of code.

  • <script src="https://unpkg.com/html5-qrcode" type="text/javascript">
    6 — Powerful set of APIs you can use to build your UI without worrying about camera setup, handling permissions, reading codes, etc.

Support for scanning local files on the device is a new addition and helpful for the web browser which does not support inline web-camera access in smartphones. Note: This doesn't upload files to any server — everything is done locally.

Demo at scanapp.orgDemo at qrcode.minhazav.dev - Scanning different types of codes

Notice

UX/UXD/UXR help wanted: We are looking to improve user experience of this code scanning library — if you are interested in making this experience better for both developers and end users, please share your ideas, thoughts, inputs in this discussion

Supported platforms

We are working continuously on adding support for more and more platforms. If you find a platform or a browser where the library is not working, please feel free to file an issue. Check the demo link to test it out.

Legends

  • Means full support — inline webcam and file based
  • Means partial support — only file based, webcam in progress

PC / Mac


Firefox
Chrome
Safari
Opera
Edge
Cara menggunakan html qr code scanner
Cara menggunakan html qr code scanner

Android


Chrome
Firefox
Edge
Opera
Opera Mini
UC

IOS


Safari
Chrome
Firefox
Edge**

* Supported for IOS versions >= 15.1

Before version 15.1, Webkit for IOS is used by Chrome, Firefox, and other browsers in IOS and they do not have webcam permissions yet. There is an ongoing issue on fixing the support for iOS - issue/14

Framework support

The library can be easily used with several other frameworks, I have been adding examples for a few of them and would continue to add more.

Html5VueJsElectronJsReact

Supported Code formats

Code scanning is dependent on Zxing-js library. We will be working on top of it to add support for more types of code scanning. If you feel a certain type of code would be helpful to have, please file a feature request.

CodeExampleQR CodeAZTECCODE_39CODE_93CODE_128ITFEAN_13EAN_8PDF_417UPC_AUPC_EDATA_MATRIXMAXICODE*RSS_14*RSS_EXPANDED*

*Formats are not supported by our experimental integration with native BarcodeDetector API integration (Read more).

Description - View Demo

See an end to end scanner experience at scanapp.org.

This is a cross-platform JavaScript library to integrate QR code, bar codes & a few other types of code scanning capabilities to your applications running on HTML5 compatible browser.

Supports:

  • Querying camera on the device (with user permissions)
  • Rendering live camera feed, with easy to use user interface for scanning
  • Supports scanning a different kind of QR codes, bar codes and other formats
  • Supports selecting image files from the device for scanning codes

How to use

If you are on medium

- Thorough documentation on Html5-qrcode library on Medium.

Documentation

Download the script from release page or install using

<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
7 with:

npm i html5-qrcode

Add an element you want to use as a placeholder for QR Code scanner

<div id="reader" width="600px"></div>

Ideally do not set the height of this container as the height should depend on the height of the video feed from the camera. The library would honor the existing width, otherwise apply the default width. The height is derived from the aspect ratio of the video feed.

Using directly in browser without any loader

If you are not using any loader, you can get the latest UMD javascript code in production from https://unpkg.com/html5-qrcode.

<script src="https://unpkg.com/html5-qrcode" type="text/javascript">

In case you installed the plugin using

<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
7 but still use javascript without any module loader, you can get the minified script in
<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
9

Using with module loaders

Include the script with

// To use Html5QrcodeScanner (more info below)
import {Html5QrcodeScanner} from "html5-qrcode"

// To use Html5Qrcode (more info below)
import {Html5Qrcode} from "html5-qrcode"

Easy Mode - With end to end scanner user interface

<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
5 lets you implement an end to end scanner with few lines of code with the default user interface which allows scanning using the camera or selecting an image from the file system.

You can set up the scanner as follows:

function onScanSuccess(decodedText, decodedResult) {
  // handle the scanned code as you like, for example:
  console.log(`Code matched = ${decodedText}`, decodedResult);
}

function onScanFailure(error) {
  // handle scan failure, usually better to ignore and keep scanning.
  // for example:
  console.warn(`Code scan error = ${error}`);
}

let html5QrcodeScanner = new Html5QrcodeScanner(
  "reader",
  { fps: 10, qrbox: {width: 250, height: 250} },
  /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);

Pro Mode - if you want to implement your own user interface

You can use

<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
6 class to set up your QR code scanner (with your own user interface) and allow users to scan QR codes using the camera or by choosing an image file in the file system or native cameras in smartphones.

You can use the following APIs to

// To use Html5QrcodeScanner (more info below)
import {Html5QrcodeScanner} from "html5-qrcode"

// To use Html5Qrcode (more info below)
import {Html5Qrcode} from "html5-qrcode"
2,
// To use Html5QrcodeScanner (more info below)
import {Html5QrcodeScanner} from "html5-qrcode"

// To use Html5Qrcode (more info below)
import {Html5Qrcode} from "html5-qrcode"
3 scanning and
// To use Html5QrcodeScanner (more info below)
import {Html5QrcodeScanner} from "html5-qrcode"

// To use Html5Qrcode (more info below)
import {Html5Qrcode} from "html5-qrcode"
4 scanning.

For using inline QR Code scanning with Webcam or Smartphone camera

Start Scanning

To get a list of supported cameras, query it using static method

// To use Html5QrcodeScanner (more info below)
import {Html5QrcodeScanner} from "html5-qrcode"

// To use Html5Qrcode (more info below)
import {Html5Qrcode} from "html5-qrcode"
5. This method returns a
// To use Html5QrcodeScanner (more info below)
import {Html5QrcodeScanner} from "html5-qrcode"

// To use Html5Qrcode (more info below)
import {Html5Qrcode} from "html5-qrcode"
6 with a list of devices supported in format
// To use Html5QrcodeScanner (more info below)
import {Html5QrcodeScanner} from "html5-qrcode"

// To use Html5Qrcode (more info below)
import {Html5Qrcode} from "html5-qrcode"
7.

// This method will trigger user permissions
Html5Qrcode.getCameras().then(devices => {
  /**
   * devices would be an array of objects of type:
   * { id: "id", label: "label" }
   */
  if (devices && devices.length) {
    var cameraId = devices[0].id;
    // .. use this to start scanning.
  }
}).catch(err => {
  // handle err
});

Important: Note that this method will trigger user permission if the user has not granted it already.

Warning: Direct access to the camera is a powerful feature. It requires consent from the user, and your site MUST be on a secure origin (HTTPS).

Warning: Asking for access to the camera on page load will result in most of your users rejecting access to it. More info

Once you have the camera ID from

// To use Html5QrcodeScanner (more info below)
import {Html5QrcodeScanner} from "html5-qrcode"

// To use Html5Qrcode (more info below)
import {Html5Qrcode} from "html5-qrcode"
8, start camera using
// To use Html5QrcodeScanner (more info below)
import {Html5QrcodeScanner} from "html5-qrcode"

// To use Html5Qrcode (more info below)
import {Html5Qrcode} from "html5-qrcode"
9. This method returns a
// To use Html5QrcodeScanner (more info below)
import {Html5QrcodeScanner} from "html5-qrcode"

// To use Html5Qrcode (more info below)
import {Html5Qrcode} from "html5-qrcode"
6 with Qr code scanning initiation.

const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
  cameraId, 
  {
    fps: 10,    // Optional, frame per seconds for qr code scanning
    qrbox: { width: 250, height: 250 }  // Optional, if you want bounded box UI
  },
  (decodedText, decodedResult) => {
    // do something when code is read
  },
  (errorMessage) => {
    // parse error, ignore it.
  })
.catch((err) => {
  // Start failed, handle it.
});

You can optionally set another argument in constructor called

function onScanSuccess(decodedText, decodedResult) {
  // handle the scanned code as you like, for example:
  console.log(`Code matched = ${decodedText}`, decodedResult);
}

function onScanFailure(error) {
  // handle scan failure, usually better to ignore and keep scanning.
  // for example:
  console.warn(`Code scan error = ${error}`);
}

let html5QrcodeScanner = new Html5QrcodeScanner(
  "reader",
  { fps: 10, qrbox: {width: 250, height: 250} },
  /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);
1 to print all logs to console

const html5QrCode = new Html5Qrcode("reader", /* verbose= */ true);

Scanning without cameraId

In mobile devices you may want users to directly scan the QR code using the back camera or the front camera for some use cases. For such cases you can avoid using the exact camera device ID that you get from

// To use Html5QrcodeScanner (more info below)
import {Html5QrcodeScanner} from "html5-qrcode"

// To use Html5Qrcode (more info below)
import {Html5Qrcode} from "html5-qrcode"
5. The
function onScanSuccess(decodedText, decodedResult) {
  // handle the scanned code as you like, for example:
  console.log(`Code matched = ${decodedText}`, decodedResult);
}

function onScanFailure(error) {
  // handle scan failure, usually better to ignore and keep scanning.
  // for example:
  console.warn(`Code scan error = ${error}`);
}

let html5QrcodeScanner = new Html5QrcodeScanner(
  "reader",
  { fps: 10, qrbox: {width: 250, height: 250} },
  /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);
3 method allows passing constraints in place of camera device ID similar to . You can start scanning like mentioned in these examples:

const html5QrCode = new Html5Qrcode("reader");
const qrCodeSuccessCallback = (decodedText, decodedResult) => {
    /* handle success */
};
const config = { fps: 10, qrbox: { width: 250, height: 250 } };

// If you want to prefer front camera
html5QrCode.start({ facingMode: "user" }, config, qrCodeSuccessCallback);

// If you want to prefer back camera
html5QrCode.start({ facingMode: "environment" }, config, qrCodeSuccessCallback);

// Select front camera or fail with `OverconstrainedError`.
html5QrCode.start({ facingMode: { exact: "user"} }, config, qrCodeSuccessCallback);

// Select back camera or fail with `OverconstrainedError`.
html5QrCode.start({ facingMode: { exact: "environment"} }, config, qrCodeSuccessCallback);

Passing the

function onScanSuccess(decodedText, decodedResult) {
  // handle the scanned code as you like, for example:
  console.log(`Code matched = ${decodedText}`, decodedResult);
}

function onScanFailure(error) {
  // handle scan failure, usually better to ignore and keep scanning.
  // for example:
  console.warn(`Code scan error = ${error}`);
}

let html5QrcodeScanner = new Html5QrcodeScanner(
  "reader",
  { fps: 10, qrbox: {width: 250, height: 250} },
  /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);
4 (recommended approach) is similar to

html5QrCode.start({ deviceId: { exact: cameraId} }, config, qrCodeSuccessCallback);

Stop Scanning

To stop using camera and thus stop scanning, call

function onScanSuccess(decodedText, decodedResult) {
  // handle the scanned code as you like, for example:
  console.log(`Code matched = ${decodedText}`, decodedResult);
}

function onScanFailure(error) {
  // handle scan failure, usually better to ignore and keep scanning.
  // for example:
  console.warn(`Code scan error = ${error}`);
}

let html5QrcodeScanner = new Html5QrcodeScanner(
  "reader",
  { fps: 10, qrbox: {width: 250, height: 250} },
  /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);
5 which returns a
// To use Html5QrcodeScanner (more info below)
import {Html5QrcodeScanner} from "html5-qrcode"

// To use Html5Qrcode (more info below)
import {Html5Qrcode} from "html5-qrcode"
6 for stopping the video feed and scanning.

<div id="reader" width="600px"></div>
0

Note that the class is stateful and

function onScanSuccess(decodedText, decodedResult) {
  // handle the scanned code as you like, for example:
  console.log(`Code matched = ${decodedText}`, decodedResult);
}

function onScanFailure(error) {
  // handle scan failure, usually better to ignore and keep scanning.
  // for example:
  console.warn(`Code scan error = ${error}`);
}

let html5QrcodeScanner = new Html5QrcodeScanner(
  "reader",
  { fps: 10, qrbox: {width: 250, height: 250} },
  /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);
7 should be called to properly tear down the video and camera objects safely after calling
function onScanSuccess(decodedText, decodedResult) {
  // handle the scanned code as you like, for example:
  console.log(`Code matched = ${decodedText}`, decodedResult);
}

function onScanFailure(error) {
  // handle scan failure, usually better to ignore and keep scanning.
  // for example:
  console.warn(`Code scan error = ${error}`);
}

let html5QrcodeScanner = new Html5QrcodeScanner(
  "reader",
  { fps: 10, qrbox: {width: 250, height: 250} },
  /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);
3 when the scan is over or the user intend to move on.
function onScanSuccess(decodedText, decodedResult) {
  // handle the scanned code as you like, for example:
  console.log(`Code matched = ${decodedText}`, decodedResult);
}

function onScanFailure(error) {
  // handle scan failure, usually better to ignore and keep scanning.
  // for example:
  console.warn(`Code scan error = ${error}`);
}

let html5QrcodeScanner = new Html5QrcodeScanner(
  "reader",
  { fps: 10, qrbox: {width: 250, height: 250} },
  /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);
7 will stop the video feed on the viewfinder.

For QR Code scanning using local files or inbuilt camera on Smartphones

Selector in AndroidSelector in IOSTaken on Pixel 3, Google Chrome
Taken on iPhone 7, Google Chrome

You can alternatively leverage QR Code scanning for local files on the device or default camera on the device. It works similar to inline QR Code scanning.

Define the HTML container and import the JavaScript library as mentioned above

<div id="reader" width="600px"></div>
1

It's not mandatory to set the height and width of the HTML element. If provided, the library would try to honor it. If it's not set, the library would set a default width and derive the height based on the input image's aspect ratio.

Add an

// This method will trigger user permissions
Html5Qrcode.getCameras().then(devices => {
  /**
   * devices would be an array of objects of type:
   * { id: "id", label: "label" }
   */
  if (devices && devices.length) {
    var cameraId = devices[0].id;
    // .. use this to start scanning.
  }
}).catch(err => {
  // handle err
});
0 element for supporting file selection like this:

<div id="reader" width="600px"></div>
2

Find more information about this at developers.google.com.

And in JavaScript code initialize the object and attach listener like this:

<div id="reader" width="600px"></div>
3

Note that inline scanning and file-based scanning are mutually exclusive at the moment. This means you can only use one of them at a time. I'll soon be adding support for the option to have both if the requirement comes in. If you want to use both, use

// This method will trigger user permissions
Html5Qrcode.getCameras().then(devices => {
  /**
   * devices would be an array of objects of type:
   * { id: "id", label: "label" }
   */
  if (devices && devices.length) {
    var cameraId = devices[0].id;
    // .. use this to start scanning.
  }
}).catch(err => {
  // handle err
});
1 method to clear the canvas.

Demo


Scan this image or visit blog.minhazav.dev/research/html5-qrcode.html

For more information

Check these articles on how to use this library:

  • QR and barcode scanner using HTML and JavaScript
  • HTML5 QR Code scanning — launched v1.0.1 without jQuery dependency and refactored Promise based APIs.
  • HTML5 QR Code scanning with JavaScript — Support for scanning the local file and using default camera added (v1.0.5)

Screenshots


Figure: Screenshot from Google Chrome running on MacBook Pro

Documentation

Following methods are available in this library (typescript definition)

<div id="reader" width="600px"></div>
4

Extra optional // This method will trigger user permissions Html5Qrcode.getCameras().then(devices => { /** * devices would be an array of objects of type: * { id: "id", label: "label" } */ if (devices && devices.length) { var cameraId = devices[0].id; // .. use this to start scanning. } }).catch(err => { // handle err });2 in function onScanSuccess(decodedText, decodedResult) { // handle the scanned code as you like, for example: console.log(`Code matched = ${decodedText}`, decodedResult); } function onScanFailure(error) { // handle scan failure, usually better to ignore and keep scanning. // for example: console.warn(`Code scan error = ${error}`); } let html5QrcodeScanner = new Html5QrcodeScanner( "reader", { fps: 10, qrbox: {width: 250, height: 250} }, /* verbose= */ false); html5QrcodeScanner.render(onScanSuccess, onScanFailure);3 method

Configuration object that can be used to configure both the scanning behavior and the user interface (UI). Most of the fields have default properties that will be used unless a different value is provided. If you do not want to override anything, you can just pass in an empty object

// This method will trigger user permissions
Html5Qrcode.getCameras().then(devices => {
  /**
   * devices would be an array of objects of type:
   * { id: "id", label: "label" }
   */
  if (devices && devices.length) {
    var cameraId = devices[0].id;
    // .. use this to start scanning.
  }
}).catch(err => {
  // handle err
});
4.

// This method will trigger user permissions
Html5Qrcode.getCameras().then(devices => {
  /**
   * devices would be an array of objects of type:
   * { id: "id", label: "label" }
   */
  if (devices && devices.length) {
    var cameraId = devices[0].id;
    // .. use this to start scanning.
  }
}).catch(err => {
  // handle err
});
5 — Integer, Example = 10

A.K.A frame per second, the default value for this is 2, but it can be increased to get faster scanning. Increasing too high value could affect performance. Value

// This method will trigger user permissions
Html5Qrcode.getCameras().then(devices => {
  /**
   * devices would be an array of objects of type:
   * { id: "id", label: "label" }
   */
  if (devices && devices.length) {
    var cameraId = devices[0].id;
    // .. use this to start scanning.
  }
}).catch(err => {
  // handle err
});
6 will simply fail.

// This method will trigger user permissions
Html5Qrcode.getCameras().then(devices => {
  /**
   * devices would be an array of objects of type:
   * { id: "id", label: "label" }
   */
  if (devices && devices.length) {
    var cameraId = devices[0].id;
    // .. use this to start scanning.
  }
}).catch(err => {
  // handle err
});
7 —
// This method will trigger user permissions
Html5Qrcode.getCameras().then(devices => {
  /**
   * devices would be an array of objects of type:
   * { id: "id", label: "label" }
   */
  if (devices && devices.length) {
    var cameraId = devices[0].id;
    // .. use this to start scanning.
  }
}).catch(err => {
  // handle err
});
8 or
// This method will trigger user permissions
Html5Qrcode.getCameras().then(devices => {
  /**
   * devices would be an array of objects of type:
   * { id: "id", label: "label" }
   */
  if (devices && devices.length) {
    var cameraId = devices[0].id;
    // .. use this to start scanning.
  }
}).catch(err => {
  // handle err
});
9 (Optional), Example =
const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
  cameraId, 
  {
    fps: 10,    // Optional, frame per seconds for qr code scanning
    qrbox: { width: 250, height: 250 }  // Optional, if you want bounded box UI
  },
  (decodedText, decodedResult) => {
    // do something when code is read
  },
  (errorMessage) => {
    // parse error, ignore it.
  })
.catch((err) => {
  // Start failed, handle it.
});
0

Use this property to limit the region of the viewfinder you want to use for scanning. The rest of the viewfinder would be shaded. For example, by passing config

const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
  cameraId, 
  {
    fps: 10,    // Optional, frame per seconds for qr code scanning
    qrbox: { width: 250, height: 250 }  // Optional, if you want bounded box UI
  },
  (decodedText, decodedResult) => {
    // do something when code is read
  },
  (errorMessage) => {
    // parse error, ignore it.
  })
.catch((err) => {
  // Start failed, handle it.
});
1, the screen will look like:

This can be used to set a rectangular scanning area with config like:

<div id="reader" width="600px"></div>
5

This config also accepts a function of type

<div id="reader" width="600px"></div>
6

This allows you to set dynamic QR box dimensions based on the video dimensions. See this blog article for example: Setting dynamic QR box size in Html5-qrcode - ScanApp blog

This might be desirable for bar code scanning.

If this value is not set, no shaded QR box will be rendered and the scanner will scan the entire area of video stream.

const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
  cameraId, 
  {
    fps: 10,    // Optional, frame per seconds for qr code scanning
    qrbox: { width: 250, height: 250 }  // Optional, if you want bounded box UI
  },
  (decodedText, decodedResult) => {
    // do something when code is read
  },
  (errorMessage) => {
    // parse error, ignore it.
  })
.catch((err) => {
  // Start failed, handle it.
});
2 — Float, Example 1.777778 for 16:9 aspect ratio

Use this property to render the video feed in a certain aspect ratio. Passing a nonstandard aspect ratio like

const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
  cameraId, 
  {
    fps: 10,    // Optional, frame per seconds for qr code scanning
    qrbox: { width: 250, height: 250 }  // Optional, if you want bounded box UI
  },
  (decodedText, decodedResult) => {
    // do something when code is read
  },
  (errorMessage) => {
    // parse error, ignore it.
  })
.catch((err) => {
  // Start failed, handle it.
});
3 could lead to the video feed not even showing up. Ideal values can be:

ValueAspect RatioUse Case1.3333344:3Standard camera aspect ratio1.77777816:9Full screen, cinematic1.01:1Square view

If you do not pass any value, the whole viewfinder would be used for scanning. Note: this value has to be smaller than the width and height of the

const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
  cameraId, 
  {
    fps: 10,    // Optional, frame per seconds for qr code scanning
    qrbox: { width: 250, height: 250 }  // Optional, if you want bounded box UI
  },
  (decodedText, decodedResult) => {
    // do something when code is read
  },
  (errorMessage) => {
    // parse error, ignore it.
  })
.catch((err) => {
  // Start failed, handle it.
});
4.

const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
  cameraId, 
  {
    fps: 10,    // Optional, frame per seconds for qr code scanning
    qrbox: { width: 250, height: 250 }  // Optional, if you want bounded box UI
  },
  (decodedText, decodedResult) => {
    // do something when code is read
  },
  (errorMessage) => {
    // parse error, ignore it.
  })
.catch((err) => {
  // Start failed, handle it.
});
5 — Boolean (Optional), default = false

By default, the scanner can scan for horizontally flipped QR Codes. This also enables scanning QR code using the front camera on mobile devices which are sometimes mirrored. This is

const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
  cameraId, 
  {
    fps: 10,    // Optional, frame per seconds for qr code scanning
    qrbox: { width: 250, height: 250 }  // Optional, if you want bounded box UI
  },
  (decodedText, decodedResult) => {
    // do something when code is read
  },
  (errorMessage) => {
    // parse error, ignore it.
  })
.catch((err) => {
  // Start failed, handle it.
});
6 by default and I recommend changing this only if:

  • You are sure that the camera feed cannot be mirrored (Horizontally flipped)
  • You are facing performance issues with this enabled.

Here's an example of a normal and mirrored QR Code

Normal QR CodeMirrored QR Code

const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
  cameraId, 
  {
    fps: 10,    // Optional, frame per seconds for qr code scanning
    qrbox: { width: 250, height: 250 }  // Optional, if you want bounded box UI
  },
  (decodedText, decodedResult) => {
    // do something when code is read
  },
  (errorMessage) => {
    // parse error, ignore it.
  })
.catch((err) => {
  // Start failed, handle it.
});
7 — Boolean (Optional), default = true

If

const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
  cameraId, 
  {
    fps: 10,    // Optional, frame per seconds for qr code scanning
    qrbox: { width: 250, height: 250 }  // Optional, if you want bounded box UI
  },
  (decodedText, decodedResult) => {
    // do something when code is read
  },
  (errorMessage) => {
    // parse error, ignore it.
  })
.catch((err) => {
  // Start failed, handle it.
});
8 the last camera used by the user and weather or not permission was granted would be remembered in the local storage. If the user has previously granted permissions — the request permission option in the UI will be skipped and the last selected camera would be launched automatically for scanning.

If

const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
  cameraId, 
  {
    fps: 10,    // Optional, frame per seconds for qr code scanning
    qrbox: { width: 250, height: 250 }  // Optional, if you want bounded box UI
  },
  (decodedText, decodedResult) => {
    // do something when code is read
  },
  (errorMessage) => {
    // parse error, ignore it.
  })
.catch((err) => {
  // Start failed, handle it.
});
8 the library shall remember if the camera permissions were previously granted and what camera was last used. If the permissions is already granted for "camera", QR code scanning will automatically * start for previously used camera.

const html5QrCode = new Html5Qrcode("reader", /* verbose= */ true);
0 -
const html5QrCode = new Html5Qrcode("reader", /* verbose= */ true);
1

This is only supported for

<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
5.

Default =

const html5QrCode = new Html5Qrcode("reader", /* verbose= */ true);
3

This field can be used to:

  • Limit support to either of
    const html5QrCode = new Html5Qrcode("reader", /* verbose= */ true);
    4 or
    const html5QrCode = new Html5Qrcode("reader", /* verbose= */ true);
    5 based scan.
  • Change default scan type.

How to use:

<div id="reader" width="600px"></div>
7

For file based scan only choose:

<div id="reader" width="600px"></div>
8

For supporting both as it is today, you can ignore this field or set as:

<div id="reader" width="600px"></div>
9

To set the file based scan as defult change the order:

<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
0

const html5QrCode = new Html5Qrcode("reader", /* verbose= */ true);
6 -
const html5QrCode = new Html5Qrcode("reader", /* verbose= */ true);
7

This is only supported for

<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
5.

If

const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
  cameraId, 
  {
    fps: 10,    // Optional, frame per seconds for qr code scanning
    qrbox: { width: 250, height: 250 }  // Optional, if you want bounded box UI
  },
  (decodedText, decodedResult) => {
    // do something when code is read
  },
  (errorMessage) => {
    // parse error, ignore it.
  })
.catch((err) => {
  // Start failed, handle it.
});
8 the rendered UI will have button to turn flash on or off based on device + browser support. The value is
const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
  cameraId, 
  {
    fps: 10,    // Optional, frame per seconds for qr code scanning
    qrbox: { width: 250, height: 250 }  // Optional, if you want bounded box UI
  },
  (decodedText, decodedResult) => {
    // do something when code is read
  },
  (errorMessage) => {
    // parse error, ignore it.
  })
.catch((err) => {
  // Start failed, handle it.
});
6 by default.

Scanning only specific formats

By default, both camera stream and image files are scanned against all the supported code formats. Both

<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
5 and
<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
6 classes can be configured to only support a subset of supported formats. Supported formats are defined in .

<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
1

I recommend using this only if you need to explicitly omit support for certain formats or want to reduce the number of scans done per second for performance reasons.

Scanning only QR code with
<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
6

<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
2

Scanning only QR code and UPC codes with
<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
5

<script src="https://unpkg.com/html5-qrcode" type="text/javascript">
3

Experimental features

The library now supports some experimental features which are supported in the library but not recommended for production usage either due to limited testing done or limited compatibility for underlying APIs used. Read more about it here. Some experimental features include:

  • Support for BarcodeDetector JavaScript API

How to modify and build

  1. Code changes should only be made to /src only.

  2. Run

    const html5QrCode = new Html5Qrcode("reader");
    const qrCodeSuccessCallback = (decodedText, decodedResult) => {
        /* handle success */
    };
    const config = { fps: 10, qrbox: { width: 250, height: 250 } };
    
    // If you want to prefer front camera
    html5QrCode.start({ facingMode: "user" }, config, qrCodeSuccessCallback);
    
    // If you want to prefer back camera
    html5QrCode.start({ facingMode: "environment" }, config, qrCodeSuccessCallback);
    
    // Select front camera or fail with `OverconstrainedError`.
    html5QrCode.start({ facingMode: { exact: "user"} }, config, qrCodeSuccessCallback);
    
    // Select back camera or fail with `OverconstrainedError`.
    html5QrCode.start({ facingMode: { exact: "environment"} }, config, qrCodeSuccessCallback);
    5 to install all dependencies.

  3. Run

    const html5QrCode = new Html5Qrcode("reader");
    const qrCodeSuccessCallback = (decodedText, decodedResult) => {
        /* handle success */
    };
    const config = { fps: 10, qrbox: { width: 250, height: 250 } };
    
    // If you want to prefer front camera
    html5QrCode.start({ facingMode: "user" }, config, qrCodeSuccessCallback);
    
    // If you want to prefer back camera
    html5QrCode.start({ facingMode: "environment" }, config, qrCodeSuccessCallback);
    
    // Select front camera or fail with `OverconstrainedError`.
    html5QrCode.start({ facingMode: { exact: "user"} }, config, qrCodeSuccessCallback);
    
    // Select back camera or fail with `OverconstrainedError`.
    html5QrCode.start({ facingMode: { exact: "environment"} }, config, qrCodeSuccessCallback);
    6 to build JavaScript output. The output JavaScript distribution is built to /dist/html5-qrcode.min.js. If you are developing on Windows OS, run
    const html5QrCode = new Html5Qrcode("reader");
    const qrCodeSuccessCallback = (decodedText, decodedResult) => {
        /* handle success */
    };
    const config = { fps: 10, qrbox: { width: 250, height: 250 } };
    
    // If you want to prefer front camera
    html5QrCode.start({ facingMode: "user" }, config, qrCodeSuccessCallback);
    
    // If you want to prefer back camera
    html5QrCode.start({ facingMode: "environment" }, config, qrCodeSuccessCallback);
    
    // Select front camera or fail with `OverconstrainedError`.
    html5QrCode.start({ facingMode: { exact: "user"} }, config, qrCodeSuccessCallback);
    
    // Select back camera or fail with `OverconstrainedError`.
    html5QrCode.start({ facingMode: { exact: "environment"} }, config, qrCodeSuccessCallback);
    7.

  4. Testing

    • Run
      const html5QrCode = new Html5Qrcode("reader");
      const qrCodeSuccessCallback = (decodedText, decodedResult) => {
          /* handle success */
      };
      const config = { fps: 10, qrbox: { width: 250, height: 250 } };
      
      // If you want to prefer front camera
      html5QrCode.start({ facingMode: "user" }, config, qrCodeSuccessCallback);
      
      // If you want to prefer back camera
      html5QrCode.start({ facingMode: "environment" }, config, qrCodeSuccessCallback);
      
      // Select front camera or fail with `OverconstrainedError`.
      html5QrCode.start({ facingMode: { exact: "user"} }, config, qrCodeSuccessCallback);
      
      // Select back camera or fail with `OverconstrainedError`.
      html5QrCode.start({ facingMode: { exact: "environment"} }, config, qrCodeSuccessCallback);
      8
    • Run the tests before sending a pull request, all tests should run.
    • Please add tests for new behaviors sent in PR.
  5. Send a pull request

    • Include code changes only to
      const html5QrCode = new Html5Qrcode("reader");
      const qrCodeSuccessCallback = (decodedText, decodedResult) => {
          /* handle success */
      };
      const config = { fps: 10, qrbox: { width: 250, height: 250 } };
      
      // If you want to prefer front camera
      html5QrCode.start({ facingMode: "user" }, config, qrCodeSuccessCallback);
      
      // If you want to prefer back camera
      html5QrCode.start({ facingMode: "environment" }, config, qrCodeSuccessCallback);
      
      // Select front camera or fail with `OverconstrainedError`.
      html5QrCode.start({ facingMode: { exact: "user"} }, config, qrCodeSuccessCallback);
      
      // Select back camera or fail with `OverconstrainedError`.
      html5QrCode.start({ facingMode: { exact: "environment"} }, config, qrCodeSuccessCallback);
      9. Do not change
      html5QrCode.start({ deviceId: { exact: cameraId} }, config, qrCodeSuccessCallback);
      0 manually.
    • In the pull request add a comment like

    <script src="https://unpkg.com/html5-qrcode" type="text/javascript">
    4

    • For calling out your contributions, the bot will update the contributions file.
    • Code will be built & published by the author in batches.

How to contribute

You can contribute to the project in several ways:

  • File issue ticket for any observed bug or compatibility issue with the project.
  • File feature request for missing features.
  • Take open bugs or feature request and work on it and send a Pull Request.
  • Write unit tests for existing codebase (which is not covered by tests today). Help wanted on this - read more.

Support💖

This project would not be possible without all of our fantastic contributors and sponsors. If you'd like to support the maintenance and upkeep of this project you can donate via GitHub Sponsors.

Sponsor the project for priortising feature requests / bugs relevant to you. (Depends on scope of ask and bandwidth of the contributors).

Gimana cara scan QR code tanpa aplikasi?

Alternatif berikutnya untuk scan QR Code adalah melalui browser Chrome untuk smartphone Android, dan Safari untuk iPhone..
Pertama buka dulu aplikasi browser di ponsel dan akses webqr.com..
Ketuk Allow untuk mengaktifkan kamera ponsel kamu..
Selanjutnya arahkan kamera pada website tadi ke QR Code yang ingin kamu scan..

Bagaimana cara menggunakan aplikasi QR barcode scanner?

Buka aplikasi kamera dari layar utama, pusat kontrol, atau layar terkunci. Pilih kamera belakang. Kemudian arahkan perangkat ke barcode yang hendak dipindai. Setelah itu, perangkat akan secara otomatis memindai kode QR tersebut dan menampilkan pemberitahuan setelah proses pemindaian selesai.

Kenapa scan QR code tidak bisa?

Alasan tidak dapat scan QR code ini bisa jadi disebabkan beberapa hal, seperti koneksi internet yang tidak stabil, menggunakan versi peramban lama, dan lain sebagainya.

QR barcode scanner untuk apa?

Fungsinya adalah memastikan scanner mampu melakukan pembacaan kode secara cepat dan mengetahui orientasi atau posisi kode tersebut.