Web

AI Tools

If you have integrated the age estimation and liveness API, we strongly recommend adding our face capture module to enhance your results. When deployed in a web application, Yoti optionally provides a JavaScript Face Capture Module (FCM) that uses the webcam to capture an image of the user, which can be sent to the Yoti services backend for processing.

There are 2 steps to follow to integrate the face capture module:

  1. Install the package
  2. Integrate the package.

This service has high image quality requirements.

By integrating our web FCM (via a webview), you will benefit from our proprietary Secure Image Capture (SICAP) technology. This approach effectively prevents injection attacks, as each image capture is signed and verified by our backend. It also blocks the use of virtual cameras and hijacking of HTTP requests.

Install the package

Yoti currently supports:

  • React JS (Next JS)
  • Javascript

React JS

Install the dependency.

Node.JS (npm)
Node.JS (yarn)
Copy

To ensure the Yoti Face Capture Module functions correctly, it must be excluded from minification within your Next.js configuration (next.config.js or next.config.mjs).

The package depends on the following peer dependencies:

Node.JS
Copy

The package supports the following browser versions:

BrowserVersions
Android Chrome139
Google Chrome140, 139, 138, 137
Microsoft Edge (Desktop only)140, 139
Mozilla Firefox142, 141, 140, 139
iOS Safari18.5-18.6, 18.4, 18.3
Apple Safari18.5-18.6, 18.4, 18.3, 18.2

Assets are not included in the javascript bundle. To have the components work correctly, you will need to copy library assets from @getyoti/react-face-capture/assets folder into your assets folder.

For instance, in WebPack, you can use the plugin copy-webpack-plugin in the following way:

Node.JS
Copy

JavaScript (vanilla)

For projects without a React tech stack, you can use the Face Capture vanilla version. When you install the library on your machine, It's located inside the folder vanilla.

Add the package to your codebase and serve the static assets:

html
Copy

Inside the page you want to have Face Capture, add Face Capture scripts and styles like in the example below. faceCaptureAssetsRootUrl is a property you can use to instruct the library where neural net files are served otherwise we look for the files relative to the page location assets/face-capture/.

Our scripts will give you access to Yoti.FaceCaptureModule.render where you can set 2 parameters. The first parameter is the properties, the same ones used in the integration with react. The second parameter is a reference to html DOM, allowing you to decide where to render the UI.

In order to unmount the component, it is highly recommended to call the Yoti.FaceCaptureModule.unmount function instead of destroying the html element, which could lead to some issues or misbehaviour.

index.html
Copy

CSS Customization

It is possible to customise the style by changing the following CSS properties:

CSS PropertiesDescription
--fcm-background-colorSets the background color.
--fcm-background-color-variant1Variant 1 of the background color.
--fcm-background-color-variant2Variant 2 of the background color.
--fcm-background-color-contrastColor used for contrast elements like separators or the dialog scrollbar.
--fcm-button-colorColor used for the buttons.
--fcm-button-color-hoverColor used for the buttons when hovered.
--fcm-button-color-pressColor used for the buttons when pressed.
--fcm-text-color-primaryColor used for the primary text.
--fcm-text-color-secondaryColor used for the secondary text.
--fcm-font-familySets the font family.
--fcm-overlay-colorSets the color and opacity of the overlay.
--fcm-frame-color-neutralSets the color of the face frame.
--fcm-frame-color-successSets the success color of the face frame.
--fcm-frame-color-warningSets the warning color of the face frame.
--fcm-frame-color-invalid-manualSets the color of the face frame for manual mode invalid image feedback.

The CSS custom properties must be defined using the :root CSS selector. Here is an example:

CSS
Copy

Example code

Below is the full sample code of FCM integration

React
NextJS
html + JavaScript
Copy

Web demo

Properties

PropertyTypeDefaultDescriptionRequired
onSuccessFunction(payload, base64PreviewImage)Callback called once the result (payload) is complete. The content of capture will vary when using secure or non-secure mode. The second argument base64PreviewImage will only be provided if returnPreviewImage is set to true.
clientSdkIdStringIdentifies your Yoti Hub application. This value can be found in the Hub, within your application section, in the keys tab.✅ *
captureMethod

String

manual/auto

autoThe way you capture the photo, either with the button of auto-capture.
secureBooleantrueUse the secure mode
onErrorFunctionCallback called when there is an error. See Appendix for the list of error codes we currently support.
onReadyForCaptureFunctionCallback called when the Face Capture is ready to take images (camera feed and face scan are ready).
showOverlayBooleantrueOptional use of the face overlay.
resolutionType

String

hd/full_hd

hdImage resolution constraints passed to getUserMedia. If multiframe is true, the resolution of the captured image will be HD and this field will be ignored.
format

String

jpeg/png

jpegImage format type. If multiframe is true, the format of the captured image will be jpeg and this field will be ignored.
imageType

String

original/cropped

originalSelects if the image will be the original or it will be cropped in order to improve the timing response when processing the image in the API call. If multiframe is true, the image type will be original and this field will be ignored.
qualityType

String

high/medium/low

