context.detectFaces
ContextFinds faces locally with YuNet, then fits a compact CPU CLM to estimate detailed landmarks. It is available independently of BrowseAnonymous.
| Signature | context.detectFaces(image: string, options?: FaceOptions): Promise<readonly Face[]> |
|---|---|
| Take it from | const { detectFaces } = useToolbar(); |
Parameters
| Parameter | Type | Description |
|---|---|---|
image | string | An absolute HTTP(S) image URL without credentials, or a data:image/… URL. HTTP(S) URLs are limited to 4,096 characters. SVG images and blob: URLs are unsupported. |
options | FaceOptions | Optional. { signal?: AbortSignal }. Aborting stops this caller waiting and rejects with AbortError; the component's mount also bounds the call. |
Return Value
A deeply read-only array of at most 32 faces. [] means no faces were detected; errors reject the promise.
| Type | Promise<readonly Face[]> |
|---|
Face Geometry
All positions are fractions of the decoded image's width and height, independent of inference resizing.
| Field | Meaning |
|---|---|
x, y, width, height | Face box, normalized from 0 to 1. |
score | YuNet's face-detection confidence, from 0 to 1; not landmark confidence. |
points | Measured rightEye, leftEye, nose, rightMouth, leftMouth, and the derived mouth midpoint. Right and left are the person's own: rightEye is on the viewer's left. Optional ear fields are absent with YuNet. |
mesh | Optional accepted CLM fit: 66 points, 66 visibility flags, 91 fixed triangles of zero-based indices, and pose.pitch, pose.yaw, pose.roll in radians. Mesh points can extend outside a cropped image. Visibility describes the fitted view; hidden points are inferred. |
Check mesh before using it. Faces smaller than 24 pixels across at inference size,
weak image evidence or rejected fits retain only the detector landmarks. The fitted
shape estimates lips, brows and jaw; it does not measure depth or trace the scalp.
The Faces guide lists every landmark region and explains how a toolbar maps the coordinates through CSS sizing and cropping. The API returns geometry; the toolbar owns drawing and cleanup.
Limits and Errors
The image download has a 20-second timeout and an 8 MiB file limit. Inference uses at most 640 pixels on the longer side and has a 30-second queue deadline. Small, occluded and strongly turned faces may be missed or have less accurate landmarks.
Invalid input rejects with TypeError; download, decode and worker failures reject with an error. An aborted signal
or an ended mount rejects with AbortError, including an already-aborted signal.
A worker failure clears pending detections; the next call starts a new worker.
Shared cache
One worker serves the toolbar owners, with an in-memory cache of the last 400 image results. Embedded-image keys are hashed; the cache retains geometry rather than image bytes. Cancelling a call stops that caller waiting while other callers can finish the shared work. Errors are not cached.
Availability
| Bundleware | 1.0.1, build 2026.12.02 |
|---|---|
| Runtime | Bundled toolbars, imported Chrome user toolbars and the Editor's Preview on Page. The sandbox and website-only previews have no detector. |
| Setup | Included with Bundleware, independent of the optional Gemini Nano language model. |
| Network | No @connect line is needed. Images download without cookies or referrer; pixels and detections are not uploaded. The WASM and both models ship in the extension. |
Related
| Name | Description |
|---|---|
useToolbar() | Returns the context for a toolbar component, widget or window. |
browse-anonymous.toolbar.tsx | A consumer of the shared API that maps image and CSS-background geometry to local visual effects. |