UNPKG

@quadible/web-sdk

Version:

The web sdk for Quadible's behavioral authentication service.

60 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const eventemitter2_1 = require("eventemitter2"); class StateCollector extends eventemitter2_1.EventEmitter2 { name = 'WebState'; isCollecting = false; data = []; constructor() { super(); this.registerMouseEventListeners(); this.wrapStateChangers(); } flush() { return this.data.splice(0); } async isAvailable() { return true; } start() { this.isCollecting = true; this.collect(); } stop() { this.isCollecting = false; } collect() { this.data.push({ kind: "popstate" /* EventKind.PopState */, url: location.href, event: 'popstate', timestamp: Date.now() }); } registerMouseEventListeners() { window.addEventListener('popstate', (e) => { if (this.isCollecting) { this.collect(); } }); } wrapStateChangers() { const wrap = (event) => { const original = history[event]; history[event] = (...args) => { const result = original.call(history, ...args); this.data.push({ kind: event, url: location.href, event, timestamp: Date.now() }); return result; }; }; wrap('replaceState'); wrap('pushState'); } } exports.default = StateCollector; //# sourceMappingURL=StateCollector.js.map