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
Windowtarget - 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
detailproperty 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:
| Event | Emitted 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. |
apBrowserDependencyCheckPassed | Browser compatibility check passed. Fired when all browser requirements are met and proctoring can proceed. |
apProgressUpdate | Progress updates during SDK loading. The detail property contains progress percentage and current step information. |
apProgressDelayed | Fired when a step is taking longer than expected. Useful for showing loading indicators or timeout warnings. |
apMonitoringOnAuxStarted | Monitoring started on auxiliary device. Important: For auxiliary devices, this event fires INSTEAD of apMonitoringStarted. |
apInstanceDestroyed | Fired 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
}
})
Following the HTTP status code convention, codes starting with 2 indicate success, codes starting with 4 indicate a browser error, and codes starting with 5 indicate a violation.
apSuccessEvent - Success Events
| Code | Emitted When |
|---|---|
| 2001 | Browser and Permission check completed and Permission granted |
| 2002 | HTML Elements created. Ready to async load video and ML model |
| 2003 | Video and ML model loaded. Ready to start face detection |
| 2004 | Auxiliary device started capturing. Indicates the secondary device has begun recording. |
apErrorEvent - Error Events
| Code | Emitted When |
|---|---|
| 4001 | Incompatible Browser. Doesn't pass checkBrowserCompatiblity(). |
| 4002 | From permissions API, user has already blocked access to camera. |
| 4003 | From permissions API, user has already blocked access to microphone. |
| 4004 | User has proactively declined access to camera/microphone. Or, the page is being loaded within an insecure context. |
| 4005 | Hardware error, insecure context, or some other error. |
| 4006 | From permissions API, user has already blocked access to camera and mic. |
| 4007 | Audio Not Readable Error in getUserMedia. |
| 4008 | Video Not Readable Error in getUserMedia. |
| 4007 | Mic Not Found in getUserMedia. |
| 4008 | Camera Not Found in getUserMedia. |
| 4009 | We 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. |
| 4010 | We 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. |
| 4011 | Permission 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. |
| 4012 | The 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. |
| 4013 | No sources of screen video are available for capture. |
| 4014 | You must share your entire screen in order to proceed with the test. Please reload the page to select again. |
| 4015 | We 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. |
| 4016 | Use latest version of Safari on iPhone or iPad. Else, use Chrome. |
| 4017 | Please use Chrome or Firefox, if you want to proceed with the test. (if forceCaptureSwitchedTab is true) |
| 4018 | There was some error while loading the libraries. |
apEvidenceEvent - Evidence Events
| Code | Emitted When |
|---|---|
| 5001 | No one looking at camera |
| 5002 | More than 1 Person in Video |
| 5003 | Random photo taken |
| 5004 | Audio above background levels |
| 5005 | Document page hidden or focus lost |
| 5006 | Document page became visible or focus was gained |
| 5007 | Multiple monitors detected |
| 5008 | Multiple monitors suspected (not a violation) |
| 5009 | Exited full screen mode |
| 5010 | Auxiliary 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 violationevidenceURL: 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");
}
});