JavaScript Events

AutoProctor's functionality is driven by JavaScript events. Use these events to manage the candidate flow in your integration. There are two types:

  • Regular events: The most important events are emitted directly to the Window target
  • Custom events: The less important events are emitted as a Custom Event. The specific event (for example, ML Model is loaded) is added to the detail property of the event.

Regular events

To show a quiz's <div> once monitoring has begun:

window.addEventListener('apMonitoringStarted', () => {
  div.style.visibility = 'visible'
})

AutoProctor emits the following events:

EventEmitted When
apSetupCompleted.setup() completes successfully. You can now call the .start() method
apMonitoringStarted.start() executes successfully and events are being tracked. The test start time is recorded. To hide test questions until proctoring is ready, load them after this event.
apMonitoringStopped.stop() executes successfully. The final violations are sent to the server, the test finish time is set, and the Trust Score is calculated. Redirect or show results after this event.
apTestSubmissionFailedThe final submit after .stop() failed (for example the network dropped). Call .stop() again to retry.
apBrowserDependencyCheckPassedBrowser compatibility check passed. Fired when all browser requirements are met and proctoring can proceed.
apProgressUpdateProgress updates during SDK loading. The detail property contains progress percentage and current step information.
apProgressDelayedFired when a step is taking longer than expected. Useful for showing loading indicators or timeout warnings.
apMonitoringOnAuxStartedMonitoring started on auxiliary device. Important: For auxiliary devices, this event fires INSTEAD of apMonitoringStarted.
apAuxDisconnectedFired on the primary device when the auxiliary device (phone) loses connection during proctoring. The detail property contains testAttemptId. Use this to show custom warnings or take action on primary device when the auxiliary device disconnects.
apInstanceDestroyedFired when destroy() is called and the AutoProctor instance is completely cleaned up. Recommended to reload page after this event. See .destroy() for details.
apExternalMonitorRemovedWith preventMultipleMonitors on, all extra monitors were disconnected while the candidate was blocked.

Custom Events

An AutoProctor custom event can be one of: apSuccessEvent, apErrorEvent or apEvidenceEvent. For example, to enable a button when ML models are loaded:

window.addEventListener('apSuccessEvent', (e) => {
  const { statusCode } = e.detail
  if (statusCode === 2003) {
    btn.disabled = false
  }
})

apSuccessEvent - Success Events

CodeEmitted When
2001Browser and Permission check completed and Permission granted
2002HTML Elements created. Ready to async load video and ML model
2003Video and ML model loaded. Ready to start face detection
2004Auxiliary device started capturing. Indicates the secondary device has begun recording.

apErrorEvent - Error Events

CodeEmitted When
1058.showReport() was called with every section turned off, so there is nothing to show. Needs v5
4001Incompatible Browser. Doesn't pass checkBrowserCompatiblity().
4002From permissions API, user has already blocked access to camera.
4003From permissions API, user has already blocked access to microphone.
4004User has proactively declined access to camera/microphone. Or, the page is being loaded within an insecure context.
4005Hardware error, insecure context, or some other error.
4006From permissions API, user has already blocked access to camera and mic.
4007Audio Not Readable Error in getUserMedia.
4008Video Not Readable Error in getUserMedia.
4009We weren't able to find a microphone on your device. You need to enable your microphone, or use another device that has a microphone to take this test.
4010We weren't able to find a camera (or webcam) on your device. You need to enable your camera, or use another device that has a camera to take this test.
4011Permission to access a screen area was denied by the user, or the current browsing instance is not permitted access to screen sharing. Please reload the page to provide the access.
4012The user selected a screen, window, tab, or other source of screen data, but a hardware or operating system level error or lockout occurred, preventing the sharing of the selected source.
4013No sources of screen video are available for capture.
4014You must share your entire screen in order to proceed with the test. Please reload the page to select again.
4015We have detected multiple monitors. Please disconnect the extra monitor (or displays like Chromecast). If you continue without disconnecting, your teacher will be informed of multiple monitors.
4016With the auxiliary device on, the iPhone or iPad runs an iOS version older than 14.3. Needs v5
4017The screen couldn't be captured after several attempts.
4018There was some error while loading the libraries.
4019With preventMultipleMonitors on, an extra monitor was connected after the start check.
4021The candidate's network blocks evidence uploads or, with recordTestTaker on, the candidate recording. The test doesn't start; the candidate is asked to switch networks and can try again. errorDetails names what is blocked. Needs v5

apEvidenceEvent - Evidence Events

CodeEmitted When
5001No one looking at camera
5002More than 1 Person in Video
5003Random photo taken
5004Audio above background levels
5005Document page hidden or focus lost
5006Document page became visible or focus was gained
5007Multiple monitors detected. Not sent in v5.
5008Multiple monitors suspected (not a violation). Not sent in v5.
5009Exited full screen mode
5010Ongoing noise detected (live signal; not stored in the report)
5011Auxiliary device environment video has been uploaded (fires on the phone)
5012A mobile phone was detected in the camera view
5013A monitor was connected after the start check
5014The candidate was blocked at the start because of a second monitor

The apEvidenceEvent provides detailed information about potential violations through its detail property. Available fields:

  • evidenceCode: The numeric code identifying the type of violation (5001-5014)
  • evidenceDetails: Additional context about the violation
  • evidenceURL: URL to the evidence (usually a screenshot or audio clip)
  • violationCount: Number of times this specific violation has occurred

The following example auto-submits a test after the candidate exceeds a maximum number of tab switches:

const MAX_TAB_SWITCHES_BEFORE_SUBMIT = 2;

window.addEventListener("apEvidenceEvent", (e) => {
    const { evidenceCode, evidenceURL, violationCount } = e.detail;

    // 5005 is the code for tab switching violation
    // Auto-submit the test after exceeding tab switch limit
    if (evidenceCode === 5005) {
      if (violationCount > MAX_TAB_SWITCHES_BEFORE_SUBMIT) {
        document.getElementById("testEndBtn").click(); // or your equivalent submission logic
      } else {
        showAlert(`
          <p>
            Our system detected that you switched tabs.
            Please refrain from switching tabs, or else your test will be submitted automatically.
          </p>
        `);
      }
    }
});

Handle other violations by checking their respective evidenceCode. For example, to detect when multiple people are in the frame:

window.addEventListener("apEvidenceEvent", (e) => {
    const { evidenceCode } = e.detail;

    if (evidenceCode === 5002) {
        alert("Warning: Multiple people detected in camera frame");
    }
});