3.1.9 • Published 2 months ago

@regulaforensics/vp-frontend-face-components-beta v3.1.9

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

Face SDK Web Components


Overview

The Face SDK Web Components let you add automatic capture of a user's selfie and liveness check to your web site. The components capture a face from the device camera and can either simply detect a face on the captured photo or confirm the face liveness.

The available components are the following:

  • face-capture
  • face-liveness

The Web Components are based on WebAssembly (.wasm module), which is our core C++ code compiled for use in browsers and wrapped with a JS layer. It is exactly the same code as built for all the other platform SDK packages.

Before You Start

Important notes:

  • The Face SDK Web Components and their methods strictly require secure contexts, so using the HTTPS protocol is a must.
  • The considered components are registered on the web page itself, so make sure to import the library to your website before adding any of the components to the web page code.
  • Only the modern browser versions are supported, see compatibility. Polyfills are not included in the package by default.

Compatibility

DevicesChromeFireFoxSafari
Mobile (iOS)99 (iOS14.4+)99 (iOS14.4+)11
Mobile (Android)6963-
Desktop666911

To support the older browser versions in your project, install the required polyfill packages manually. Follow the link to an npm package @webcomponents/webcomponentsjs for installation details.

Install via NPM

On the command line, navigate to the root directory of your project:

cd /path/to/project

Run the following command:

npm init

Answer the questions in the command line questionnaire.

Install @regulaforensics/vp-frontend-face-components:

npm i @regulaforensics/vp-frontend-face-components

Create index.html and index.js files in the root directory of the project.

Import @regulaforensics/vp-frontend-face-components into your index.js:

import './node_modules/@regulaforensics/vp-frontend-face-components/dist/main.js';

In index.html connect index.js and add the name of the component you want to use. Available components:

  1. <face-capture></face-capture> - for creating a face snapshot;
  2. <face-liveness></face-liveness> - for performing liveness verification.

For example:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>My app</title>
  </head>
  <body>
    <face-capture></face-capture>
    <script type="module" src="index.js"></script>
  </body>
</html>

Install via CDN

Connect the script in your .html file. CDN link: unpkg.com/:package@:version/:file

For example:

<script src="https://unpkg.com/@regulaforensics/vp-frontend-face-components@latest/dist/main.js"></script>

Add the name of the component to the html, as in the example above.

Settings

Note that we have removed the videoRecording setting. Now you should use recordingProcess instead.

You can set any parameter using settings. Find below examples of applying all the settings at once as well as using just some of them.

An example of using all the settings:

const component = document.getElementsByTagName('face-liveness')[0];

component.settings = {
    locale: 'en',
    copyright: true,
    cameraId: '123',
    changeCamera: true,
    startScreen: true,
    closeDisabled: true,
    finishScreen: true,
    url: 'https://your-server.com',
    headers: {
        Authorization: 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
    },
    tag: 'sessionIdValue',
    retryCount: 5,
    recordingProcess: 1,
    customization: {
        fontFamily: 'Noto Sans, sans-serif',
        fontSize: '16px',
        onboardingScreenStartButtonBackground: '#7E57C5',
        onboardingScreenStartButtonBackgroundHover: '#7c45b4',
        onboardingScreenStartButtonTitle: '#FFFFFF',
        onboardingScreenStartButtonTitleHover: '#FFFFFF',
        cameraScreenFrontHintLabelBackground: '#E8E8E8',
        onboardingScreenIllumination: 'https://path-to-image.com',
        onboardingScreenAccessories: 'data:image/svg+xml;base64,PHN2...',
        onboardingScreenCameraLevel: importedImage,
        cameraScreenFrontHintLabelText: '#000000',
        cameraScreenSectorActive: '#7E57C5',
        cameraScreenSectorTarget: '#BEABE2',
        cameraScreenStrokeNormal: '#7E57C5',
        processingScreenProgress: '#7E57C5',
        retryScreenRetryButtonBackground: '#7E57C5',
        retryScreenRetryButtonBackgroundHover: '#7c45b4',
        retryScreenRetryButtonTitle: '#FFFFFF',
        retryScreenRetryButtonTitleHover: '#FFFFFF',
        retryScreenEnvironmentImage: 'https://path-to-image.com',
        retryScreenPersonImage: 'data:image/svg+xml;base64,PHN2...',
        successScreenImage: importedImage,
    }
}

An example of using just the selected settings:

const yourSettings = {
    locale: 'de',
    videoRecording: false,
    url: 'https://your-server.com',
    headers: {
        Authorization: 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
    },
    customization: {
        fontFamily: 'Noto Sans, sans-serif',
        successScreenImage: importedImage,
    }
}

const component = document.getElementsByTagName('face-liveness')[0];

component.settings = yourSettings;

Here are all the available settings:

SettingInfoData typeDefault valueValuesUsed in
localeLanguage of the component.stringenru, en, de, pl, it, hu, zh, sk, uk, fr, es, pt, ar, nl, id, vi, ko, ms, ro, el, tr, ja, cs, th, hi, bn, he, fi, sv, da, hr, noface-liveness, face-capture
urlBackend URL.stringhttps://faceapi.regulaforensics.com/any urlface-liveness
copyrightWhether to show the Regula copyright footer.booleanfalsetrue, falseface-liveness, face-capture
cameraIdAbility to select a camera by defining the camera ID.stringundefinedcamera id string valueface-liveness, face-capture
changeCameraWhether to show the "Camera Switch" button.booleantruetrue, falseface-liveness, face-capture
startScreenWhether to show the Start screen with video instructions. If true, the start screen is shown. If false, no start screen is shown and instead the camera of the device is turned on automatically to capture a face.booleantruetrue, falseface-liveness, face-capture
finishScreenWhether to show the Result screen (success screen, retry-screen). If true, the Result screen is shown to the user. If false, no Result screen is displayed, and, during a single session, the user has only one attempt to pass liveness assessment. In cases where finishScreen is set to false, we recommend to monitor Events associated with the liveness assessment and then display relevant information to the user based on those events. This approach ensures that the user receives necessary feedback even though the Result screen is not displayed by the component itself.booleantruetrue, falseface-liveness, face-capture
closeDisabledWhether to disable the "Close" button of the component. If set to true, the "Close" button is hidden from the user.booleanfalsetrue, falseface-liveness, face-capture
recordingProcessWhether to enable a video recording of the process. If set to 0, the video is sent to the server with an additional request. If set to 1, the video is sent to the server with the liveness package. If set to 2, the video isn't sent. The video format depends on the browser: MP4 for Safari, WEB for other browsers.number00, 1, 2face-liveness
tagThe server generates a unique identifier for each session before starting a verification process. Using tag, you can set a custom value. Make sure that tag is unique for each session.stringundefinedany unique for each sessionface-liveness
retryCountUsing the retryCount setter, you can set the number of liveness transaction attempts for the user. Once the attempts are exhausted, the component will display a white screen and throw the "RETRY_COUNTER_EXCEEDED" event. By default, the number of attempts is unlimited. Setting the value to 0 removes the limit on the number of attempts, while any positive number limits the attempts.number-1number of the attempts countface-liveness
headersBefore starting the camera capture, the component sends a start request to the server and receives the initialization data in response. Once the component successfully completes two stages of verification, it sends the received data to the API for processing. You can use the headers setter to set the headers for the HTTP POST method. Additionally, the video recording is transmitted to the server along with these headers.objectundefinedobject with headers (key, value).face-liveness
customizationYou can customize the element's color, font, and image by using this object. See the Customization section below.objectundefinedobject with customization settingsface-liveness, face-capture
nonceYou can set a unique nonce value to maintain the CSP policy.stringundefinedunique nonce valueface-liveness, face-capture
rotationAngleDesktop only. By using the rotationAngle setter, you can specify an angle to compensate for the rotation of your physical camera. When set to values of 90 and -90, the component's design will switch to a mobile (vertical) orientation.numberundefined0,180,90,-90face-liveness, face-capture
holdStillDurationFor the Capture screen, sets the duration that the user needs to stand straight and look in the camera.numberundefinedsecondsface-capture
timeoutIntervalTimeout for the Capture screen.numberundefinedsecondsface-capture

