DEV Community

Cover image for Add proctoring to a React quiz in five lines
Ashhar Akhlaque
Ashhar Akhlaque

Posted on

Add proctoring to a React quiz in five lines

TL;DR: npm install proctorkit, add a page key, create one proctor per candidate and call runChecks() then start() from your Start button. Recording only is free during launch. AI review is ₹15 ($0.25) per candidate session, with the first 50 free.

Most cheating in online tests is casual, and most proctoring only starts at the interview. I wanted every candidate's first-round test covered, and I didn't want to move the questions into someone else's platform. This is the React version of how I added it to a hiring test we already had.

Before the code: it runs in desktop Chrome or Edge only. It's built for everyday cheating (a phone, a friend, an AI chat in the next tab, and 20+ other checks), not determined attackers. What it doesn't see:

Not covered Why
A phone fully outside the camera's view The camera can't see it
Tools built to hide from screen sharing They don't show up in the shared screen
Someone speaking off camera Nothing on screen or camera shows it

See it in action

What you get

  • A system check and a consent screen before the first question
  • Full screen, the entire screen shared and the camera on, for the whole test
  • The recording and every event tied to the question on screen
  • With AI review on, a report per candidate, riskiest first

Your questions, answers and scoring stay where they are. You can sign up, add the code and proctor real candidates the same day, with no sales call.

1. Install

npm install proctorkit
Enter fullscreen mode Exit fullscreen mode

2. Get a page key

Create an account at proctorkit.com, choose Record or Record + AI review, and add the website your quiz runs on. You get a key that starts with pk_pub_. It's safe in the page: it only works on the websites you list, and on localhost while you build.

3. One proctor per candidate

// proctor.ts
import { createProctor } from 'proctorkit';

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' },
  });
Enter fullscreen mode Exit fullscreen mode

4. Start it from your Start button

const [proctor] = useState(() => makeProctor(user));
const [started, setStarted] = useState(false);

const begin = async () => {
  const check = await proctor.runChecks(); // system check and consent
  if (check.ok && proctor.start()) setStarted(true);
  else setProblem(check.reason ?? 'not ready'); // e.g. 'unsupported', 'camera'
};

useEffect(() => {
  if (started) proctor.setContext({ questionId: questions[i].id });
}, [started, i]);

const submit = () => {
  proctor.stop(); // releases camera and screen
  // ...save the answers as you do today
};
Enter fullscreen mode Exit fullscreen mode

runChecks() has to run from a click, because browsers only allow screen sharing and full screen after one.

5. A timer that stops during pauses

If the candidate leaves full screen or stops sharing, the test pauses until they fix it. Base your countdown on activeMs(), which leaves out paused time:

const left = limitMs - proctor.activeMs();
Enter fullscreen mode Exit fullscreen mode

6. See the results

Each candidate shows up in your dashboard under their test, with the recording and flags laid out by question. With AI review on, the riskiest sessions come first.

What it costs

Recording only is free during launch. AI review is ₹15 ($0.25) per candidate session, with the first 50 free. No subscription.

Try it

Try to cheat the five-question demo (desktop Chrome or Edge), then read the report it writes about you: proctorkit.com/demo. On your phone? Start at proctorkit.com and save the demo for your laptop. Full guide: proctorkit.com/docs/react.

Top comments (1)

Collapse
 
jonrandy profile image
Jon Randy 🎖️ •

Proctoring? This is invigilation. Proctoring sounds like something that would go on in a doctor's examination room