The Lifecycle

Every proctored test follows the same four-step flow:

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

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'
})

After this call, your credentials are available on the instance (e.g. apInst.hashedTestAttemptId). No network requests are made yet.

.setup(proctoringOptions)

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

  1. Downloads the required JS libraries and ML models
  2. Creates the HTML elements for the proctoring UI
await apInst.setup({
    track: { audio: true, numHumans: true, tabSwitch: true }
})

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
  2. Checks device and browser compatibility
  3. Requests camera, microphone, and screenshare permissions
  4. Loads video streams and ML models for face detection
apInst.start()

window.addEventListener('apMonitoringStarted', () => {
    // Proctoring is active — show the test questions
    document.getElementById('quiz').style.display = 'block'
})

Emits apMonitoringStarted when proctoring is active. You can call .start() after awaiting .setup(), or listen for the apSetupCompleted event.

.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('apMonitoringStopped', () => {
    window.location.href = '/test-complete'
})

Emits apMonitoringStopped when finalized. After this, calling .start() again with the same testAttemptId will throw an error.

.destroy()

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

  1. Stops all proctoring activity
  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()
})