Customization

You can customize the color of some elements, fonts, and images with the help of the customization field in the settings object. The customization settings are the following:

SettingInfoMigrate fromData typeDefault value
fontFamilyFont.--font-familystringNoto Sans, sans-serif
fontSizeBase font size.--font-sizestring16px
onboardingScreenStartButtonBackgroundInstruction screen button background color.--main-colorstring#7E57C5
onboardingScreenStartButtonBackgroundHoverInstruction screen button background hover color.--hover-colorstring#7C45B4
onboardingScreenStartButtonTitleInstruction screen button text color.string#FFFFFF
onboardingScreenStartButtonTitleHoverInstruction screen button text hover color.string#FFFFFF
onboardingScreenIlluminationInstruction screen "Illumination" icon image.base64 or url or imported image
onboardingScreenAccessoriesInstruction screen "No accessories" icon image.base64 or url or imported image
onboardingScreenCameraLevelInstruction screen "Camera level" icon image.base64 or url or imported image
cameraScreenFrontHintLabelBackgroundСamera screen plate with info message background color.--plate-colorstring#E8E8E8
cameraScreenFrontHintLabelTextСamera screen plate with info message text color.string#000000
cameraScreenSectorActiveUser progress sector color (available only in face-liveness component).string#7E57C5
cameraScreenSectorTargetTarget sector color (available only in face-liveness component).--target-sector-colorstring#BEABE2
cameraScreenStrokeNormalStroke color of the camera circle.string#7E57C5
processingScreenProgressProcessing screen spinner color.string#7E57C5
retryScreenEnvironmentImageRetry screen environment image.base64 or url or imported image
retryScreenPersonImageRetry screen person image.base64 or url or imported image
retryScreenRetryButtonBackgroundRetry screen button background color.--main-colorstring#7E57C5
retryScreenRetryButtonBackgroundHoverRetry screen button background hover color.--hover-colorstring#7C45B4
retryScreenRetryButtonTitleRetry screen button text color.string#FFFFFF
retryScreenRetryButtonTitleHoverRetry screen button text hover color.string#FFFFFF
successScreenImageSuccess screen image.base64 or url or imported image

For example:

const component = document.getElementsByTagName('face-liveness')[0]; 

component.settings = {
    ...otherSettings,
    customization: {
        fontFamily: 'Noto Sans, sans-serif',
        fontSize: '16px',
        onboardingScreenStartButtonBackground: '#7E57C5',
        onboardingScreenStartButtonBackgroundHover: '#7c45b4',
        retryScreenPersonImage: 'data:image/svg+xml;base64,PHN2...',
    }
}

Events

You can subscribe to the component events.

For example:

const faceLivenessComponent = document.getElementsByTagName('face-liveness')[0]; 
const faceCaptureComponent = document.getElementsByTagName('face-capture')[0];

faceLivenessComponent.addEventListener('face-liveness', (event) => console.log(event.detail)); // event listener for face-liveness component
faceCaptureComponent.addEventListener('face-capture', (event) => console.log(event.detail)); // event listener for face-capture component

The face-liveness type of event is generated for the face-liveness component, and face-capture type of event is generated for the face-capture component.

The generated event object (event.detail) contains three fields that describe the event:

{
  action: "PRESS_START_BUTTON", // the type of action that generated the event (all actions are described in the table below)
  data: null, // component data
  manual: true // event generated by user action or component by itself
}

Type of actions:

