Barcode Reader for Your Website - User Guide

Dynamsoft Barcode Reader JavaScript Edition (DBR-JS) is equipped with industry-leading algorithms for exceptional speed, accuracy and read rates in barcode reading. Using its well-designed API, you can turn your web page into a barcode scanner with just a few lines of code.

version downloads jsdelivr vulnerabilities

Once the DBR-JS SDK gets integrated into your web page, your users can access a camera via the browser and read barcodes directly from its video input.

In this guide, you will learn step by step on how to integrate the DBR-JS SDK into your website.

Table of Contents

Popular Examples

You can also:

Hello World - Simplest Implementation

Let's start with the "Hello World" example of the DBR-JS SDK which demonstrates how to use the minimum code to enable a web page to read barcodes from a live video stream.

Understand the code

The complete code of the "Hello World" example is shown below

Code in Github   Run via JSFiddle   Run in Dynamsoft


About the code

Run the example

You can run the example deployed to the Dynamsoft Demo Server or test it with JSFiddle code editor. You will be asked to allow access to your camera, after which the video will be displayed on the page. After that, you can point the camera at a barcode to read it.

When a barcode is decoded, you will see the result text pop up and the barcode location will be highlighted in the video feed.

Alternatively, you can make a local test simply by taking the code in step 1, pasting it in a file with the name "hello-world.html" and open it in a browser.

Note:

If you open the web page as file:/// or http:// , the camera may not work correctly because the API getUserMedia usually requires HTTPS to access the camera.

To make sure your web application can access the camera, please configure your web server to support HTTPS. The following links may help.

  1. NGINX: Configuring HTTPS servers
  2. IIS: Create a Self Signed Certificate in IIS
  3. Tomcat: Setting Up SSL on Tomcat in 5 minutes
  4. Node.js: npm tls

If the test doesn't go as expected, you can contact us.

Building your own page

Include the SDK

Use a CDN

The simplest way to include the SDK is to use either the jsDelivr or UNPKG CDN. The "hello world" example above uses jsDelivr.

Host the SDK yourself

Besides using the CDN, you can also download the SDK and host its files on your own website / server before including it in your application.

Options to download the SDK:

Depending on how you downloaded the SDK and how you intend to use it, you can typically include it like this:

or

or

Configure the SDK

Before using the SDK, you need to configure a few things.

Specify the license

The SDK requires a license to work, use the API license to specify a license key.

To test the SDK, you can request a 30-day trial license via the customer portal.

If you registered a Dynamsoft account and downloaded the SDK from the official website, Dynamsoft will automatically generate a 30-day trial license for you and put the license key into all the samples that come with the SDK.

Specify the location of the "engine" files

This is usually only required with frameworks like Angular or React, etc. where dbr.js is compiled into another file.

The purpose is to tell the SDK where to find the engine files (*.worker.js, *.wasm.js and *.wasm, etc.). The API is called engineResourcePath:

Interact with the SDK

Create a BarcodeScanner object

You can use one of two classes ( BarcodeScanner and BarcodeReader ) to interact with the SDK. BarcodeReader is a low-level class that processes images directly. BarcodeScanner , on the other hand, inherits from BarcodeReader and provides high-level APIs and a built-in GUI to allow continuous barcode scanning on video frames. We'll focus on BarcodeScanner in this guide.

To use the SDK, we first create a BarcodeScanner object.

Tip: When creating a BarcodeScanner object within a function which may be called more than once, it's best to use a "helper" variable to avoid double creation such as pScanner in the following code

Customize the BarcodeScanner Settings (optional)

Let's take a look at the following code snippets:

Try in JSFiddle

As you can see from the above code snippets, there are three types of configurations:

Find the full list of the runtime settings here.

Customize the UI (optional)

The built-in UI of the BarcodeScanner object is defined in the file dist/dbr.ui.html . There are a few ways to customize it:

API Documentation

You can check out the detailed documentation about the APIs of the SDK at https://www.dynamsoft.com/barcode-reader/programming/javascript/api-reference/?ver=9.3.1.

System Requirements

DBR requires the following features to work:

The following table is a list of supported browsers based on the above requirements:

Browser NameVersion
Chromev59+1
Firefoxv52+ (v55+ on Android/iOS1)
Edge2v16+
Safari3v11+

1 iOS 14.3+ is required for camera video streaming in Chrome and Firefox or Apps using webviews.

2 On Edge, due to strict Same-origin policy, you must host the SDK files on the same domain as your web page.

3 Safari v11.x already has the required features, but it has many other issues, so we recommend v12+.

Apart from the browsers, the operating systems may impose some limitations of their own that could restrict the use of the SDK. Browser compatibility ultimately depends on whether the browser on that particular operating system supports the features listed above.

How to Upgrade

If you want to upgrade the SDK from an old version to a newer one, please see how to upgrade.

Release Notes

Learn about what are included in each release at https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/release-notes/?ver=latest.

Next Steps

Now that you have got the SDK integrated, you can choose to move forward in the following directions

  1. Check out the Official Samples and Demo
  2. Learn how to make use of the SDK features
  3. See how the SDK works in Popular Use Cases