Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.
Deprecated version

This page exists only for clients who still integrate the SDK locally via pnpm/npm (.tgz file). New integrations should follow the main documentation via CDN.

Starting from version 2.5.0, the CDN requires the ?v=VERSION parameter and previous versions are no longer resolved by the default bootstrap. If you are in this scenario, stay on this page until you complete the migration.

Fortface SDK Web Integration in Your Web App

Installation

Download

You should download the .tgz installation file for the SDK from the following link: fortface-sdk-v2.4.3.tgz.

⚠️ To facilitate development using developer tools, use the debug mode version: fortface-sdk-v2.4.3-debug-mode.tgz Do not use in your production web app. Our SDK does not allow the use of these tools ⚠️

1. Add the file to your project

Example:

your_project/fortface-sdk-v2.4.3.tgz

  • Uncompress the .tgz file
  • Copy the folder package/dist/fortface-sdk to your assets or vendor folder
    Example: your_project/vendor/fortface-sdk
  • In the head tag of your file, import the SDK:
<head>
<script type="module" src="/vendor/fortface-sdk/fortface-sdk.esm.js"></script>
<script nomodule src="/vendor/fortface-sdk/fortface-sdk.js"></script>
</head>
Security Requirement for Encryption

To ensure security, the SDK requires that the execution environment supports HTTPS encryption, except in development environments (localhost or 127.0.0.1). Otherwise, the SDK will not initialize and the error FortfaceError.FORTFACE_INSECURE_PROTOCOL will be thrown.

Pre-initialization

Before starting the capture process, you must establish the device’s integrity to guarantee secure communication with the Fortface API. Therefore, you must:

  1. Import our SDK into your web app;
  2. Initialize FortfaceSdk;
  3. Obtain deviceRequestInfo.

Establish Device Integrity (local installation)

Our SDK is built as a Web Component. This means that before you use any method exposed by the SDK, you must register the browser's native definitions by calling the defineCustomElements() function. This registration allows the browser to recognize and initialize the components correctly. After executing, it is important to ensure that the component has already been registered before interacting with it — for example, calling public methods like start() or startSession(). For this, it is recommended to use the native API customElements.whenDefined('fortface-sdk') together with await, ensuring that the element is completely ready and available before continuing execution.

Furthermore, in applications that use Server-Side Rendering (SSR), it is important to ensure that the registration and use of the Fortface SDK components are not executed on the server, where the window and customElements objects are not available.

Initialize the SDK and obtain the deviceRequestInfo.

<!DOCTYPE html>
<html>
<head>
<title>Example with Fortface SDK</title>

<script type="module" src="/vendor/fortface-sdk/fortface-sdk.esm.js"></script>
<script nomodule src="/vendor/fortface-sdk/fortface-sdk.js"></script>
</head>
<body>
<div>
<fortface-sdk></fortface-sdk>
</div>
<script>
function fortfaceSdkInit() {
customElements.whenDefined('fortface-sdk').then(async () => {
const fortfaceSdk = document.querySelector("fortface-sdk");

// For document capture
const deviceRequestInfo = await fortfaceSdk.startDoc();

// For document upload
// const deviceRequestInfo = await fortfaceSdk.startDocUpload();
});
}
document.addEventListener("DOMContentLoaded", function () {
fortfaceSdkInit();
});
</script>
</body>
</html>
Removal of the applyPolyfills function

From version 2.3.0, the applyPolyfills function is no longer available. Therefore, there is no need for this configuration, which will be done automatically. If you are using a version prior to 2.3.0, update and follow the previous examples.

With deviceRequestInfo in hand, you can perform a handshake between your backend and the Fortface API.

Camera Permissions

Our SDK automatically handles the camera permission request. However, if your application needs to request these permissions before calling the SDK’s startDoc method, it is essential to stop any active camera stream before the SDK’s pre-initialization. This ensures that the camera opens correctly for capture. For example:

// Request camera permission before initializing the SDK
const tracks = await navigator.mediaDevices.getUserMedia({ video: true });

// Before pre-initializing the SDK, make sure to stop any active camera stream
tracks.getTracks().forEach((track) => track.stop());

// Now it is safe to pre-initialize the SDK
fortfaceSdk.startDoc();

Versioning

To find out which version of our SDK is being used, simply call the getVersion() function. Example:

const version = await fortfaceSdk.getVersion();

Other sections

For what follows after pre-initialization, the behavior of the SDK is identical to the CDN integration. See the main page: