{"id":17031217,"url":"https://github.com/Dynamsoft/barcode-reader-javascript","last_synced_at":"2025-02-21T11:34:50.846Z","repository":{"id":40471127,"uuid":"145683056","full_name":"Dynamsoft/barcode-reader-javascript","owner":"Dynamsoft","description":"Dynamsoft Barcode Reader JavaScript SDK for package managers. PDF417, QR Code, DataMatrix, MaxiCode and more are supported.","archived":false,"fork":false,"pushed_at":"2024-10-10T10:41:12.000Z","size":137886,"stargazers_count":170,"open_issues_count":9,"forks_count":110,"subscribers_count":14,"default_branch":"main","last_synced_at":"2024-10-12T11:35:09.070Z","etag":null,"topics":["1d-barcode","aztec-code","barcode","barcode-reader","html5-barcode","javascript","javascript-barcode","javascript-qrcode","linear-barcode","npm-package","pdf417","qrcode","sdk","web","web-barcode","webassembly"],"latest_commit_sha":null,"homepage":"https://www.dynamsoft.com/barcode-reader/sdk-javascript/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dynamsoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-22T08:57:56.000Z","updated_at":"2024-10-10T10:40:41.000Z","dependencies_parsed_at":"2024-01-16T10:37:25.397Z","dependency_job_id":"f5411bb3-b8ad-47c0-ae62-f71d275f7ab7","html_url":"https://github.com/Dynamsoft/barcode-reader-javascript","commit_stats":{"total_commits":60,"total_committers":7,"mean_commits":8.571428571428571,"dds":"0.44999999999999996","last_synced_commit":"f8b19e523e7488e47594c5606b50c7a2179d6b37"},"previous_names":["dynamsoft/javascript-barcode","dynamsoft-dbr/javascript-barcode"],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dynamsoft%2Fbarcode-reader-javascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dynamsoft%2Fbarcode-reader-javascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dynamsoft%2Fbarcode-reader-javascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dynamsoft%2Fbarcode-reader-javascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dynamsoft","download_url":"https://codeload.github.com/Dynamsoft/barcode-reader-javascript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219853381,"owners_count":16556199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["1d-barcode","aztec-code","barcode","barcode-reader","html5-barcode","javascript","javascript-barcode","javascript-qrcode","linear-barcode","npm-package","pdf417","qrcode","sdk","web","web-barcode","webassembly"],"created_at":"2024-10-14T08:11:01.753Z","updated_at":"2025-02-21T11:34:50.808Z","avatar_url":"https://github.com/Dynamsoft.png","language":null,"readme":"# Barcode Reader for Your Website - User Guide\n\n[Dynamsoft Barcode Reader JavaScript Edition](https://www.dynamsoft.com/barcode-reader/sdk-javascript/) (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.\n\n![version](https://img.shields.io/npm/v/dynamsoft-barcode-reader.svg)\n![downloads](https://img.shields.io/npm/dm/dynamsoft-barcode-reader.svg)\n![jsdelivr](https://img.shields.io/jsdelivr/npm/hm/dynamsoft-barcode-reader.svg)\n\n![version](https://img.shields.io/npm/v/dynamsoft-javascript-barcode.svg)\n![downloads](https://img.shields.io/npm/dm/dynamsoft-javascript-barcode.svg)\n![jsdelivr](https://img.shields.io/jsdelivr/npm/hm/dynamsoft-javascript-barcode.svg)\n\nOnce 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.\n\nIn this guide, you will learn step by step on how to integrate the DBR-JS SDK into your website.\n\n\u003cspan style=\"font-size:20px\"\u003eTable of Contents\u003c/span\u003e\n\n- [Barcode Reader for Your Website - User Guide](#barcode-reader-for-your-website---user-guide)\n  - [Hello World - Simplest Implementation](#hello-world---simplest-implementation)\n    - [Understand the code](#understand-the-code)\n      - [About the code](#about-the-code)\n    - [Run the example](#run-the-example)\n  - [Preparing the SDK](#preparing-the-sdk)\n    - [Step 1: Include the SDK](#step-1-include-the-sdk)\n      - [Option 1: Use a public CDN](#option-1-use-a-public-cdn)\n      - [Option 2: Host the SDK yourself (optional)](#option-2-host-the-sdk-yourself-optional)\n    - [Step 2: Prepare the SDK](#step-2-prepare-the-sdk)\n      - [1. Specify the license](#1-specify-the-license)\n      - [2. \\[Optional\\] Specify the location of the \"engine\" files](#2-optional-specify-the-location-of-the-engine-files)\n  - [Using the SDK](#using-the-sdk)\n    - [Step 1: Preload the module](#step-1-preload-the-module)\n    - [Step 2: Create a CaptureVisionRouter object](#step-2-create-a-capturevisionrouter-object)\n    - [Step 3: Connect an image source](#step-3-connect-an-image-source)\n    - [Step 4: Register a result receiver](#step-4-register-a-result-receiver)\n    - [Step 5: Start process video frames](#step-5-start-process-video-frames)\n  - [Customizing the process](#customizing-the-process)\n    - [1. Adjust the preset template settings](#1-adjust-the-preset-template-settings)\n      - [1.1. Change barcode settings](#11-change-barcode-settings)\n      - [1.2. Retrieve the original image](#12-retrieve-the-original-image)\n      - [1.3. Change reading frequency to save power](#13-change-reading-frequency-to-save-power)\n      - [1.4. Specify a scan region](#14-specify-a-scan-region)\n    - [2. Edit the preset templates directly](#2-edit-the-preset-templates-directly)\n    - [3. \\[Important\\] Filter the results](#3-important-filter-the-results)\n      - [Method 1: Verify results across multiple frames](#method-1-verify-results-across-multiple-frames)\n      - [Method 2: Eliminate redundant results detected within a short time frame](#method-2-eliminate-redundant-results-detected-within-a-short-time-frame)\n    - [4. Add feedback](#4-add-feedback)\n  - [Customizing the UI](#customizing-the-ui)\n  - [Documentation](#documentation)\n    - [API Reference](#api-reference)\n    - [How to Upgrade](#how-to-upgrade)\n    - [Release Notes](#release-notes)\n  - [Next Steps](#next-steps)\n\n**Popular Examples**\n\n- Hello World - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.31/hello-world/hello-world.html) \\| [Run](https://demo.dynamsoft.com/Samples/DBR/JS/hello-world/hello-world.html?ver=10.4.31\u0026utm_source=github)\n- Angular App - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.31/hello-world/angular)\n- React App - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.31/hello-world/react)\n- Vue App - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.31/hello-world/vue)\n- PWA App - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.31/hello-world/pwa) \\| [Run](https://demo.dynamsoft.com/Samples/DBR/JS/hello-world/pwa/helloworld-pwa.html?ver=10.4.31\u0026utm_source=github)\n- WebView in Android and iOS - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/v10.4.31/hello-world/webview)\n- Read Driver Licenses - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.31/use-case/read-a-drivers-license/index.html) \\| [Run](https://demo.dynamsoft.com/Samples/DBR/JS/use-case/read-a-drivers-license/index.html?ver=10.4.31\u0026utm_source=github)\n- Fill A Form - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.31/use-case/fill-a-form-with-barcode-reading.html) \\| [Run](https://demo.dynamsoft.com/Samples/DBR/JS/use-case/fill-a-form-with-barcode-reading.html?ver=10.4.31\u0026utm_source=github)\n- Show result information on the video - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.31/use-case/show-result-texts-on-the-video.html) \\| [Run](https://demo.dynamsoft.com/Samples/DBR/JS/use-case/show-result-texts-on-the-video.html?ver=10.4.31\u0026utm_source=github)\n- Debug Camera and Collect Video Frame - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.31/others/debug)\n\nYou can also:\n\n- Try the Official Demo - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-demo/) \\| [Run](https://demo.dynamsoft.com/barcode-reader-js/?ver=10.4.31\u0026utm_source=github)\n- Try Online Examples - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/v10.4.31/)\n\n## Hello World - Simplest Implementation\n\nLet'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.  \n\n**Basic Requirements**\n  - Internet connection\n  - A supported browser\n  - Camera access\n\n### Understand the code\n\nThe complete code of the \"Hello World\" example is shown below\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003cbody\u003e\n\u003cdiv id=\"camera-view-container\" style=\"width: 100%; height: 60vh\"\u003e\u003c/div\u003e\n\u003ctextarea id=\"results\" style=\"width: 100%; min-height: 10vh; font-size: 3vmin; overflow: auto\" disabled\u003e\u003c/textarea\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@10.4.3100/dist/dbr.bundle.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  Dynamsoft.License.LicenseManager.initLicense(\"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9\");\n  Dynamsoft.Core.CoreModule.loadWasm([\"dbr\"]);\n  (async () =\u003e {\n    let cvRouter = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();\n\n    let cameraView = await Dynamsoft.DCE.CameraView.createInstance();\n    let cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance(cameraView);\n    document.querySelector(\"#camera-view-container\").append(cameraView.getUIElement());\n    cvRouter.setInput(cameraEnhancer);\n\n    const resultsContainer = document.querySelector(\"#results\");\n    cvRouter.addResultReceiver({ onCapturedResultReceived: (result) =\u003e {\n      if (result.barcodeResultItems?.length) {\n        resultsContainer.textContent = '';\n        for (let item of result.barcodeResultItems) {\n          resultsContainer.textContent += `${item.formatString}: ${item.text}\\n\\n`;\n        }\n      }\n    }});\n\n    let filter = new Dynamsoft.Utility.MultiFrameResultCrossFilter();\n    filter.enableResultCrossVerification(\"barcode\", true);\n    filter.enableResultDeduplication(\"barcode\", true);\n    await cvRouter.addResultFilter(filter);\n\n    await cameraEnhancer.open();\n    await cvRouter.startCapturing(\"ReadSingleBarcode\");\n  })();\n\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n\u003c!--TOM: Update the code links--\u003e\n\n\u003cp align=\"center\" style=\"text-align:center; white-space: normal; \"\u003e\n  \u003ca target=\"_blank\" href=\"https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.31/hello-world/hello-world.html\" title=\"Code in Github\" style=\"text-decoration:none;\"\u003e\n    \u003cimg src=\"https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/github.svg\" alt=\"Code in Github\" width=\"20\" height=\"20\" style=\"width:20px;height:20px;\"\u003e\n  \u003c/a\u003e\n  \u0026nbsp;\n  \u003ca target=\"_blank\" href=\"https://jsfiddle.net/DynamsoftTeam/csm2f9wb/\" title=\"Run via JSFiddle\" style=\"text-decoration:none;\"\u003e\n    \u003cimg src=\"https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/jsfiddle.svg\" alt=\"Run via JSFiddle\" width=\"20\" height=\"20\" style=\"width:20px;height:20px;\" \u003e\n  \u003c/a\u003e\n  \u0026nbsp;\n  \u003ca target=\"_blank\" href=\"https://demo.dynamsoft.com/Samples/DBR/JS/hello-world/hello-world.html?ver=10.4.31\u0026utm_source=github\" title=\"Run in Dynamsoft\" style=\"text-decoration:none;\"\u003e\n    \u003cimg src=\"https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.0.0/svgs/solid/circle-play.svg\" alt=\"Run in Dynamsoft\" width=\"20\" height=\"20\" style=\"width:20px;height:20px;\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003e Don't want to deal with too many details? We also have an **out-of-the-box** version:\n\u003e \n\u003e [Easy Barcode Scanner \u003e\u003e](https://github.com/Dynamsoft/easy-barcode-scanner) available for your reference.\n\u003e ```js\n\u003e // Scan instantly with a single function!\n\u003e let txt = await EasyBarcodeScanner.scan();\n\u003e ```\n\n-----\n\n#### About the code\n\n- `Dynamsoft.License.LicenseManager.initLicense()`: This method initializes the license for using the SDK in the application. Note that the string \"**DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9**\" used in this example points to an online license that requires a network connection to work. Read more on [Specify the license](#specify-the-license).\n\n- `Dynamsoft.Core.CoreModule.loadWasm([\"dbr\"])`: This is an optional code. Used to load wasm resources in advance, reducing latency between video playing and barcode decoding.\n\n- `Dynamsoft.CVR.CaptureVisionRouter.createInstance()`: This method creates a `CaptureVisionRouter` object `cvRouter` which controls the entire process in three steps:\n  - **Retrieve Images from the Image Source**\n    - `cvRouter` connects to the image source through the [ImageSourceAdapter](https://www.dynamsoft.com/capture-vision/docs/core/architecture/input.html#image-source-adapter?lang=js) interface with the method `setInput()`.\n      ```js\n      cvRouter.setInput(cameraEnhancer);\n      ```\n    \u003e The image source in our case is a [CameraEnhancer](https://www.dynamsoft.com/camera-enhancer/docs/web/programming/javascript/user-guide/index.html) object created with `Dynamsoft.DCE.CameraEnhancer.createInstance(cameraView)`\n  - **Coordinate Image-Processing Tasks**\n    - The coordination happens behind the scenes. `cvRouter` starts the process by specifying a preset template \"ReadSingleBarcode\" in the method `startCapturing()`.\n      ```js\n      cvRouter.startCapturing(\"ReadSingleBarcode\");\n      ```\n  - **Dispatch Results to Listening Objects**\n    - The processing results are returned through the [CapturedResultReceiver](https://www.dynamsoft.com/capture-vision/docs/core/architecture/output.html#captured-result-receiver?lang=js) interface. The `CapturedResultReceiver` object is registered to `cvRouter` via the method `addResultReceiver()`. For more information, please check out [Register a result receiver](#register-a-result-receiver).\n      ```js\n      cvRouter.addResultReceiver({/*The-CapturedResultReceiver-Object\"*/});\n      ```\n    - Also note that reading from video is extremely fast and there could be many duplicate results. We can use a [filter](#filter-the-results-important) with result deduplication enabled to filter out the duplicate results. The object is registered to `cvRouter` via the method `addResultFilter()`.\n      ```js\n      cvRouter.addResultFilter(filter);\n      ```\n\n\u003e Read more on [Capture Vision Router](https://www.dynamsoft.com/capture-vision/docs/core/architecture/#capture-vision-router).\n\n### Run the example\n\nYou can run the example deployed to [the Dynamsoft Demo Server](https://demo.dynamsoft.com/Samples/DBR/JS/hello-world/hello-world.html?ver=10.4.31\u0026utm_source=github) or test it with [JSFiddle code editor](https://jsfiddle.net/DynamsoftTeam/csm2f9wb/). \n\nYou 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.\n\nWhen a barcode is decoded, you will see the result text show up under the video and the barcode location will be highlighted in the video feed.\n\nAlternatively, you can test locally by copying and pasting the code shown above into a local file (e.g. \"hello-world.html\") and opening it in your browser.\n\n\u003e *Secure Contexts*:\n\u003e\n\u003e If you open the web page as `http://` , our SDK may not work correctly because the [MediaDevices: getUserMedia()](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) and other methods only work in [secure contexts](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts) (HTTPS, `localhost`, `127.0.0.1`, `file://`), in some or all supporting browsers.\n\u003e\n\u003e Regarding configuring https on your server, these guides for [nginx](https://nginx.org/en/docs/http/configuring_https_servers.html) / [IIS](https://aboutssl.org/how-to-create-a-self-signed-certificate-in-iis/) / [tomcat](https://dzone.com/articles/setting-ssl-tomcat-5-minutes) / [nodejs](https://nodejs.org/docs/v0.4.1/api/tls.html) might help.\n\u003e\n\u003e If the test doesn't go as expected, you can [contact us](https://www.dynamsoft.com/company/contact/?ver=10.4.31\u0026utm_source=github\u0026product=dbr\u0026package=js).\n\n## Preparing the SDK\n\n### Step 1: Include the SDK\n\n#### Option 1: Use a public CDN\n\nThe simplest way to include the SDK is to use either the [jsDelivr](https://jsdelivr.com/) or [UNPKG](https://unpkg.com/) CDN. The \"hello world\" example above uses **jsDelivr**.\n\n- jsDelivr\n\n  ```html\n  \u003cscript src=\"https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@10.4.3100/dist/dbr.bundle.js\"\u003e\u003c/script\u003e\n  ```\n\n- UNPKG\n\n  ```html\n  \u003cscript src=\"https://unpkg.com/dynamsoft-barcode-reader-bundle@10.4.3100/dist/dbr.bundle.js\"\u003e\u003c/script\u003e\n  ```\n\n- In some rare cases (such as some restricted areas), you might not be able to access the CDN. If this happens, you can use the following files for the test.\n\n  ```html\n  \u003cscript src=\"https://download2.dynamsoft.com/packages/dynamsoft-barcode-reader-bundle@10.4.3100/dist/dbr.bundle.js\"\u003e\u003c/script\u003e\n  ```\n\n  However, please **DO NOT** use `download2.dynamsoft.com` resources in a production application as they are for temporary testing purposes only. Instead, you can try hosting the SDK yourself.\n\n- In frameworks like React, Vue and Angular, you may want to add the package as a dependency.\n\n  ```sh\n  npm i dynamsoft-barcode-reader-bundle@10.4.3100 -E\n  # or\n  yarn add dynamsoft-barcode-reader-bundle@10.4.3100 -E\n  ```\n\n  NOTE that in frameworks, you need to [specify the engineResourcePaths](#specify-the-location-of-the-engine-files-optional).\n\n#### Option 2: Host the SDK yourself (optional)\n\nBesides using the public CDN, you can also download the SDK and host its files on your own server or a commercial CDN before including it in your application.\n\n- From the website\n\n  [Download Dynamsoft Barcode Reader JavaScript Package](https://www.dynamsoft.com/barcode-reader/downloads/?ver=10.4.31\u0026utm_source=github\u0026product=dbr\u0026package=js)\n\n  The resources are located at path `dynamsoft/distributables/\u003cpkg\u003e@\u003cversion\u003e`.\n\n- From npm\n\n  ```sh\n  npm i dynamsoft-barcode-reader-bundle@10.4.3100 -E\n  # Compared with using CDN, you need to set up more resources.\n  npm i dynamsoft-capture-vision-std@1.4.21 -E\n  npm i dynamsoft-image-processing@2.4.31 -E\n  ```\n\n  The resources are located at the path `node_modules/\u003cpkg\u003e`, without `@\u003cversion\u003e`. You must copy \"dynamsoft-xxx\" packages elsewhere and add `@\u003cversion\u003e`. The `\u003cversion\u003e` can be obtained from `package.json` of each package. Another thing to do is to [specify the engineResourcePaths](#2-optional-specify-the-location-of-the-engine-files) so that the SDK can correctly locate the resources.\n  \u003e Since \"node_modules\" is reserved for Node.js dependencies, and in our case the package is used only as static resources, we recommend either renaming the \"node_modules\" folder or moving the \"dynamsoft-\" packages to a dedicated folder for static resources in your project to facilitate self-hosting.\n\nYou can typically include SDK like this:\n\n```html\n\u003cscript src=\"path/to/dynamsoft-barcode-reader-bundle@10.4.3100/dist/dbr.bundle.js\"\u003e\u003c/script\u003e\n```\n\n*Note*:\n\n* Certain legacy web application servers may lack support for the `application/wasm` mimetype for .wasm files. To address this, you have two options:\n  1. Upgrade your web application server to one that supports the `application/wasm` mimetype.\n  2. Manually define the mimetype on your server. You can refer to the guides for [apache](https://developer.mozilla.org/en-US/docs/Learn/Server-side/Apache_Configuration_htaccess#media_types_and_character_encodings) / [IIS](https://docs.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/mimemap) / [nginx](https://www.nginx.com/resources/wiki/start/topics/examples/full/#mime-types).\n\n* To work properly, the SDK requires a few engine files, which are relatively large and may take quite a few seconds to download. We recommend that you set a longer cache time for these engine files, to maximize the performance of your web application.\n\n  ```\n  Cache-Control: max-age=31536000\n  ```\n\n  Reference: [Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control).\n\n### Step 2: Prepare the SDK\n\nBefore using the SDK, you need to configure a few things.\n\n#### 1. Specify the license\n\nTo enable the SDK's functionality, you must provide a valid license. Utilize the API function initLicense to set your license key.\n\n```javascript\nDynamsoft.License.LicenseManager.initLicense(\"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9\");\n```\n\nAs previously stated, the key \"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9\" serves as a test license valid for 24 hours, applicable to any newly authorized browser. To test the SDK further, you can request a 30-day free trial license via the \u003ca href=\"https://www.dynamsoft.com/customer/license/trialLicense?ver=10.4.31\u0026utm_source=github\u0026product=dbr\u0026package=js\" target=\"_blank\"\u003eRequest a Trial License\u003c/a\u003e link.\n\n\u003e Upon registering a Dynamsoft account and obtaining the SDK package from the official website, Dynamsoft will automatically create a 30-day free trial license and embed the corresponding license key into all the provided SDK samples.\n\n#### 2. [Optional] Specify the location of the \"engine\" files\n\nThis is usually only required with frameworks like Angular, React or Vue.\n\nThe purpose is to tell the SDK where to find the engine files (\\*.worker.js, \\*.wasm.js and \\*.wasm, etc.).\n\n```ts\n// in framework\nimport { CoreModule } from \"dynamsoft-barcode-reader-bundle\";\nCoreModule.engineResourcePaths.rootDirectory = \"https://cdn.jsdelivr.net/npm/\";\n```\n```js\n// in pure js\nDynamsoft.Core.CoreModule.engineResourcePaths.rootDirectory = \"https://cdn.jsdelivr.net/npm/\";\n```\nThese code uses the jsDelivr CDN as an example, feel free to change it to your own location.\n\n## Using the SDK\n\n### Step 1: Preload the module\n\nThe image processing logic is encapsulated within .wasm library files, and these files may require some time for downloading. To enhance the speed, we advise utilizing the following method to preload the libraries.\n\n```js\n// Preload the .wasm files\nawait Dynamsoft.Core.CoreModule.loadWasm([\"dbr\"]);\n```\n\n### Step 2: Create a CaptureVisionRouter object\n\nTo use the SDK, we first create a `CaptureVisionRouter` object.\n\n```javascript\nDynamsoft.License.LicenseManager.initLicense(\"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9\");\n\nlet cvRouter = null;\ntry {\n    cvRouter = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();\n} catch (ex) {\n    console.error(ex);\n}\n```\n\n*Tip*:\n\nWhen creating a `CaptureVisionRouter` 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 `pCvRouter` in the following code:\n\n```javascript\nDynamsoft.License.LicenseManager.initLicense(\"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9\");\n\nlet pCvRouter = null; // The helper variable which is a promise of cvRouter\nlet cvRouter = null;\n\ndocument.getElementById('btn-scan').addEventListener('click', async () =\u003e {\n    try {\n        cvRouter = await (pCvRouter = pCvRouter || Dynamsoft.CVR.CaptureVisionRouter.createInstance());\n    } catch (ex) {\n        console.error(ex);\n    }\n});\n```\n\n### Step 3: Connect an image source\n\nThe `CaptureVisionRouter` object, denoted as `cvRouter`, is responsible for handling images provided by an image source. In our scenario, we aim to detect barcodes directly from a live video stream. To facilitate this, we initialize a `CameraEnhancer` object, identified as `cameraEnhancer`, which is specifically designed to capture image frames from the video feed and subsequently forward them to `cvRouter`.\n\nTo enable video streaming on the webpage, we create a `CameraView` object referred to as `cameraView`, which is then passed to `cameraEnhancer`, and its content is displayed on the webpage.\n\n```html\n\u003cdiv id=\"camera-view-container\" style=\"width: 100%; height: 100vh\"\u003e\u003c/div\u003e\n```\n\n```javascript\nlet cameraView = await Dynamsoft.DCE.CameraView.createInstance();\nlet cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance(cameraView);\ndocument.querySelector(\"#camera-view-container\").append(cameraView.getUIElement());\ncvRouter.setInput(cameraEnhancer);\n```\n\n### Step 4: Register a result receiver\n\nOnce the image processing is complete, the results are sent to all the registered `CapturedResultReceiver` objects. Each `CapturedResultReceiver` object may encompass one or multiple callback functions associated with various result types. This time we use `onCapturedResultReceived`:\n\u003c!--In our particular case, our focus is on identifying barcodes within the images, so it's sufficient to define the callback function `onDecodedBarcodesReceived`:--\u003e\n\n```javascript\nconst resultsContainer = document.querySelector(\"#results\");\nconst resultReceiver = new Dynamsoft.CVR.CapturedResultReceiver();\nresultReceiver.onCapturedResultReceived = (result) =\u003e {\n  if (result.barcodeResultItems?.length) {\n    resultsContainer.textContent = '';\n    for (let item of result.barcodeResultItems) {\n      // In this example, the barcode results are displayed on the page below the video.\n      resultsContainer.textContent += `${item.formatString}: ${item.text}\\n\\n`;\n    }\n  }\n};\ncvRouter.addResultReceiver(resultReceiver);\n```\n\nYou can also write code like this. It is the same.\n\n```javascript\nconst resultsContainer = document.querySelector(\"#results\");\ncvRouter.addResultReceiver({ onCapturedResultReceived: (result) =\u003e {\n  if (result.barcodeResultItems?.length) {\n    resultsContainer.textContent = '';\n    for (let item of result.barcodeResultItems) {\n      // In this example, the barcode results are displayed on the page below the video.\n      resultsContainer.textContent += `${item.formatString}: ${item.text}\\n\\n`;\n    }\n  }\n}});\n```\n\nCheck out [CapturedResultReceiver](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/capture-vision-router/captured-result-receiver.html) for more information.\n\n### Step 5: Start process video frames\n\nWith the setup now complete, we can proceed to process the images in two straightforward steps:\n\n1. Initiate the image source to commence image acquisition. In our scenario, we invoke the `open()` method on `cameraEnhancer` to initiate video streaming and simultaneously initiate the collection of images. These collected images will be dispatched to `cvRouter` as per its request.\n2. Define a preset template to commence image processing. In our case, we utilize the \"ReadSingleBarcode\" template, specifically tailored for processing images containing a single barcode.\n\n```javascript\nawait cameraEnhancer.open();\nawait cvRouter.startCapturing(\"ReadSingleBarcode\");\n```\n\n*Note*:\n\n* `cvRouter` is engineered to consistently request images from the image source.\n* Various preset templates are at your disposal for barcode reading:\n\n| Template Name                  | Function Description                                           |\n| ------------------------------ | -------------------------------------------------------------- |\n| **ReadBarcodes_Default**       | Scans multiple barcodes by default setting.                    |\n| **ReadSingleBarcode**          | Quickly scans a single barcode.                                |\n| **ReadBarcodes_SpeedFirst**    | Prioritizes speed in scanning multiple barcodes.               |\n| **ReadBarcodes_ReadRateFirst** | Maximizes the number of barcodes read.                         |\n| **ReadBarcodes_Balance**       | Balances speed and quantity in reading multiple barcodes.      |\n| **ReadDenseBarcodes**          | Specialized in reading barcodes with high information density. |\n| **ReadDistantBarcodes**        | Capable of reading barcodes from extended distances.           |\n\nRead more on the [preset CaptureVisionTemplates](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/capture-vision-router/preset-templates.html).\n\n## Customizing the process\n\n### 1. Adjust the preset template settings\n\nWhen making adjustments to some basic tasks, we often only need to modify [SimplifiedCaptureVisionSettings](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/capture-vision-router/interfaces/simplified-capture-vision-settings.html).\n\n#### 1.1. Change barcode settings\n\nThe preset templates can be updated to meet different requirements. For example, the following code limits the barcode format to QR code.\n\n```javascript\nlet settings = await cvRouter.getSimplifiedSettings(\"ReadSingleBarcode\");\nsettings.barcodeSettings.barcodeFormatIds =\n  Dynamsoft.DBR.EnumBarcodeFormat.BF_QR_CODE;\nawait cvRouter.updateSettings(\"ReadSingleBarcode\", settings);\nawait cvRouter.startCapturing(\"ReadSingleBarcode\");\n```\n\nFor a list of adjustable barcode settings, check out [SimplifiedBarcodeReaderSettings](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/interfaces/simplified-barcode-reader-settings.html).\n\n#### 1.2. Retrieve the original image\n\nAdditionally, we have the option to modify the template to retrieve the original image containing the barcode.\n\n```javascript\nlet settings = await cvRouter.getSimplifiedSettings(\"ReadSingleBarcode\");\nsettings.capturedResultItemTypes |= \n  Dynamsoft.Core.EnumCapturedResultItemType.CRIT_ORIGINAL_IMAGE;\nawait cvRouter.updateSettings(\"ReadSingleBarcode\", settings);\nawait cvRouter.startCapturing(\"ReadSingleBarcode\");\n```\n\nLimit the barcode format to QR code, and retrieve the original image containing the barcode, at the same time.\n\n```javascript\nlet settings = await cvRouter.getSimplifiedSettings(\"ReadSingleBarcode\");\nsettings.capturedResultItemTypes = \n  Dynamsoft.DBR.EnumBarcodeFormat.BF_QR_CODE |\n  Dynamsoft.Core.EnumCapturedResultItemType.CRIT_ORIGINAL_IMAGE;\nawait cvRouter.updateSettings(\"ReadSingleBarcode\", settings);\nawait cvRouter.startCapturing(\"ReadSingleBarcode\");\n```\n\nPlease be aware that it is necessary to update the `CapturedResultReceiver` object to obtain the original image. For instance:\n\n```javascript\nconst EnumCRIT = Dynamsoft.Core.EnumCapturedResultItemType;\nresultReceiver.onCapturedResultReceived = (result) =\u003e {\n  if (result.barcodeResultItems?.length) {\n    // Use a filter to get the image on which barcodes are found.\n    let image = result.items.filter(\n      item =\u003e item.type === EnumCRIT.CRIT_ORIGINAL_IMAGE\n    )[0].imageData;\n  }\n};\n```\n\n#### 1.3. Change reading frequency to save power\n\nThe SDK is initially configured to process images sequentially without any breaks. Although this setup maximizes performance, it can lead to elevated power consumption, potentially causing the device to overheat. In many cases, it's possible to reduce the reading speed while still satisfying business requirements. The following code snippet illustrates how to adjust the SDK to process an image every 500 milliseconds:\n\n\u003e Please bear in mind that in the following code, if an image's processing time is shorter than 500 milliseconds, the SDK will wait for the full 500 milliseconds before proceeding to process the next image. Conversely, if an image's processing time exceeds 500 milliseconds, the subsequent image will be processed immediately upon completion.\n\n```javascript\nlet settings = await cvRouter.getSimplifiedSettings(\"ReadSingleBarcode\");\nsettings.minImageCaptureInterval = 500;\nawait cvRouter.updateSettings(\"ReadSingleBarcode\", settings);\nawait cvRouter.startCapturing(\"ReadSingleBarcode\");\n```\n\n#### 1.4. Specify a scan region\n\nWe can specify a scan region to allow the SDK to process only part of the image, improving processing speed. The code snippet below demonstrates how to do this using the `cameraEnhancer` image source.\n\n```javascript\ncameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance(cameraView);\n// In this example, we set the scan region to cover the central 25% of the image.\ncameraEnhancer.setScanRegion({\n  x: 25,\n  y: 25,\n  width: 50,\n  height: 50,\n  isMeasuredInPercentage: true,\n});\n```\n\n*Note*:\n\n1. By configuring the region at the image source, images are cropped before processing, removing the need to adjust any further processing settings.\n2. `cameraEnhancer` enhances interactivity by overlaying a mask on the video, clearly marking the scanning region.\n\n*See Also*:\n\n[CameraEnhancer::setScanRegion](https://www.dynamsoft.com/camera-enhancer/docs/web/programming/javascript/api-reference/acquisition.html#setscanregion)\n\n\u003c!-- Since DCE is always used, no need to use this approach\n\n\nYou can use the parameter `roi` (region of interest) together with the parameter `roiMeasuredInPercentage` to configure the SDK to only read a specific region on the image frames. For example, the following code limits the reading in the center 25%( = 50% * 50%) of the image frames:\n\n```javascript\nlet settings = await cvRouter.getSimplifiedSettings(\"ReadSingleBarcode\");\nsettings.roiMeasuredInPercentage = true;\nsettings.roi.points = [\n  { x: 25, y: 25 },\n  { x: 75, y: 25 },\n  { x: 75, y: 75 },\n  { x: 25, y: 75 },\n];\nawait cvRouter.updateSettings(\"ReadSingleBarcode\", settings);\nawait cvRouter.startCapturing(\"ReadSingleBarcode\");\n``` --\u003e\n\n\n\u003c!--\n* Specify the maximum time allowed for processing each image\n\nYou can set the maximum time allowed for processing a single image with the property `timeout`.\n\n\u003e Please be aware that the SDK will cease processing an image if its processing time exceeds the duration specified by the `timeout` parameter. It should not be confused with the previously discussed parameter, `minImageCaptureInterval`.\n\n```javascript\nlet settings = await cvRouter.getSimplifiedSettings(\"ReadSingleBarcode\");\nsettings.timeout = 500;\nawait cvRouter.updateSettings(\"ReadSingleBarcode\", settings);\nawait cvRouter.startCapturing(\"ReadSingleBarcode\");\n```\n--\u003e\n\n### 2. Edit the preset templates directly\n\nThe preset templates have many more settings that can be customized to suit your use case best. If you [download the SDK from Dynamsoft website](https://www.dynamsoft.com/barcode-reader/downloads/1000003-confirmation/), you can find the templates under\n\n* \"/dynamsoft-barcode-reader-js-10.4.3100/dynamsoft/templates/\"\n\nUpon completing the template editing, you can invoke the `initSettings` method and provide it with the template path as an argument.\n\n```javascript\nawait cvRouter.initSettings(\"PATH-TO-THE-FILE\"); // E.g. \"https://your-website/ReadSingleBarcode.json\")\nawait cvRouter.startCapturing(\"ReadSingleBarcode\"); // Make sure the name matches one of the CaptureVisionTemplates in the template JSON file.\n```\n\n### 3. [Important] Filter the results\n\nWhen processing video frames, the same barcode is often detected multiple times. To improve the user experience, we can use the [MultiFrameResultCrossFilter](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/utility/multi-frame-result-cross-filter.html) object. This object provides two methods for handling duplicate detections, which can be used independently or together, depending on what best suits your application needs:\n\n#### Method 1: Verify results across multiple frames\n\n```js\nlet filter = new Dynamsoft.Utility.MultiFrameResultCrossFilter();\nfilter.enableResultCrossVerification(\"barcode\", true);\nawait cvRouter.addResultFilter(filter);\n```\n\n*Note*:\n\n* `enableResultCrossVerification` was designed to cross-validate the outcomes across various frames in a video streaming scenario, enhancing the reliability of the final results. This validation is particularly crucial for barcodes with limited error correction capabilities, such as 1D codes.\n\n#### Method 2: Eliminate redundant results detected within a short time frame\n\n```js\nlet filter = new Dynamsoft.Utility.MultiFrameResultCrossFilter();\nfilter.enableResultDeduplication(\"barcode\", true);\nawait cvRouter.addResultFilter(filter);\n```\n\n*Note*:\n\n* `enableResultDeduplication` was designed to prevent high usage in video streaming scenarios, addressing the repetitive processing of the same code within a short period of time.\n\nInitially, the filter is set to forget a result 3 seconds after it is first received. During this time frame, if an identical result appears, it is ignored.\n\n\u003e It's important to know that in version 9.x or earlier, the occurrence of an identical result would reset the timer, thus reinitiating the 3-second count at that point. However, in version 10.2.10 and later, an identical result no longer resets the timer but is instead disregarded, and the duration count continues uninterrupted.\n\nUnder certain circumstances, this duration can be extended with the method `setDuplicateForgetTime()`.\n\n```js\nlet filter = new Dynamsoft.Utility.MultiFrameResultCrossFilter();\nfilter.setDuplicateForgetTime(5000); // Extend the duration to 5 seconds.\nawait cvRouter.addResultFilter(filter);\n```\n\nYou can also enable both options at the same time:\n\n```js\nlet filter = new Dynamsoft.Utility.MultiFrameResultCrossFilter();\nfilter.enableResultCrossVerification(\"barcode\", true);\nfilter.enableResultDeduplication(\"barcode\", true);\nfilter.setDuplicateForgetTime(5000);\nawait cvRouter.addResultFilter(filter);\n```\n\n### 4. Add feedback\n\nWhen a barcode is detected within the video stream, its position is immediately displayed within the video. Furthermore, utilizing the \"Dynamsoft Camera Enhancer\" SDK, we can introduce feedback mechanisms, such as emitting a \"beep\" sound or triggering a \"vibration\".\n\nThe following code snippet adds a \"beep\" sound for when a barcode is found:\n\n```js\nconst resultReceiver = new Dynamsoft.CVR.CapturedResultReceiver();\nresultReceiver.onDecodedBarcodesReceived = (result) =\u003e {\n  if (result.barcodeResultItems.length \u003e 0) {\n    Dynamsoft.DCE.Feedback.beep();\n  }\n};\ncvRouter.addResultReceiver(resultReceiver);\n```\n\n## Customizing the UI\n\n```javascript\n// Create a CameraView instance with default settings\nlet cameraView = await Dynamsoft.DCE.CameraView.createInstance();\n// Create a CameraView instance with a specified HTML file path, typically a local or remote URL\nlet cameraView1 = await Dynamsoft.DCE.CameraView.createInstance('@engineResourcePath/dce.mobile-native.ui.html');\n// Create a CameraView instance within a specified DOM element\nlet cameraView2 = await Dynamsoft.DCE.CameraView.createInstance(document.getElementById('my-ui'));\n// Create a CameraView instance using a custom UI file path\nlet cameraView3 = await Dynamsoft.DCE.CameraView.createInstance('url/to/my/ui.html');\n\n// Get the UI element associated with the cameraView instance\nlet uiElement = cameraView.getUIElement();\n// Remove the camera selection dropdown from the CameraView's UI element\nuiElement.shadowRoot.querySelector('.dce-sel-camera').remove();\n// Remove the resolution selection dropdown from the CameraView's UI element\nuiElement.shadowRoot.querySelector('.dce-sel-resolution').remove();\n```\n\nThe UI is part of the auxiliary SDK \"Dynamsoft Camera Enhancer\", read more on how to [customize the UI](https://www.dynamsoft.com/barcode-reader/docs/core/programming/features/ui-customization-js.html?lang=js).\n\n## Documentation\n\n### API Reference\n\nYou can check out the detailed documentation about the APIs of the SDK at\n[https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/?ver=10.4.3100](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/?ver=10.4.3100).\n\n\u003c!--  Compatibility is basically not an issue. Pls remove to another place\n\n## System Requirements\n\nDBR requires the following features to work:\n\n- Secure context (HTTPS deployment)\n\n  When deploying your application / website for production, make sure to serve it via a secure HTTPS connection. This is required for two reasons\n  \n  - Access to the camera video stream is only granted in a security context. Most browsers impose this restriction.\n  \u003e Some browsers like Chrome may grant the access for `http://127.0.0.1` and `http://localhost` or even for pages opened directly from the local disk (`file:///...`). This can be helpful for temporary development and test.\n  \n  - Dynamsoft License requires a secure context to work.\n\n- `WebAssembly`, `Blob`, `URL`/`createObjectURL`, `Web Workers`\n\n  The above four features are required for the SDK to work.\n\n- `MediaDevices`/`getUserMedia`\n\n  This API is required for in-browser video streaming.\n\n- `getSettings`\n\n  This API inspects the video input which is a `MediaStreamTrack` object about its constrainable properties.\n\nThe following table is a list of supported browsers based on the above requirements:\n\n  | Browser Name |     Version      |\n  | :----------: | :--------------: |\n  |    Chrome    | v78+\u003csup\u003e1\u003c/sup\u003e |\n  |   Firefox    | v68+\u003csup\u003e1\u003c/sup\u003e |\n  |     Edge     |       v79+       |\n  |    Safari    |       v14+       |\n\n  \u003csup\u003e1\u003c/sup\u003e devices running iOS needs to be on iOS 14.3+ for camera video streaming to work in Chrome, Firefox or other Apps using webviews.\n\nApart 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.\n\n--\u003e\n\n### How to Upgrade\n\nIf you want to upgrade the SDK from an old version to a newer one, please see [how to upgrade](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/upgrade-guide/index.html?ver=10.4.3100\u0026utm_source=github).\n\n### Release Notes\n\nLearn about what are included in each release at [https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/release-notes/index.html](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/release-notes/index.html?ver=10.4.31\u0026utm_source=github).\n\n## Next Steps\n\nNow that you have got the SDK integrated, you can choose to move forward in the following directions\n\n1. Learn how to [Use in Framework](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/user-guide/use-in-framework.html)\n2. Check out the [Official Samples and Demo](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/samples-demos/index.html?ver=10.4.31)\n3. Learn about the [APIs of the SDK](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/index.html?ver=10.4.3100)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDynamsoft%2Fbarcode-reader-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDynamsoft%2Fbarcode-reader-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDynamsoft%2Fbarcode-reader-javascript/lists"}