proctor-ai-sdk
Version:
A powerful SDK for preventing cheating during online exams using face detection, voice detection, and tab monitoring.
22 lines (17 loc) • 521 B
JavaScript
//⬅️ Detect tab switch/minimize
import { logEvent } from "../logs/logger.js";
let hasFocus = true;
export const startTabSwitchDetector = () => {
document.addEventListener("visibilitychange", () => {
if (document.hidden) {
logEvent("tab-switched");
hasFocus = false;
} else if (!hasFocus) {
logEvent("tab-returned");
hasFocus = true;
}
});
};
export const stopTabSwitchDetector = () => {
document.removeEventListener("visibilitychange", () => {});
};