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.
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.
apInstanceDestroyedFired when destroy() is called and the AutoProctor instance is completely cleaned up. Recommended to reload page after this event. See .destroy() for details.

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 { successCode } = e.detail
  if (successCode === 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
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.
4007Mic Not Found in getUserMedia.
4008Camera Not Found 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.
4016Use latest version of Safari on iPhone or iPad. Else, use Chrome.
4017Please use Chrome or Firefox, if you want to proceed with the test. (if forceCaptureSwitchedTab is true)
4018There was some error while loading the libraries.

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
5008Multiple monitors suspected (not a violation)
5009Exited full screen mode
5010Auxiliary device environment video has been uploaded

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

  • evidenceCode: The numeric code identifying the type of violation (5001-5010)
  • 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");
    }
});