scandit-sdk4.2.2 • Public • Published
Scandit Barcode Scanner SDK for the Web
Made by Scandit
Access cameras available on the devices for video input, display a barcode picker interface, configure in-depth settings for barcode symbologies and performance, and let users easily scan barcodes in your web application.
To use this library you must possess a valid Scandit account and license key. You can register for a free trial here.
Table of Contents:
- Getting Started: Web Application
- Getting Started: Local Development
- Example Applications
- Advanced Components and Sample Apps
- Browser Support and Requirements
- Important Notes
- Project Commands
- Versioning and Changelog
- Built With
Getting Started: Web Application
You can use the jsDelivr or UNPKG CDN to easily specify a certain version (range) and include our library as follows (example for
4.2.2: the current version automatically retrieved when specifying a
4.x version; check our latest available library here):
<!-- or -->
npm install scandit-sdk --save
yarn add scandit-sdk
Include as UMD module (this is most probably what you need):
Include as ES module:
Non-minified modules are also available if needed: just include the non-".min" file.
The library will then be accessible via the global
Getting Started: Local Development
npm install scandit-sdk --save
yarn add scandit-sdk
We provide two different bundled versions of the library depending on your needs:
- CommonJS module (with type definitions) -
- ES6 module (with type definitions) -
For reference, you also have the following browser bundles:
The library can be included in your code via either CommonJS or ES imports.
var ScanditSDK = ;
With ES imports it's also possible to use single components. For example:
The first thing that is needed to use the library is to do an initial configuration of the
ScanditSDK object, this is required before any other function of the library can be used.
The configuration function looks as follows:
The first required configuration option is a valid Scandit license key - this is necessary for the library to work and is verified at configuration time. In order to get your license key you must register and login to your account. The key will be available (and configurable) in your personal dashboard and is tied to your website / web application.
The next (often required) optional configuration option is the location of the Scandit Engine library location (external WebAssembly files):
scandit-engine-sdk.wasm. WebAssembly requires these separate files which are loaded by our main library at runtime. They can be found inside the
build folder in the library you either download or access via a CDN; if you download the library, these files should be put in a path that's accessible to be downloaded by the running library script. The configuration option that you provide should then point to the folder containing these files, either as a path of your website or an absolute URL (like the CDN one). By default the library will look at the root of your website. If you use a CDN to access the library, you will want to set this to
"https://unpkg.com/scandit-sdk/build", or similar. Please ensure that the version of the main library that you set up in the "Getting Started" section corresponds to the version of the external Scandit Engine library retrieved via the
engineLocation option, either by ensuring the served files are up-to-date or the path/URL specifies a specific version. In case a common CDN is used here (jsDelivr or UNPKG) the library will automatically internally set up the correct URLs pointing directly at the files needed for the matching library version. It is highly recommended to handle the serving of these files yourself on your website/server, ensuring optimal compression, no request redirections and correct caching headers usage; thus resulting in faster loading.
A configuration call could look as follows:
Note that camera access requests and external Scandit Engine library loads are done lazily only when needed by a
Scanner) object. To make the loading process faster when scanning is actually needed, it is recommended depending on the use case to create in advance a (hidden and paused)
Scanner object, to later simply show and unpause it when needed. You can also eagerly ask only for camera access permissions by calling the
ScanditSDK.CameraAccess.getCameras() function. An example of this advanced usage can be found in the
example_background.html file. More details are also given in the next section.
Once the library has been configured, there are two main ways to interact with it: via the
BarcodePicker object, providing an easy to use high-level UI and API to setup barcode scanning via cameras, or via the
Scanner object, providing only low level methods to process image data.
In order to use the
BarcodePicker, an HTML element must be provided to act as (parent) container for the UI. You can configure size and other styling properties/restrictions by simply setting rules on this element - the picker will fit inside it. A sample element could look as follows:
BarcodePicker can then be created by simply passing the previous HTML element plus optional settings; this will show the UI, access the camera, initialize the Scandit Engine library and start scanning.
By default, no symbology is enabled for recognition so nothing special will happen; we can now quickly set up
ScanSettings to enable wanted symbologies plus other more advanced options if needed (we could also already have done it via the previous constructor). Setting up some sample configuration looks as follows.
var scanSettings =enabledSymbologies: "ean8" "ean13" "upca" "upce" "code128" "code39" "code93" "itf"codeDuplicateFilter: 1000;barcodePicker;// Note that enumeration variables for symbologies are recommended to be used instead (strings are used here for brevity)
The picker is now actively scanning the selected symbologies (detecting the same barcode a maximum of one time per second), if we later want to change the settings we just have to modify the object and apply it again to the picker. In order to react to a successful scan event with your code you can attach one or more listener functions to the picker.
Please refer to the documentation for all the other available configuration options and functions, as well as more advanced
You can have a look at the
example.html file for a (almost) ready to use webpage using the library. A valid license key must be inserted replacing
"YOUR_LICENSE_KEY_IS_NEEDED_HERE"; you then only need to serve the folder containing it for it to run. Note that it depends on the
build folder contents.
You can also find a more advanced sample webpage in the
example_background.html file, showing how to create a
BarcodePicker object which loads the library in the background and how to start/show it at will. This is the recommended way to use the library in many situations.
You can use your own tools, or the following proposed simple way to quickly set up a local server.
Globally install the
npm install http-server -g
yarn global add http-server
Run the new package from the folder containing
Please note that this simple server will not compress files thus resulting in slower loading times than normal.
Finally, access the webpage via your favourite (and supported) browser at
Advanced Components and Sample Apps
For the Angular framework you can use our scandit-sdk-angular component.
For the React framework you can use our scandit-sdk-react component.
You can find online further sample applications making use of this library at https://github.com/Scandit/barcodescanner-sdk-for-web-samples.
Browser Support and Requirements
Due to the advanced features required and some limitations imposed by operating systems, only the browsers listed below are able to correctly use this library.
The following is a list of the main required browser features together with links to updated support statistics:
- Blob - current support?
- URL/createObjectURL - current support?
- Web Workers - current support?
- WebAssembly - current support?
- MediaDevices/getUserMedia - current support? (optional, required for camera video streaming)
This results in the current browser compatibility list:
- Chrome 57+
- Firefox 52+ (except ESR 52)
- Opera 44+
- Safari 11+
- Edge 16+
- Mobile - Android
- Chrome 59+
- Firefox 55+
- Samsung Internet 7+
- Opera 46+
- Mobile - iOS
- Safari 11+
- Chrome 59+ (no camera video streaming)
- Firefox 55+ (no camera video streaming)
You must serve your final web application / website via HTTPS: due to browser security restrictions, camera video streaming access is only granted if that's the case. This is not needed for local IP addresses during development, however note that depending on the browser camera permissions could be asked every time in this case. This does not apply for "single image mode".
WASM file format
Please make sure that your webserver serves the
Content-Type: application/wasm(it should be the default correct MIME type), failure to do so will result in some browsers failing to execute the external library or loading it more slowly.
Cookies for device identification
Our Scandit Engine library makes several different requests at initialization and during usage of the scanning library to our servers, in order to store and provide analytics data about the usage of the SDK. This request/information is the same as what we collect for other SDKs.
A Scandit license key for this particular library is required. The license key is verified at runtime with each library usage and is linked/limited to your specified domain names to prevent abuse. Local addresses and private IPs are also allowed for testing independently from the domain name restriction in a valid license.
On desktop or Android devices, the Chrome browser provides more advanced camera controls and results in better performance than other browsers. At the moment, it is also the only browser to support manual camera focus operations (via tapping the screen) and mobile torch toggling, where available. More browsers are expected to support these advanced features soon.
The performance of the scanner depends on the device and camera being used. Nonetheless for optimal speed/quality, please keep in mind the following guidelines/tips:
- Enable only the symbologies you really need to scan (1D code scanning is usually faster than 2D code scanning, only having 1D codes enabled is faster).
- Only increase the maximum amount of codes per single frame from the default of 1 if it's really needed.
- If possible, restrict the scanning search area to be less than the default full frame.
- Depending on your use case, it might be worth to enable Full HD video quality, resulting in slower frame processing times but higher resolution recognition.
- "Single image mode" internally uses higher quality settings to scan images, this results in slower but much better scanning performance, with the limitation of having to take and provide single pictures from the camera.
- The first "single image mode" scan might be slower than subsequent ones depending on the network condition as the engine has to first verify the license key online before proceeding.
- GPU acceleration allows for faster and more accurate barcode localization at challenging positions and angles but is only available if the browser supports it.
- Blurry code recognition (enabled by default) allows for accurate scanning capabilities for out-of-focus (1D) codes at the expense of more computationally expensive frame analysis: check and adjust scan settings according to your needs.
In order to provide the best possible experience in your web application, please follow these guidelines to guarantee optimal performance of this library:
scandit-engine-sdk.wasmfiles are served compressed, without redirections and with caching headers enabled by your web server. Note that some CDN services do not offer compression or, depending on used settings/URLs, implement redirections that don't allow for correct caching of assets.
- Ensure that the
scandit-engine-sdk.wasmfile is served with the
Content-TypeHTTP header set to
application/wasmto ensure the correct and fast loading of the WebAssembly library component.
BarcodePickerinstances whenever possible by reassigning, hiding and showing them instead of destroying and recreating them: each object needs to load and initialize the external library on creation. Ideally only one instance should be used.
- If possible, create a (hidden and paused)
BarcodePickerin the background and simply resume scanning by switching its visibility to
"show"when needed, instead of creating it on the fly to provide instant scanning capabilities. You can also set it up to not access the camera immediately (
cameraAccessoption set to
falseon creation) and lazily do that later when needed (
BarcodePicker.accessCamera()function call), or also pause and resume camera access when necessary. For a sample application, please refer to the
- Remember to use
destroy()methods on the
- Camera permissions can be asked to the user in advance via this library (background
ScanditSDK.CameraAccess.getCameras()function call) or other external methods to ensure a more fluid experience depending on the situation. Remember that usually these permissions are stored forever and need only to be asked once. As an alternative you can consider "single image mode".
In accordance with our license terms, the Scandit logo displayed in the bottom right corner of the barcode picker must be displayed and cannot be hidden by any method. Workarounds are not allowed.
iOS 11.2.2 / 11.2.5 / 11.2.6 support
Apple released iOS version 11.2.2 on January 8, 2018, as an emergency update meant to mitigate the effects of the widespread Spectre vulnerability. This update also included changes related to WebKit and the Safari browser, as documented here. Unfortunately this update also introduced a critical WebAssembly bug, which caused this and many other libraries relying on this technology to randomly crash and fail to access memory with
Out of bounds memory accessor
None: abort(6)errors on iOS versions 11.2.2, 11.2.5 and 11.2.6. This problem cannot be solved by us or other library developers; the issue has already been reported to Apple by multiple sources and a fix for it has been released in iOS 11.3. We suggest to conditionally use the library or show alerts to the affected users by utilizing the OS version information available in the browser via the user agent string.
An updated in-depth documentation of all of the libraries' specifications and functionalities can be generated/found in the
docs folder or can also be accessed online at https://docs.scandit.com/stable/web.
How big is the library?
The main library is currently about 89kB (minified, gzipped), while the external Scandit Engine library is around 42kB + 923kB (JS + WASM, gzipped). Keep in mind that you will not need to wait for these files to download to display your webpage / web application, they can be downloaded and prepared in the background without affecting the rest of the application (the Scandit Engine library is also always automatically downloaded and prepared asynchronously in a separate thread). On browsers supporting caching of WebAssembly data (currently Firefox and Edge) the external Scandit Engine library WASM file can be pre-parsed and cached to be reused for subsequent loads.
Why is only Safari fully supported on iOS?
This is (for now) a limitation imposed by Apple, which doesn't yet allow any external browser using WKWebView from accessing device cameras for video streaming, see this discussion. As an alternative/workaround, "single image mode" can be used to scan pictures in other browsers on this platform.
How well are barcodes recognized?
This obviously depends from the specifics of the camera being used, but in general the performance of this library is only slightly inferior to what is provided by Scandit's native SDKs. Currently it's not possible on all major browsers to (efficiently) use WebGL instructions inside WebWorkers, meaning that advanced GPU control and functions provided to our library can be limited. The situation will improve over time as more of the features present in the native SDK are implemented/enabled and as browsers allow more control over the GPU and camera.
Does the library require network access?
The scanning of barcodes doesn't require network access and is executed completely on the client in the browser. Our engine however needs network access at configuration time to verify license keys and will also attempt to send additional requests afterwards for data analytics purposes (linked to your license key).
Why can I sometimes see "Intervention" messages about blocked vibrate calls in the browser's debugger?
Why does my BarcodePicker/Scanner not work/start?
Please ensure that you correctly configured the library via the
ScanditSDK.configurefunction call before using the objects provided. More specifically check that in its arguments:
- You provided a valid license key (any domain name restriction will work for local testing).
- You configured the
engineLocationsetting appropriately for your folder/deployment structure.
Why do I randomly get "Out of bounds memory access" or "None: abort(6)" errors?
This is caused by a iOS 11.2.2 / 11.2.5 / 11.2.6 Safari browser, due to WebKit memory access problems introduced by this specific iOS versions by Apple, as indicated in the Important Notes section. This is unfortunately out of our control, but a fix for it has already been released by Apple in iOS version 11.3.
Why do I keep getting asked for camera access permissions?
Each browser has slightly different privacy rules for the situations in which to ask the user for access to their camera feed. Nonetheless all browsers usually let users store ("remember") their permissions for each website or web application, so that these permissions don't need to be asked again. In order to ensure permissions are stored correctly in any situation, your website / web application should be served via HTTPS.
How does "single image mode" work?
This mode is meant as an alternative/fallback mode for a
BarcodePickerto provide single camera pictures to be scanned. It still performs all operations locally in the browser, but trades off continuous camera stream access for (more high quality) single snapshot scanning; this results in less browser features needed for the library to work and extended browser support. In "single image mode" a specially set UI is provided which enables users to click/tap to directly take a picture with the camera (mobile/tablet) or upload a file (desktop), this picture is then scanned and the results are provided. In this mode special camera access permissions don't have to be requested.
Why does Safari use more and more memory until it crashes, causing the page to reload with the error "A problem occurred with this webpage so it was reloaded"?
Why can't I access the camera in full HD resolution in Safari?
The Safari browser currently provides limited support to access audio and video media devices via standard web technologies (WebRTC): the available maximum resolution seems to be capped at 1280x720. This is unfortunately out of our control, but we expect Apple to improve these and other related features of its browser soon.
If you want to work on this project, the following is a list of the most useful Yarn commands you can run in this project (here shown with Yarn).
You should use
yarn instead of
npm to handle project dependencies to make use of the existing
Start developing (watch task for build and tests):
Build and create all output modules:
Lint with type checking:
Run unit tests and check coverage:
Show all available commands:
Versioning and Changelog
- TypeScript Starter
- Lorenzo Wölckner (Scandit)
This project is licensed under a custom license - see the LICENSE file for details (also found inside the project).