@procteye/sdk
v2.1.0
Published
Embeddable React component for browser-safe Procteye assessment, interview, and screening sessions.
Maintainers
Readme
@procteye/sdk
Embed a browser-safe Procteye session directly into your own React
application. <ProcteyeSession> mounts the Procteye assessment portal inside a
sandboxed <iframe> and streams session events (violations, completion,
errors) back to your app over postMessage.
Scope — read this first. This SDK hosts the browser-safe practice / interview / screening tier: sessions a candidate can take inside an ordinary browser tab (camera + microphone + optional screen share). Full proctored, locked-down assessments run in the Procteye desktop app (kiosk mode, keyboard hook, VM detection, watchdog) — that level of enforcement is not achievable inside an iframe and is intentionally out of scope here. Use this component to let recruiters and partners embed low-friction sessions; hand off to the desktop client for high-stakes proctored exams.
Installation
npm install @procteye/sdk
# or
pnpm add @procteye/sdk
# or
yarn add @procteye/sdkreact and react-dom (^16.8 through ^19) are peer dependencies — the
SDK does not bundle its own copy and has zero runtime dependencies.
Usage
import React from "react";
import { ProcteyeSession, ViolationPayload } from "@procteye/sdk";
export function InterviewPage({
practiceSessionToken,
}: {
practiceSessionToken: string;
}) {
const [preparing, setPreparing] = React.useState(false);
return (
<div style={{ maxWidth: 1000, margin: "0 auto", padding: 40 }}>
<h1>Screening Interview</h1>
{preparing && <p>Preparing your questions…</p>}
<ProcteyeSession
// Your own id for this attempt; the portal reports the real one.
sessionId="attempt_123"
// practice_session_token from POST /external/v1/practice-sessions,
// fetched by your backend for this attempt.
sessionToken={practiceSessionToken}
portalUrl="https://procteye.com"
onStarting={() => setPreparing(true)}
onViolation={(v: ViolationPayload) =>
console.warn(`[${v.severity}] ${v.type}`, v.details)
}
onComplete={(r) => console.log("Session complete:", r)}
onError={(e) => console.error("Session error:", e.message)}
style={{ height: 700 }}
/>
</div>
);
}Getting the session token
sessionToken is a practice session token. Your backend gets one from the
Integrity API with its secret key, then passes it to the page that renders
<ProcteyeSession>:
curl https://api.procteye.com/external/v1/practice-sessions \
-H "Authorization: Bearer $PROCTEYE_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{"external_user_ref": "user_42", "job_posting_id": "<job posting id>"}'
# => {"practice_session_token": "…", "expires_at": "2026-11-13T10:15:00.000Z"}job_posting_idis the job the practice interview is generated for, andexternal_user_refis your own id for the candidate.- The token is short-lived (see
expires_at) and starts exactly one practice session. A second start with the same token fails withpractice_session_token_used, so issue a new token for every attempt. - The portal sends the token as the
x-practice-session-tokenheader on each request; it is never put in the iframe URL.
Integrity sessions do not use this component. A normal integrity session
(POST /external/v1/sessions) returns a client_secret, which goes to the
tier-appropriate client named by its launch.mode: @procteye/proctor-js in
your own page for browser and browser+mobile, or the Procteye desktop app
for desktop. Never pass a client_secret or an API key as sessionToken.
Props
| Prop | Type | Required | Default | Description |
| --------------------- | ---------------------------------------------------- | :------: | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| sessionId | string | yes | — | Your own id for this embed (for example the attempt id). Used in the frame URL and as the fallback id in onComplete/onDone; the portal reports the real practice session id. |
| sessionToken | string | yes | — | The practice_session_token from POST /external/v1/practice-sessions (see above). Sent to the portal in the procteye:init handshake, never in the URL. Not an API key or client_secret. |
| portalUrl | string | no | "https://procteye.com" | Base URL of the Procteye portal; also the trusted origin for incoming postMessage events. Must be HTTPS; plain http is only accepted for localhost in development/test builds or when allowInsecurePortal is set. |
| allowInsecurePortal | boolean | no | false | Dev-only escape hatch. Explicitly allows a plain-http portal origin (any host) so the session token can be handed to a local/insecure portal. Never set this in production. |
| theme | "light" \| "dark" \| "system" | no | "system" | Colour theme of the session frame. "system" follows your page's prefers-color-scheme and updates the frame when it changes. Sent in procteye:init and, on later changes, in procteye:theme. |
| onViolation | (v: ViolationPayload) => void | no | — | Fired for each proctoring violation reported by the session. |
| onComplete | (r: { sessionId: string; status: string }) => void | no | — | Fired once when the session finishes, with the real sessionId/status reported by the embed. |
| onStarting | () => void | no | — | Fired when the candidate presses Start. Preparing the questions can take around 20 seconds, so show your own progress cue. |
| onError | (e: { message: string }) => void | no | — | Fired when the session frame reports an error. |
| onDone | (r: { sessionId: string }) => void | no | — | Fired when the candidate dismisses the completed screen — a cue to close/advance the host’s own UI. |
| style | React.CSSProperties | no | — | Merged into the outer container style (e.g. override height). |
| className | string | no | — | Applied to the outer container <div>. |
ViolationPayload
interface ViolationPayload {
type: string;
severity: "low" | "medium" | "high" | "critical";
details?: string;
timestamp: number;
}How it works
The component renders a strictly sandboxed iframe pointed at:
{portalUrl}/sessions/embed?session_id={sessionId}&embed=truewith sandbox="allow-scripts allow-same-origin allow-forms allow-popups" and allow="fullscreen; camera; microphone; display-capture; accelerometer; gyroscope". allow-same-origin lets the portal keep its own origin: without it the frame runs with an opaque origin (Origin: null), its scripts fail CORS and the API refuses its requests, so the portal never loads. This is safe because the portal is served from a different origin than your page, so the same-origin policy still keeps the frame out of your page, and top navigation stays blocked. If portalUrl is on your page's own origin, the component leaves allow-same-origin out, because with allow-scripts that would let the frame reach window.parent.document.
3-Step Bi-Directional PostMessage Handshake Protocol
- Step 1 — Frame Mount & Ready Beacon (
procteye:ready): When the assessment frame loads inside the iframe, it broadcasts aprocteye:readyevent to its parent window (window.parent.postMessage({ type: "procteye:ready" }, "*")). - Step 2 — Targeted Initialization Handshake (
procteye:init): Upon receivingprocteye:ready,<ProcteyeSession>verifies thatevent.source === iframe.contentWindowand that the event is trustworthy, then transmits the candidate'ssessionTokenvia a targeted message:- Opaque-origin frames (same-origin portal only): when the portal shares your page's origin the sandbox omits
allow-same-origin, so real browsers report the frame's origin as"null"(an opaque origin). That is accepted only whenevent.sourcematches the iframe's owncontentWindow(the browser fills this in — it cannot be spoofed by other pages), the sandbox still omitsallow-same-origin, and the configuredportalUrlis itself an allowed origin (HTTPS, or localhost in dev mode). The init reply is then addressed to that specific window with"*", since an opaque frame cannot be addressed by origin. - Portal origin (the normal case):
event.originmust exactly match the expectedportalUrlorigin, byte-for-byte (never prefix-matched), and that origin must be HTTPS outside dev mode.
iframe.contentWindow.postMessage( { type: "procteye:init", payload: { sessionId, sessionToken, theme }, // theme: "light" | "dark" }, expectedPortalOrigin, // "*" only for the same-origin opaque fallback );themeis the resolved colour theme ("light"or"dark"): thethemeprop, with"system"resolved against the host page'sprefers-color-scheme. It is optional for the portal; without it the portal keeps its default light theme. - Opaque-origin frames (same-origin portal only): when the portal shares your page's origin the sandbox omits
- Step 3 — Origin-Bound Session Execution & Event Stream:
The embed host captures
trustedParentOrigin = event.originfrom the handshake and guarantees that all subsequent event payloads (procteye:violation,procteye:complete,procteye:error,procteye:done) are strictly dispatched directly totrustedParentOrigin(never wildcard"*").
Theme updates (sent by the SDK)
After the handshake, whenever the resolved theme changes (the host's colour scheme changes while theme is "system", or the theme prop changes), the SDK sends the portal, at the same target origin as procteye:init:
{ type: "procteye:theme", payload: { theme: "light" | "dark" } }postMessage event contract (consumed by the SDK)
The embedded portal dispatches events of the following shape to the parent window. The SDK reads data.type and maps data.payload onto the corresponding callback:
| data.type | data.payload fields | Invokes |
| -------------------- | ---------------------------------------------------- | ----------------------------------------------------- |
| procteye:ready | (none) | Responds with procteye:init payload containing auth |
| procteye:starting | (none) | onStarting() |
| procteye:violation | violation_type, severity, details, timestamp | onViolation({ type, severity, details, timestamp }) |
| procteye:complete | session_id, status | onComplete({ sessionId, status }) |
| procteye:error | message | onError({ message }) |
| procteye:done | session_id | onDone({ sessionId }) |
Missing fields fall back to defaults (violation_type → "unknown",
severity → "medium", timestamp → Date.now()). For procteye:complete,
sessionId/status fall back to the sessionId prop and "completed" only
if the embed omits them from the payload. Any other data.type is ignored.
What the embedding site must provide
- A
sessionIdof your own and asessionToken: the practice session token your backend gets fromPOST /external/v1/practice-sessions. The SDK never asks for and never carries an API key — server credentials stay on your server. - The
portalUrlof the Procteye deployment you are integrating with. - A page served over HTTPS if the portal is HTTPS, and appropriate
camera/microphone/display-capturepermissions policy so the iframe can request device access. TheportalUrlmust itself be HTTPS outside development/test builds. For a plainhttpportal (other than the cases above), ajavascript:URL or a malformed one, the component renders a visible "Secure session unavailable" error state instead of the iframe, so no camera or microphone permission is delegated and no token is sent, and it callsonErroronce.
Changelog
2.1.0
- Add a
themeprop ("light","dark"or"system", default"system"). The resolved theme goes to the portal inprocteye:init, and later changes in a newprocteye:thememessage, so the frame follows the host page's dark mode. - Add
onStarting, fired on the portal'sprocteye:startingevent when the candidate presses Start. - The iframe title is now "Procteye session".
- Show the portal frame at full opacity as soon as it mounts. The white loading overlay, the opacity fade and the container's light background and transition are gone, so the host page shows through until the portal paints; the portal shows its own "Connecting…" state.
- Document that
sessionTokenis the practice session token fromPOST /external/v1/practice-sessions, and that integrity sessions use@procteye/proctor-jsor the desktop app instead. - An insecure
portalUrl(plainhttpto a non-loopback host withoutallowInsecurePortal,http://localhostoutside development/test builds,javascript:or malformed) now renders a visible error state and callsonError, instead of an empty iframe that still delegated camera and microphone access.
2.0.2
- The default
portalUrlis nowhttps://procteye.com, the production portal that serves/sessions/embed. The previous default,https://assess.procteye.com, is not a Procteye host. To use a local portal, passportalUrlexplicitly.
2.0.1
- The portal iframe now keeps its own origin (
allow-same-originadded to the sandbox). Before this, the frame ran withOrigin: null, its scripts failed CORS and the API refused its requests, so the embedded portal never loaded.allow-same-originis still left out whenportalUrlis on the host page's own origin.
Development
pnpm install --no-frozen-lockfile
pnpm run lint && pnpm run typecheck
timeout 600 pnpm test
pnpm run buildRepository rules: AGENTS.md. Releases: RELEASING.md.
Links
- Documentation: https://docs.procteye.com
- npm: https://www.npmjs.com/package/@procteye/sdk
License
MIT
