<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Josh Salbury</title>
    <description>The latest articles on Forem by Josh Salbury (@astrodog-joshh).</description>
    <link>https://forem.com/astrodog-joshh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2605144%2F211ee488-f2ba-4702-b0e4-fcd3c0b4b403.jpg</url>
      <title>Forem: Josh Salbury</title>
      <link>https://forem.com/astrodog-joshh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/astrodog-joshh"/>
    <language>en</language>
    <item>
      <title>Tutorial React Barcode Scanner with TypeScript</title>
      <dc:creator>Josh Salbury</dc:creator>
      <pubDate>Wed, 02 Apr 2025 12:34:54 +0000</pubDate>
      <link>https://forem.com/astrodog-joshh/tutorial-react-barcode-scanner-with-typescript-58jc</link>
      <guid>https://forem.com/astrodog-joshh/tutorial-react-barcode-scanner-with-typescript-58jc</guid>
      <description>&lt;p&gt;Sharing a video tutorial with you on how to build a React barcode scanner web application using TypeScript, Vite, and the Scanbot Web SDK. &lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/AMnaKOIa3zM"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;For those who'd like going through the code snippets step by step, I'll link the written guide with code snippets &lt;a href="https://scanbot.io/techblog/react-barcode-reader-tutorial/?utm_source=dev.to&amp;amp;utm_medium=social&amp;amp;utm_campaign=&amp;amp;utm_content=44"&gt;here&lt;/a&gt;. Looking forward to your feedback! &lt;/p&gt;

</description>
      <category>typescript</category>
      <category>vite</category>
      <category>react</category>
    </item>
    <item>
      <title>How to use QuaggaJS – a barcode scanner example for your website or web app</title>
      <dc:creator>Josh Salbury</dc:creator>
      <pubDate>Thu, 06 Feb 2025 11:05:40 +0000</pubDate>
      <link>https://forem.com/astrodog-joshh/how-to-use-quaggajs-a-barcode-scanner-example-for-your-website-or-web-app-3omc</link>
      <guid>https://forem.com/astrodog-joshh/how-to-use-quaggajs-a-barcode-scanner-example-for-your-website-or-web-app-3omc</guid>
      <description>&lt;p&gt;QuaggaJS is a popular open-source barcode scanner written in JavaScript that locates and decodes various 1D barcode symbologies in the user’s camera stream.&lt;/p&gt;

&lt;p&gt;While the &lt;a href="https://github.com/serratus/quaggaJS" rel="noopener noreferrer"&gt;original project&lt;/a&gt; is no longer maintained, it lives on as &lt;a href="https://github.com/ericblade/quagga2" rel="noopener noreferrer"&gt;Quagga2&lt;/a&gt;, which is what we’ll be using in our tutorial.&lt;/p&gt;

&lt;p&gt;Since Quagga is a JavaScript-only library, it is easy to integrate into any website or web app. In this tutorial, we’ll show you how to set up the barcode scanner in a single HTML file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Setting up the HTML file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s start by creating the basic structure of the HTML document:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8"/&amp;gt;
    &amp;lt;title&amp;gt;QuaggaJS&amp;lt;/title&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡 The line &lt;code&gt;&amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/&amp;gt;&lt;/code&gt; ensures that the page fits the device’s resolution and that users cannot zoom into it.&lt;/p&gt;

&lt;p&gt;The first thing we’ll put into the body is a &lt;code&gt;div&lt;/code&gt; into which we’ll later render the camera stream:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;div id="camera"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Configuring Quagga&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, we’ll add Quagga itself. We’re including the &lt;code&gt;quagga.min.js&lt;/code&gt; script from jsDelivr, but you can of course also host the script on your own web server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;div id="camera"&amp;gt;&amp;lt;/div&amp;gt;
    // new
    &amp;lt;script src="https://cdn.jsdelivr.net/npm/@ericblade/quagga2/dist/quagga.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we need to configure QuaggaJS. First, we have to specify the DOM element where the video stream will be displayed. Next, we also need to specify the barcode decoders we want to use.&lt;/p&gt;

&lt;p&gt;To accomplish the first part, we create a config object, which we will call &lt;code&gt;quaggaConf&lt;/code&gt;. We use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector" rel="noopener noreferrer"&gt;document.querySelector&lt;/a&gt; to select the &lt;code&gt;div&lt;/code&gt; we created above as the target where the video stream will be displayed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
    const quaggaConf = {
        inputStream: {
            target: document.querySelector("#camera")
        }
    }
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we specify which barcode symbologies our QuaggaJS app will read (to optimize performance, it’s recommended to only include those you expect to scan). In this tutorial, we’ll be sticking to the common barcode type Code 128. You can find a list of all supported symbologies in the &lt;a href="https://github.com/ericblade/quagga2?tab=readme-ov-file#decoder" rel="noopener noreferrer"&gt;Quagga2 GitHub repository&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
    const quaggaConf = {
        inputStream: {
            target: document.querySelector("#camera"),
        },
        // new
        decoder: {
            readers: ['code_128_reader']
        },
    }
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step is to prepare the initialization function. We provide our Quagga configuration and an error handler. If the initialization is successful, &lt;code&gt;Quagga.start()&lt;/code&gt; will begin the barcode scanning process.&lt;/p&gt;

&lt;p&gt;We have also added a function to display an alert with the barcode result when a barcode is detected and read.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
    const quaggaConf = {
        inputStream: {
            target: document.querySelector("#camera"),
        },
        decoder: {
            readers: ['code_128_reader']
        },
    }

    // new
    Quagga.init(quaggaConf, function (err) {
        if (err) {
            return console.log(err);
        }
        Quagga.start();
    });

    Quagga.onDetected(function (result) {
        alert("Detected barcode: " + result.codeResult.code);
    });
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Configuring the video stream&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we’ll add &lt;code&gt;LiveStream&lt;/code&gt; as the input stream type, since we want to process and display the live video as captured by the user’s camera. Other possible values for the stream type are described in the &lt;a href="https://github.com/ericblade/quagga2?tab=readme-ov-file#inputstream" rel="noopener noreferrer"&gt;Quagga docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We’ll also have to define the constraints for the video stream. To do that, we need to specify the width, height, aspect ratio, and camera for the input stream.&lt;/p&gt;

&lt;p&gt;💡 A lower resolution will result in faster scanning speeds at the cost of accuracy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
    const quaggaConf = {
        inputStream: {
            target: document.querySelector("#camera"),
            // new
            type: "LiveStream",
            constraints: {
                width: { min: 640 },
                height: { min: 480 },
                facingMode: "environment",
                aspectRatio: { min: 1, max: 2 }
            }
        },
        decoder: {
            readers: ['code_128_reader']
        },
    }

    Quagga.init(quaggaConf, function (err) {
        if (err) {
            return console.log(err);
        }
        Quagga.start();
    });

    Quagga.onDetected(function (result) {
        alert("Detected barcode: " + result.codeResult.code);
    });
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we add some styling to display the video in the resolution we requested from the camera to ensure it fits the screen.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8"/&amp;gt;
    &amp;lt;title&amp;gt;QuaggaJS&amp;lt;/title&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/&amp;gt;
    // new
    &amp;lt;style&amp;gt;
        #camera video{
            width:100%;
            max-width: 640px;
        }
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly, we’re going to apply a &lt;code&gt;style&lt;/code&gt; attribute to our camera &lt;code&gt;div&lt;/code&gt; to make it take up the entire width of the body.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;div id="camera" style="width:100%"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we’re done! 🎉&lt;/p&gt;

&lt;p&gt;The final result looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8"/&amp;gt;
    &amp;lt;title&amp;gt;QuaggaJS&amp;lt;/title&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/&amp;gt;
    &amp;lt;style&amp;gt;
        #camera video{
            width:100%;
            max-width: 640px;
        }
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
&amp;lt;div id="camera" style="width:100%"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;script src="https://cdn.jsdelivr.net/npm/@ericblade/quagga2/dist/quagga.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;
    const quaggaConf = {
        inputStream: {
            target: document.querySelector("#camera"),
            type: "LiveStream",
            constraints: {
                width: { min: 640 },
                height: { min: 480 },
                facingMode: "environment",
                aspectRatio: { min: 1, max: 2 }
            }
        },
        decoder: {
            readers: ['code_128_reader']
        },
    }

    Quagga.init(quaggaConf, function (err) {
        if (err) {
            return console.log(err);
        }
        Quagga.start();
    });

    Quagga.onDetected(function (result) {
        alert("Detected barcode: " + result.codeResult.code);
    });
&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try scanning a Code 128 to see if everything works as intended.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fardf3mjx7q02n725i1l6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fardf3mjx7q02n725i1l6.png" alt="Image description" width="312" height="145"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Drawbacks of using QuaggaJS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As impressive as this JavaScript-based barcode scanner implementation is, QuaggaJS does have its disadvantages.&lt;/p&gt;

&lt;p&gt;The biggest drawback is that it only supports 1D barcodes. Two-dimensional symbologies like QR Code, Data Matrix, and Aztec encode much more data while taking up less space, which makes them a valuable alternative to their one-dimensional counterparts.&lt;/p&gt;

&lt;p&gt;As useful as it is to have a barcode scanner written in JavaScript, the performance of the detection algorithm would also benefit from an implementation in WebAssembly. Especially on low-end devices, this could result in increased scanning speeds.&lt;/p&gt;

&lt;p&gt;Quagga’s feature set is also not on par with that of &lt;a href="https://docs.scanbot.io/barcode-scanner-sdk/web/barcode-scanner/use-cases/?_gl=1*y1fge3*_gcl_au*MTM5NzA2NjMzMS4xNzMzNDc3NjE1LjExNDQ1NTk3MDcuMTczNDcwMzkxMi4xNzM0NzAzOTEy*FPAU*MzQ1MzE3MTE0LjE3MzMzOTYwMjM.*_ga*MzQ3MzMwMTU2LjE3MzM0Nzc2MTQ.*_ga_4ZZ821ELNM*MTczODgzMzE2NS4xMDcuMS4xNzM4ODM3MjUxLjAuMC4zNTY3NDE4NjU." rel="noopener noreferrer"&gt;professional solutions&lt;/a&gt;. Enterprise-grade barcode scanner software often includes dedicated modules for scanning many barcodes simultaneously or in rapid succession, as well as UI elements, all of which this open-source solution lacks.&lt;/p&gt;

&lt;p&gt;If you plan to use Quagga in production, you should also keep in mind that you will depend entirely on the open-source community for its maintenance and for support. If you run into a problem, you might have to find a solution on your own.&lt;/p&gt;

&lt;p&gt;For companies that heavily rely on barcode scanning in their business processes, we recommend using an enterprise-grade solution instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementing a JavaScript-based barcode scanner with the Scanbot SDK&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We developed the &lt;a href="https://scanbot.io/barcode-scanner-sdk/?utm_source=dev.to&amp;amp;utm_medium=social&amp;amp;utm_campaign=&amp;amp;utm_content=7"&gt;Scanbot Barcode Scanner SDK&lt;/a&gt; to help enterprises overcome the hurdles presented by free barcode scanning software. Our goal was to have a developer-friendly solution available for a wide range of platforms that consistently delivers high-quality results – even in challenging circumstances.\&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7a5vld5szh0xoj43xukn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7a5vld5szh0xoj43xukn.jpg" alt="QR Code Example" width="320" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scan the QR code or follow this link to try the &lt;a href="https://websdk-barcode.scanbot.io/?_gl=1*8hnm64*_gcl_au*MTM5NzA2NjMzMS4xNzMzNDc3NjE1LjExNDQ1NTk3MDcuMTczNDcwMzkxMi4xNzM0NzAzOTEy*FPAU*MzQ1MzE3MTE0LjE3MzMzOTYwMjM.*_ga*MzQ3MzMwMTU2LjE3MzM0Nzc2MTQ.*_ga_4ZZ821ELNM*MTczODgzMzE2NS4xMDcuMS4xNzM4ODM3NDMwLjYwLjAuMzU2NzQxODY1#/onboarding" rel="noopener noreferrer"&gt;Web Barcode Scanner Demo&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;In the following section, we’ll show you how easy it is to integrate our Web Barcode Scanner SDK into your JavaScript app. Thanks to our SDK’s &lt;strong&gt;Ready-to-Use UI Components&lt;/strong&gt;, you can even use an AR overlay to display multiple barcodes’ contents right in the viewfinder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fke0z208wwh1j7kva6wzu.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fke0z208wwh1j7kva6wzu.gif" alt="Image description" width="351" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To accomplish that, we’ll need to follow the steps below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download the SDK files&lt;/li&gt;
&lt;li&gt;Create the HTML page and configure the Web SDK&lt;/li&gt;
&lt;li&gt;Start a local HTTP server&lt;/li&gt;
&lt;li&gt;Start scanning&lt;/li&gt;
&lt;li&gt;Configure styling and scanning behavior&lt;/li&gt;
&lt;li&gt;Deploy to a server (optional)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s dive into more details for each step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Download the SDK&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, create a new empty directory for your app and name it &lt;strong&gt;my-scanner-app&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Then, download the Scanbot SDK &lt;strong&gt;npm package&lt;/strong&gt; directly from &lt;a href="https://registry.npmjs.org/scanbot-web-sdk/-/scanbot-web-sdk-5.1.0.tgz" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;💡 As specified in our &lt;a href="https://docs.scanbot.io/barcode-scanner-sdk/web/getting-started/?_gl=1*1f6kj0p*_gcl_au*MTM5NzA2NjMzMS4xNzMzNDc3NjE1LjExNDQ1NTk3MDcuMTczNDcwMzkxMi4xNzM0NzAzOTEy*FPAU*MzQ1MzE3MTE0LjE3MzMzOTYwMjM.*_ga*MzQ3MzMwMTU2LjE3MzM0Nzc2MTQ.*_ga_4ZZ821ELNM*MTczODgzMzE2NS4xMDcuMS4xNzM4ODM4MDM2LjAuMC4zNTY3NDE4NjU.?utm_source=dev.to&amp;amp;utm_medium=social&amp;amp;utm_campaign=&amp;amp;utm_content=8"&gt;documentation&lt;/a&gt;, you can also use npm install to download and install the package, but for this tutorial, we suggest manually downloading it and installing it from the link provided.&lt;/p&gt;

&lt;p&gt;Unzip the downloaded files into my-scanner-app. Your folder structure should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-scanner-app/
  |- scanbot-web-sdk/
    |- webpack/
    |- bundle/
    |- @types/
    |- index.js
    |- ui.js
    ... (and some other files)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⚠️ Make sure the folder containing the package files is called &lt;strong&gt;scanbot-web-sdk&lt;/strong&gt;, not “package” or similiar.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Create the HTML page and configure the Web SDK&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To create the HTML with the Scanbot SDK, first create an &lt;strong&gt;index.html&lt;/strong&gt; file in the &lt;strong&gt;my-scanner-app/&lt;/strong&gt; folder. Then, add the following code to the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;!-- We prevent the user from zooming on mobile device --&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" /&amp;gt;
    &amp;lt;title&amp;gt;My Scanner App&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body style="margin: 0"&amp;gt;
&amp;lt;button id="start-scanning"&amp;gt;Start scanning&amp;lt;/button&amp;gt;
&amp;lt;pre id="result"&amp;gt;&amp;lt;/pre&amp;gt;
&amp;lt;script type="module"&amp;gt;
    // We import the necessary ScanbotSDK module
    import "./scanbot-web-sdk/bundle/ScanbotSDK.ui2.min.js";
    // When initializing the SDK, we specify the path to the barcode scanner engine
    const sdk = await ScanbotSDK.initialize({
        engine: "scanbot-web-sdk/bundle/bin/barcode-scanner/"
    });
    document.getElementById("start-scanning").addEventListener("click", async () =&amp;gt; {
        // We create a new default configuration for the barcode scanner
        const config = new ScanbotSDK.UI.Config.BarcodeScannerConfiguration();
        // We create a barcode scanner UI component
        const scanResult = await ScanbotSDK.UI.createBarcodeScanner(config);
        // Once the scanning is done, we display the result
        if (scanResult?.items?.length &amp;gt; 0) {
            document.getElementById("result").innerText =
                `Barcode type: ${scanResult.items[0].type} \n` +
                `Barcode content: "${scanResult.items[0].text}" \n`;
        } else {
            document.getElementById("result").innerText = "Scanning aborted by the user";
        }
    });
