UNPKG

@quadible/web-sdk

Version:

The web sdk for Quadible's behavioral authentication service.

66 lines 2.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const eventemitter2_1 = require("eventemitter2"); class KeyboardCollector extends eventemitter2_1.EventEmitter2 { static KEYBOARD_EVENTS = [ 'keydown', 'keyup', 'keypress' ]; name = 'WebKeyboard'; isCollecting = false; data = []; constructor() { super(); this.registerEventListeners(); } flush() { return this.data.splice(0); } async isAvailable() { return true; } start() { this.isCollecting = true; } stop() { this.isCollecting = false; } registerEventListeners() { for (const event of KeyboardCollector.KEYBOARD_EVENTS) { window.addEventListener(event, (e) => { const targetEl = e.srcElement; if (this.isCollecting) { this.data.push({ kind: event, name: event, element: { class: targetEl?.className, name: targetEl?.getAttribute?.('name'), id: targetEl?.getAttribute?.('id'), type: targetEl?.getAttribute?.('type'), tagName: targetEl?.tagName, width: targetEl?.clientWidth, height: targetEl?.clientHeight }, timestamp: Date.now(), key: e.key, keyCode: e.keyCode, charCode: e.charCode, code: e.code, type: e.type, ctrlKey: e.ctrlKey, metaKey: e.metaKey, shiftKey: e.shiftKey, altKey: e.altKey, location: e.location, which: e.which, isTrusted: e.isTrusted }); } }); } } } exports.default = KeyboardCollector; //# sourceMappingURL=KeyboardCollector.js.map