Docs / Guides
Add proctoring to a React quiz
This guide adds ProctorKit to a React quiz you already have (Vite, Create React App or any other setup). The ProctorKit part is 5 lines; the rest is the React wiring you already have. Candidates get a system check and a consent screen, the test runs in full screen with the entire screen shared and the camera on, and the recording and every event are tied to the question on screen. For Next.js, see the Next.js guide.
1. Install
npm install proctorkit
2. Get a page key
Create an account, choose Record or Record + AI review, and add the website your quiz runs on. You get a key that starts with pk_pub_. It is safe in the page: it works only on the websites you list (and on localhost while you build). Without a key, ProctorKit still runs and hands everything to your own code instead; see the docs.
3. Create one proctor per candidate
// proctor.ts
import { createProctor } from 'proctorkit';
// who is taking the test: the dashboard shows them by name
export const makeProctor = (user: {
id: string;
name: string;
email?: string;
}) =>
createProctor({
key: import.meta.env.VITE_PROCTORKIT_KEY,
candidate: user,
test: { id: 'round-1', name: 'Screening round 1' },
});
candidate.id and candidate.name are required with a key; test is optional and groups candidates in the dashboard.
4. Start it from your Start button
import { useEffect, useState } from 'react';
import { makeProctor } from './proctor';
export function Quiz({
user,
questions,
}: {
user: { id: string; name: string; email?: string };
questions: { id: string; text: string }[];
}) {
// once per attempt, stable across re-renders
const [proctor] = useState(() => makeProctor(user));
const [started, setStarted] = useState(false);
const [problem, setProblem] = useState<string | null>(null);
const [i, setI] = useState(0);
const begin = async () => {
// shows the system check and consent
const check = await proctor.runChecks();
if (check.ok && proctor.start()) setStarted(true);
// e.g. 'unsupported', 'camera', 'screen_share', 'cancelled'
else setProblem(check.reason ?? 'not ready');
};
useEffect(() => {
// every event now carries this question
if (started) proctor.setContext({ questionId: questions[i].id });
}, [started, i]);
const submit = () => {
// releases camera and screen
proctor.stop();
// ...save the answers as you do today
};
if (!started) return <button onClick={begin}>Start test</button>;
return (
<QuestionView
q={questions[i]}
onNext={() => setI(i + 1)}
onSubmit={submit}
/>
);
}
runChecks() must run from a click, because browsers only allow screen sharing and full screen after one.
5. A timer that stops during pauses
When the candidate leaves full screen or stops sharing, ProctorKit pauses the test until they fix it. Base your countdown on activeMs(), which leaves out paused time:
import type { Proctor } from 'proctorkit';
// in Quiz: const left = useTimeLeft(proctor, 30 * 60_000, started, submit);
function useTimeLeft(
proctor: Proctor,
limitMs: number,
running: boolean,
onEnd: () => void,
) {
const [left, setLeft] = useState(limitMs);
useEffect(() => {
if (!running) return;
const t = setInterval(() => {
const l = limitMs - proctor.activeMs();
setLeft(l);
if (l <= 0) {
clearInterval(t);
onEnd();
}
}, 500);
return () => clearInterval(t);
}, [running]);
return left;
}
6. See the results
Each candidate appears in your dashboard under their test, with the recording and flags laid out by question. With AI review on, sessions are ranked by review priority so you look at the riskiest first.
Good to know
- If the key is refused (wrong website, switched off, daily limit), the test still runs with the on-device checks. Listen for it:
proctor.on('cloud_unavailable', (e) => console.warn(e.data)). - Desktop Chrome or Edge gives the full set of checks. Other browsers get
check.reason === 'unsupported'straight away, never a broken test. - HTTPS is required in production;
localhostworks while you build. - TypeScript types ship with the package.
- Paid use at volume: create sessions on your server with a server key instead; see With a server key.
Try the demo to see what candidates see, then read the full docs for every option and event.