highSets the image quality of jpeg format images only. High (1) - Medium (0.96) - Low (0.90). If multiframe is true, the quality of the captured image will be high and this field will be ignored.
a11yLiveRegionModeString assertive/politepoliteDEPRECATED: will be removed in the next major release. Determines the politeness setting of the live region used to read out prompts for screen reader users
faceCaptureAssetsRootUrlStringassets/face-capture/Root url where the face detection assets are located. See copy assets section for assets configuration.
loadTimeoutNumber60000 millisecondsSets the time (in ms) the Face Capture will use to notify through the onError callback if the module takes too long to download and load the module. The Face Capture will keep loading after the notification.
showGetHelpButtonBooleantrueShow the Get Help button.
showInitialGuidanceBooleantrueShow the initial help guidance.
autoSessionReloadBooleantrueAutomatically renews sessions after they expire.
userRetryErrorBooleantrueGives the possibility to users to retry several times when an error occurs.
returnPreviewImageBooleanfalseProvide the image captured (base64PreviewImage) in the onSuccess callback. Please note that the preview image is not signed, so it should only be used for user feedback. For applications that need to store or use the actual image, we recommend setting encryptImage to false.
encryptImageBooleantrueEncrypt the image inside the payload argument on the onSuccess callback when it runs the secure mode.
allowBackgroundFacesBooleanfalseAllows faces to be present in the background when the image is being captured. The Face Capture will return a cropped image with the main face when set to true. If multiframe is true, this field will be ignored and treated as false. Note: This feature is designed for retail terminals and is unsuitable for online users' face capture.
faceSelectionMethod

String

center/area

centerDefines where the main face can be placed, in the center or anywhere in the image. Note: This feature is designed for retail terminals and unsuitable for online user's face capture. It is recommend to enable allowBackgroundFaces when faceSelectionMethod is set to area.
numStableFramesNumber4Determines how many frames are used for the stability check. The minimum value is 3 and the maximum is 6.
sessionDurationNumber-Causes the session to time out after the specified number of milliseconds, regardless of number of retry attempts taken. Must be at least 30,000 (30s) and at most 300,000 (5m).

isScoPortraitCamera

(experimental)

BooleanfalseDefines if the FCM should adapt to a camera stream with portrait resolution in a SCO (self-checkout) machine. This property won't rotate your camera stream but adapt the module to a portrait resolution. This property is meant for SCO machines only and shouldn't be used on mobile phone integrations.
luminosityCheckLevelString default/low/disableddefaultSpecify how strict the luminosity check should be for the FCM to capture an image. May be helpful to ease the capture process in challenging lighting conditions but could increase the rejection rate in the service. Note: This feature is designed for retail terminals and unsuitable for online user's face capture.
multiframeBooleanfalseCauses the FCM to collect more than one image, providing more security. This feature only works when secure is active, if not it will be ignored.
languageString (refer to the Language Code list)enThe language code to set the language of the feedback messages

Language code list

CodeLanguageCodeLanguageCodeLanguage
en-GBEnglishhi-INHindipt-PTPortuguese (Portugal)
ar-XNArabichr-HRCroatianro-RORomanian
bg-BGBulgarianhu-HUHungarianru-RURussian
bs-BABosnianhy-AMArmeniansk-SKSlovak
cs-CZCzechid-IDBahasasr-RSSerbian (Cyrillic script)
da-DKDanishit-ITItaliansr-Latn-RSSerbian (Latin script)
de-DEGermanja-JPJapanesesv-SESwedish
el-GRGreekko-KRKoreanth-THth-TH
esSpanish (Spain) **lt-LTLithuaniantl-PHTagalog
es-ESSpanish (Spain)lv-LVLatviantr-TRTurkish
es-419Spanish (Latin America)ms-MYMalayuk-UAUkrainian
et-EEEstoniannb-NONorwegianur-PKUrdu
fa-IRPersiannl-NLDutchvi-VNVietnamese
fi-FIFinnishpl-PLPolishzh-CNChinese (Simplified)
fr-FRFrenchptPortuguese (Portugal) **
he-ILHebrewpt-BRPortuguese (Brazil)

(*) This field is only mandatory when using the secure mode. (secure = true)

()** Language codes marked with *** are listed for disambiguation purposes on the fallback.

Language fallback

A mechanism used for the property language to avoid issues when the value passed is wrong. Example: first try exact match (es-es or es-ES , ignore case):

  • If there is no match, try the mainstream es , by removing the region part -es .
  • If there is no mainstream, try any other available es-[region] sibling (example: es-419 ).
  • If there is no regional sibling, use the default language: en .

Error codes

Error CodeDescription
NO_CAMERANo camera detected on the user’s device.
GENERIC_CAMERA_ERRORUndefined camera error. The reasons can be various and inconsistent across browsers.
UNSUPPORTED_BROWSERThe user’s browser is not supported. This could be because the API needed for the camera interaction is missing. Note: Older Non-Safari browsers on iOS fall into this category.
NO_CAMERA_PERMISSIONThe user rejected the camera permission.
OVERCONSTRAINEDThe camera constraints are not compatible with available camera devices. Note: One recovery option could be to use hd resolution.
FACE_DETECTION_INIT_ERRORThe face detection has failed to initialise. This usually means the required model assets are missing from the host application.
INTERNAL_ERRORThis can be due to a programming error, or the user using an old unsupported browser.
CAPTURE_LOAD_ERRORThe secure module could not be loaded. This usually means your token is not updated, or there is an error on the module provider.
VIDEO_STREAM_INTERRUPTEDThe camera stream has stopped unexpectedly.
SECURE_SESSION_EXPIREDThe secure session has expired (the token expire field is older than the current time).
EXCEEDED_TIME_TO_LOADThe module is taking longer than the time set in the FaceCapture component to load. This error does not prevent the module from continuing to load. It alerts the integrator so they can decide to give additional reassurance to their users. The timeout value can be changed by updating the loadTimeout option, which defaults to 60 seconds (60000ms).
VERSION_NO_LONGER_AVAILABLEThe requested Face Capture secure module is no longer available. Note that the FCM will log a warning in the console if the module was deprecated.
INVALID_SECURE_CLIENT_SDK_IDThe client SDK ID has a wrong format, it isn't included on the internal product mapping or there is a mismatch between the SDK from the JWT and the one related to the internal product contained in the BE request.
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard