The Lifecycle

Every proctored test follows the same four-step flow:

const apInst = new AutoProctor(credentials)
await apInst.setup(proctoringOptions)
apInst.start()
// ... candidate takes the test ...
apInst.stop()

AutoProctor is defined once the SDK has loaded. Run this code after the apLibReady event, as in the Minimal Working Example.

new AutoProctor(credentials)

Creates an AutoProctor instance with your credentials object.

const apInst = new AutoProctor({
    clientId: 'YOUR_CLIENT_ID',
    testAttemptId: 'unique-attempt-id',
    hashedTestAttemptId: 'computed-hmac-hash'
})

The constructor validates the credentials and throws if a key is unknown or has the wrong type. After this call, your credentials are available on the instance (e.g. apInst.hashedTestAttemptId, see Instance Properties). No network requests are made yet.

.setup(proctoringOptions)

Prepares the browser for proctoring using your proctoringOptions. This method:

  1. Validates the options. Invalid options are shown in a browser alert, and .setup() throws.
  2. Downloads the required JS libraries and ML models
  3. Creates the HTML elements for the proctoring UI
try {
    await apInst.setup({
        trackingOptions: { audio: true, numHumans: true, tabSwitch: true }
    })
} catch (err) {
    // Invalid options: fix your configuration
}

Emits apSetupCompleted on success, or an apErrorEvent with the corresponding error code on failure.

.start()

Begins proctoring. This is where the heavy lifting happens:

  1. Creates a test attempt on the server (or resumes it)
  2. Checks device and browser compatibility
  3. Requests camera, microphone, and screenshare permissions
  4. Loads video streams and ML models, then walks the candidate through the checks you enabled (face, photo, ID card, full screen, phone pairing)
  5. Marks the test as started and emits apMonitoringStarted
window.addEventListener('apMonitoringStarted', () => {
    // Proctoring is active — show the test questions
    document.getElementById('quiz').style.display = 'block'
})

apInst.start()

Call .start() after awaiting .setup(), or after the apSetupCompleted event.

Add your event listeners before calling .start(), and show your test on apMonitoringStarted. If the test can't start, AutoProctor tells the candidate why and .start() returns false Needs v5. If the network blocks uploads, the candidate is asked to switch networks (error 4021) and .start() waits until a retry succeeds Needs v5.

.stop()

Ends proctoring when the candidate finishes the test. This method:

  1. Sends the final violations to the server
  2. Sets the test finish time
  3. Triggers Trust Score calculation
document.getElementById('submit-btn').addEventListener('click', () => {
    apInst.stop()
})

window.addEventListener('apTestSubmissionFailed', () => {
    // The final upload failed: let the candidate click Submit again
})

window.addEventListener('apMonitoringStopped', () => {
    window.location.href = '/test-complete'
})

Emits apMonitoringStopped when finalized, just after the promise returned by .stop() resolves to true Needs v5. If the final upload fails, apTestSubmissionFailed fires (and in SDK 5.0 the promise resolves to false); nothing is lost, and calling .stop() again retries.

A finished attempt cannot be started again: calling .start() later with the same testAttemptId shows the candidate a dialog saying the attempt is already complete.

.destroy()

Immediately stops and cleans up the AutoProctor instance, whether proctoring has started or not. This method:

  1. Stops all proctoring activity (evidence collected so far is uploaded, but the attempt is not submitted)
  2. Releases camera and microphone
  3. Removes all AutoProctor elements from the page
window.addEventListener('beforeunload', () => {
    if (apInst) { apInst.destroy() }
})

Emits apInstanceDestroyed when cleanup completes.

window.addEventListener('apInstanceDestroyed', () => {
    alert('Proctoring was interrupted')
    window.location.reload()
})

Methods at a Glance

MethodReturnsNotes
new AutoProctor(credentials)instanceThrows on invalid credentials.
.setup(proctoringOptions)Promise<void>Rejects on invalid options.
.start()Promise<boolean>See .start().
.stop()Promise<boolean>true when submitted.
.destroy()booleanStops and cleans up, then emits apInstanceDestroyed.
.showReport(reportOptions)Promise<boolean>See Viewing a Single Report.
.getReport()Promise<object>See Viewing a Single Report.
.showResults(resultsOptions)Promise<void>See Viewing All Results.
.getResults(options)Promise<array>See Viewing All Results.

In SDK 4.x, .start(), .stop() and .showReport() resolve to nothing.

Instance Properties

These read-only properties describe the instance:

PropertyTypeDescription
testAttemptIdstrThe testAttemptId from your credentials.
hashedTestAttemptIdstrThe hashedTestAttemptId from your credentials.
setupStatestr or nullnull until .setup() finishes, then "ready", or "error" if it failed, and null again after .destroy().
testAttemptLabelstr or nullShort code AutoProctor assigns to the attempt after .start(), null until then (undefined before .setup()); also the phone pairing code.
isAuxiliaryDevicebooltrue on the phone paired as the auxiliary device.
isAuxiliaryDeviceSetupFullyboolOn the laptop, true once the phone is paired and set up.

Using AutoProctor in React, Vue or another SPA

The SDK has no framework component; use the AutoProctor class directly.

  • Create the instance in the browser only (in an effect or mounted hook, never during server-side rendering), after apLibReady.
  • Keep one instance per test attempt for the life of the test page. Don't create a new one on every render; React's Strict Mode runs effects twice in development, so guard against creating two.
  • Call .destroy() when the test page unmounts, and register your window event listeners in the same place so you can remove them.