&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code block above:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adds the “Start scanning” button.&lt;/li&gt;
&lt;li&gt;Imports and initializes the Scanbot SDK.&lt;/li&gt;
&lt;li&gt;Executes the user interface from the Scanbot SDK when the user clicks the “Start scanning” button.&lt;/li&gt;
&lt;li&gt;If a barcode is identified, it will present the barcode type and its content to the user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Start local HTTP server&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Scanbot SDK uses advanced browser features that are unavailable when opening our site via a file URL. Therefore, a local HTTP server is required to view the site.&lt;/p&gt;

&lt;p&gt;There are two main ways to run the index.js file in a localhost server: using &lt;strong&gt;Python&lt;/strong&gt; or &lt;strong&gt;Node.js&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you have &lt;strong&gt;Python&lt;/strong&gt; installed, you can use it to start a local HTTP server. To do so, follow the steps below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open a terminal in the &lt;strong&gt;my-scanner-app/&lt;/strong&gt; folder.&lt;/li&gt;
&lt;li&gt;Use the command  &lt;code&gt;python3 -m http.server&lt;/code&gt; to start a local test server. &lt;/li&gt;
&lt;li&gt;Now, you can access it on your browser at &lt;code&gt;http://localhost:8000&lt;/code&gt;. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To stop running the localhost server, press &lt;strong&gt;Ctrl+C&lt;/strong&gt; on the terminal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Node.js&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;Node.js&lt;/strong&gt; is installed, you can use the npm serve package to start a local HTTP server. To do so, follow the steps below:&lt;/p&gt;

&lt;p&gt;Open a terminal in the &lt;strong&gt;my-scanner-app/&lt;/strong&gt; folder.&lt;br&gt;
Run the command &lt;code&gt;npx serve&lt;/code&gt;. &lt;br&gt;
Once it finishes loading, you can access the page using the URL provided in your terminal, which usually is &lt;code&gt;http://localhost:3000&lt;/code&gt;. &lt;br&gt;
To stop running the localhost server, press Ctrl+C on the terminal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Start scanning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you access the site on your browser, follow the steps below to test the Scanbot SDK:&lt;/p&gt;

&lt;p&gt;Click the “Start scanning” button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flpcrjqofq7qaeq2x9jpp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flpcrjqofq7qaeq2x9jpp.png" alt="Our simple start screen" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The scanning UI will open, allowing you to scan a barcode using your camera. Point your camera to a barcode, as in the example below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcb1ht4hp391cphem30fn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcb1ht4hp391cphem30fn.png" alt="The default scanning screen" width="791" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After scanning, the UI closes, displaying the scanned code and its type right below the “Start scanning” button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4s9qc69zd612nqe40z2z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4s9qc69zd612nqe40z2z.png" alt="Display" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Configure the style and scanning behavior&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The app code provided in Step 2 has the UI fully configured. To change the app’s appearance, you can customize the config object. You can, for example, change the viewfinder size and color.&lt;/p&gt;

&lt;p&gt;To do so, you can change the &lt;code&gt;aspectRatio&lt;/code&gt; and &lt;code&gt;strokeColor&lt;/code&gt; after defining the &lt;code&gt;config&lt;/code&gt; object, as displayed in the following code block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const config = new ScanbotSDK.UI.Config.BarcodeScannerConfiguration();
config.viewFinder.aspectRatio.height = 1;
config.viewFinder.aspectRatio.width = 5;
config.viewFinder.style.strokeColor = "#FF000050";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above configurations will result in the following styling:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fril06to26jky4z4r26ae.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fril06to26jky4z4r26ae.png" alt="Horizontal" width="791" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find more configuration options by accessing the &lt;a href="https://docs.scanbot.io/barcode-scanner-sdk/web/barcode-scanner/ready-to-use-ui/?_gl=1*q2epxt*_gcl_au*MTM5NzA2NjMzMS4xNzMzNDc3NjE1LjExNDQ1NTk3MDcuMTczNDcwMzkxMi4xNzM0NzAzOTEy*FPAU*MzQ1MzE3MTE0LjE3MzMzOTYwMjM.*_ga*MzQ3MzMwMTU2LjE3MzM0Nzc2MTQ.*_ga_4ZZ821ELNM*MTczODgzMzE2NS4xMDcuMS4xNzM4ODM4MzAzLjAuMC4zNTY3NDE4NjU." rel="noopener noreferrer"&gt;SDK&lt;/a&gt; or &lt;a href="https://scanbotsdk.github.io/documentation/web/classes/UIConfig.BarcodeScannerConfiguration.html" rel="noopener noreferrer"&gt;API documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As another configuration example, you can display an &lt;strong&gt;AR overlay&lt;/strong&gt; and let the user pick a specific barcode when the app identifies multiple barcodes on the camera. To add this feature, add the following code after defining the &lt;code&gt;config&lt;/code&gt; object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;config.useCase.arOverlay.visible = true;
config.useCase.arOverlay.automaticSelectionEnabled = false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you open your app again, it will look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqa8rcdknh37q05c1zzcy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqa8rcdknh37q05c1zzcy.png" alt="Image description" width="791" height="600"&gt;&lt;/a&gt;&lt;br&gt;
The AR overlay displays the barcodes’ contents right in the viewfinder&lt;/p&gt;

&lt;p&gt;💡 The AR labels can also be &lt;a href="https://docs.scanbot.io/barcode-scanner-sdk/web/barcode-scanner/ready-to-use-ui/?_gl=1*1t0v43m*_gcl_au*MTM5NzA2NjMzMS4xNzMzNDc3NjE1LjExNDQ1NTk3MDcuMTczNDcwMzkxMi4xNzM0NzAzOTEy*FPAU*MzQ1MzE3MTE0LjE3MzMzOTYwMjM.*_ga*MzQ3MzMwMTU2LjE3MzM0Nzc2MTQ.*_ga_4ZZ821ELNM*MTczODgzMzE2NS4xMDcuMS4xNzM4ODM4NTU2LjQwLjAuMzU2NzQxODY1#ar-overlay" rel="noopener noreferrer"&gt;fully configured&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Deploy to a server (optional)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To test your new app on your phone, you need to deploy it to a server. If you don’t have a web server ready, you can prototype your site using services like &lt;a href="https://static.app/" rel="noopener noreferrer"&gt;Static.app&lt;/a&gt; by executing the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Zip the content from &lt;strong&gt;my-scanner-app&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;Access Static.app and click &lt;strong&gt;Upload for free&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Find and select the &lt;strong&gt;my-scanner-app.zip&lt;/strong&gt; file.&lt;/li&gt;
&lt;li&gt;After the upload, your site will run within minutes. You will then be presented with a URL. Use it to access the app from any device, including your mobile phone.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Scanbot SDK UI is optimized for mobile devices. It allows users to choose the camera and toggle the flashlight by default. Use the URL to test the app interface on your mobile device, as displayed below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5ui5r000br5t5yrnl4g.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5ui5r000br5t5yrnl4g.jpg" alt="JavaScript barcode scanner" width="604" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That’s it! You now have a fully functional barcode-scanning web app using the &lt;a href="https://docs.scanbot.io/barcode-scanner-sdk/web/barcode-scanner/ready-to-use-ui/?_gl=1*q2epxt*_gcl_au*MTM5NzA2NjMzMS4xNzMzNDc3NjE1LjExNDQ1NTk3MDcuMTczNDcwMzkxMi4xNzM0NzAzOTEy*FPAU*MzQ1MzE3MTE0LjE3MzMzOTYwMjM.*_ga*MzQ3MzMwMTU2LjE3MzM0Nzc2MTQ.*_ga_4ZZ821ELNM*MTczODgzMzE2NS4xMDcuMS4xNzM4ODM4MzAzLjAuMC4zNTY3NDE4NjU.?utm_source=dev.to&amp;amp;utm_medium=social&amp;amp;utm_campaign=&amp;amp;utm_content=9"&gt;Scanbot SDK’s RTU UI&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>html</category>
    </item>
  </channel>
</rss>
