HTML - Vanilla JS

Accura IDScan Plugin — Vanilla HTML Integration Guide

This guide walks you through integrating the Accura IDScan Plugin into a standard HTML project using native ES Modules.

Step 1: Implementation

Create an index.html file in your project directory and add the following import and initialization code inside a <script type="module"> block.

<script type="module">
  // Import the IDCardPlugin class directly from the Accura CDN using ESM syntax.
  // No npm install is required for plain HTML projects.
  import IDCardPlugin from "https://unpkg.com/accuraidscanplugin/dist/accuramain.js";

  // Declare a variable to hold the active plugin instance.
  // This allows us to safely call destroy() before re-initializing.
  let currentPlugin = null;

  // Destroy any previously active instance before creating a new one.
  // This prevents duplicate camera sessions or memory leaks.
  if (currentPlugin) currentPlugin.destroy();

  // Instantiate the IDCardPlugin with two required arguments:
  //   1. The callback function that receives captured card images as base64 Data URLs
  //   2. A configuration object specifying the target card and UI appearance
  currentPlugin = new IDCardPlugin(
    handleCapture,   // Callback invoked upon successful ID card scan completion
    {
      countryCode: "UGA",    // country code of the card being scanned
      cardCode: "UGNIDF",    // card code for the front side of the ID
      topTextSize: "",       // Size of the top instruction overlay text (default if empty)
      topTextColor: "",      // Color of the top instruction overlay text (default if empty)
      topTextWeight: "",     // Font weight of the top instruction text (default if empty)
      bottomTextSize: "",    // Size of the bottom instruction overlay text (default if empty)
      bottomTextColor: "",   // Color of the bottom instruction overlay text (default if empty)
      bottomTextWeight: "",  // Font weight of the bottom instruction text (default if empty)
    }
  );

  // Start the plugin engine. This opens the camera and begins card detection.
  try {
    await currentPlugin.start();
  } catch (error) {
    console.error("Failed to start plugin:", error);
  }
</script>

Step 2: Response Handling

When the plugin completes an ID card scan, it invokes the handleCapture callback with a single payload object. This object may contain one or both of the following properties:

Property
Type
Description

front

string

Base64 Data URL of the front side of the ID card

back

string

Base64 Data URL of the back side of the ID card (if applicable)

What is Base64? Base64 is a binary-to-text encoding scheme that converts raw binary image data into a sequence of printable ASCII characters. Each captured card image is delivered as a Data URL string (e.g., data:image/jpeg;base64,/9j/...), which combines the MIME type prefix with the encoded image payload. Before transmitting to a server, this string must be decoded back into binary form (a Blob) to construct a valid multipart HTTP request.


Step 3: Demo Implementation

The following is a complete, ready-to-use index.html file. Copy and paste it as-is into your project. No modifications have been made to the original logic.


Note: Since this uses ESM imports, you must serve the file via a local server (e.g., using Live Server in VS Code or npx serve .). Opening the file directly via file:// may cause CORS or module issues.

Last updated