Type of actionDescription of the actionThe component
ELEMENT_VISIBLEThe component is appended in the DOM.face-liveness, face-capture
PRESS_START_BUTTONThe "Get started" button is pressed.face-liveness, face-capture
PRESS_RETRY_BUTTONThe "Retry" button is pressed.face-liveness, face-capture
CLOSEThe "Close" button is pressed.face-liveness, face-capture
PROCESS_FINISHEDThe component has finished its work.face-liveness, face-capture
SERVICE_INITIALIZEDThe component has started its work.face-liveness, face-capture
RETRY_COUNTER_EXCEEDEDThe component has finished its work due to the exceeded number of transaction attempts.face-liveness

In cases of successful operation of the components, the data field will contain the following fields:

{
  response: { ... }, // component result
  status: 1 // 1 for successful work and 0 for unsuccessful
}

In cases of unsuccessful work, the data field will contain the following fields:

{
  reason: "CAMERA_PERMISSION_DENIED", // error reason (possible causes of errors are described in the table below)
  status: 0
}

Table of event causes:

ReasonDescription of the reason
WASM_ERRORError in WASM.
UNKNOWN_ERRORUnknown error.
NOT_SUPPORTEDThe browser is not supported.
CAMERA_UNKNOWN_ERRORUnknown camera error.
CAMERA_PERMISSION_DENIEDAccess to the camera is prohibited.
NO_CAMERAThere is no camera.
INCORRECT_CAMERA_IDThere is no camera available.
CONNECTION_ERRORConnection errors.
LANDSCAPE_MODE_RESTRICTEDWork in landscape orientation is prohibited.
TIMEOUT_ERRORTransaction failed due to timeout.
CHANGE_CAMERAThe user has changed the camera. Return to start-screen or restart service if start-screen is disabled.
DEVICE_ROTATEThe user has rotated the device. Return to start-screen or restart service if start-screen is disabled.
APP_INACTIVEThe user has closed the tab or browser during the face capture process.
INCORRECT_CAMERA_IDNo camera with the specified ID found.

The table below describes the cases of event generation:

face-liveness & face-capture

Event object event.detail

face-liveness face-capture

{
  action: "ELEMENT_VISIBLE", 
  data: null
}

To receive this event, you must wrap the component in another element (for example, a div) and add an addEventListener to it. When the component appears in the DOM, the event will pop up.

For example:

<div id="add-event-listener-to-this-element">
  <face-liveness></face-liveness>
</div>

face-liveness face-capture

{
  action: "PRESS_START_BUTTON", 
  data: null
}

face-liveness face-capture

{
  action: "PRESS_RETRY_BUTTON", 
  data: null
}

face-liveness face-capture

{
  action: "CLOSE", 
  data: null
}

face-liveness face-capture

{
  action: "PROCESS_FINISHED", 
  data: {
    response: { ... },
    status: 1
  },
}

face-liveness face-capture

{
  action: "PROCESS_FINISHED", 
  data: {
    reason: "An event has occurred",
    status: 0
  },
}

face-liveness face-capture

{
  action: "PROCESS_FINISHED", 
  data: {
    reason: "TIMEOUT_ERROR"
    status: 0
  },
}

face-liveness face-capture

{
  action: "SERVICE_INITIALIZED",
  data: null
}

Response

You can get the response of the component in the detail field of the event object.

For example:

const component = document.getElementsByTagName('face-capture')[0];

function listener(event) {
    if (event.detail.action === 'PROCESS_FINISHED' && event.detail.data.status === 1) {
        const response = event.detail.data.response;
        console.log(response);
    }
}

component.addEventListener('face-capture', listener);

The face-liveness response has the following structure:

{
  code: number // Result codes from core lib
  metadata: {
    [key: string]: any
  };
  tag: string
  status: number // liveness status: 0 if the person's liveness is confirmed, 1 if not. 
  estimatedAge: number | null // approximate age with an accuracy of +/-3 years
  transactionId: string
  images: string[] // array with the final image in base64 
}

The face-capture response has the following structure:

{
  capture: string[] // array with the final image in base64 
}

Custom translations

To change the standard component messages or any text, specify the language you are using (or add your own) and the label you want to change (you can see the list of available languages in the settings section, the locale setting):

Note. To see the changes, don't forget to set the language you changed to the locale setting:

const element = document.querySelector('face-liveness');

element.settings = {
    locale: 'en'
};

element.translations = {
   en: { 
     selfieTime: 'Get Selfie',
   },
};

The list of labels used in the component:

LabelDefault message in en locale
showOnlyOneFaceMake sure there is only one face on the screen.face-liveness, face-capture
preparingCameraPreparing the camera...face-liveness, face-capture
allowAccessCameraAllow access to the cameraface-liveness, face-capture
somethingWentWrongSomething went wrongface-liveness, face-capture
incorrectCameraIdNo camera with the specified ID found.face-liveness, face-capture
checkCameraIdCheck if the specified camera ID is correct.face-liveness, face-capture
preparingServicePreparing the service...face-liveness, face-capture
allowAccessToCameraAllow access to the camera and reload this page to continue.face-liveness, face-capture
errorError!face-liveness, face-capture
versionNotSupportedYour browser version is not supported.face-liveness, face-capture
updateBrowserUpdate your browser versionface-liveness, face-capture
licenseErrorA license error has occurredface-liveness, face-capture
licenseExpiredThe license cannot be found or has expiredface-liveness, face-capture
onlyPortraitOrientationPortrait orientation onlyface-liveness, face-capture
turnDeviceIntoPortraitPlease turn your device into portrait modeface-liveness, face-capture
tryAgainTry againface-liveness, face-capture
noCameraAvailableNo camera availableface-liveness, face-capture
checkCameraConnectionCheck the camera connection and try again.face-liveness, face-capture
lookStraightLook straightface-liveness, face-capture
fitYourFaceCenter your faceface-liveness, face-capture
moveCloserMove closerface-liveness, face-capture
moveAwayMove awayface-liveness, face-capture
holdSteadyHold steadyface-liveness, face-capture
processingProcessing...face-liveness, face-capture
retryButtonTextRetryface-liveness, face-capture
followGuidelinesTextBut please follow these guidelines:face-liveness, face-capture
letsTryAgainTitleLet’s try that againface-liveness, face-capture
noCameraPermissionCamera unavailable!face-liveness, face-capture
goButtonGoface-liveness, face-capture
selfieTimeSelfie time!face-liveness, face-capture
ambientLightingAmbient lighting is not too bright or too dark and there are no shadows or glare on your faceface-liveness
noMaskSunglassesHeaddressNeutral facial expression (no smiling, eyes open and mouth closed), no mask, sunglasses or headwearface-liveness
turnHeadTurn your head a bitface-liveness
centerFaceTurnHeadCenter your face, turn your headface-liveness
centerFaceCenter your faceface-capture
errorCodeError code:face-liveness
illuminationGood illumination.face-liveness, face-capture
cameraLevelCamera at eye level.face-liveness, face-capture
noAccessoriesNo accessories: glasses, mask, hat, etc.face-liveness, face-capture
getReadyGet readyface-liveness, face-capture

Examples

You can find examples of using the components on the Samples page.

Additional Resources

The Face SDK Web Components are also available on Storybook.

3.1.9

2 months ago

3.1.8

3 months ago

3.1.7

3 months ago

3.1.6

3 months ago

3.1.5

3 months ago

3.1.4

3 months ago

3.1.3

4 months ago

3.1.2

4 months ago

3.1.1

5 months ago

3.1.0

5 months ago

3.0.2

11 months ago

3.0.1

11 months ago

3.0.0

11 months ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.4

1 year ago

1.0.0

1 year ago

1.0.1-beta.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

0.0.2-beta.1

1 year ago

0.0.2-beta.0

1 year ago

0.0.1

1 year ago