A high-level API to control headless Chrome over the DevTools Protocol
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Keyboard, mouse, and touch input simulation for comprehensive user interaction automation.
Simulate keyboard input including typing, key presses, and modifier keys.
/**
* Keyboard input simulation
*/
class Keyboard {
/** Type text with optional delay */
type(text: string, options?: {delay?: number}): Promise<void>;
/** Press and release key */
press(key: KeyInput, options?: PressOptions): Promise<void>;
/** Press key down (without releasing) */
down(key: KeyInput, options?: {text?: string}): Promise<void>;
/** Release key */
up(key: KeyInput): Promise<void>;
/** Send character directly */
sendCharacter(char: string): Promise<void>;
}
interface PressOptions {
delay?: number;
text?: string;
}
type KeyInput = "Enter" | "Tab" | "Escape" | "ArrowUp" | "ArrowDown" | "ArrowLeft" | "ArrowRight" | "Space" | "Backspace" | "Delete" | "Home" | "End" | "PageUp" | "PageDown" | "F1" | "F2" | "F3" | "F4" | "F5" | "F6" | "F7" | "F8" | "F9" | "F10" | "F11" | "F12" | "Digit0" | "Digit1" | "Digit2" | "Digit3" | "Digit4" | "Digit5" | "Digit6" | "Digit7" | "Digit8" | "Digit9" | "KeyA" | "KeyB" | "KeyC" | "KeyD" | "KeyE" | "KeyF" | "KeyG" | "KeyH" | "KeyI" | "KeyJ" | "KeyK" | "KeyL" | "KeyM" | "KeyN" | "KeyO" | "KeyP" | "KeyQ" | "KeyR" | "KeyS" | "KeyT" | "KeyU" | "KeyV" | "KeyW" | "KeyX" | "KeyY" | "KeyZ" | "ControlLeft" | "ControlRight" | "ShiftLeft" | "ShiftRight" | "AltLeft" | "AltRight" | "MetaLeft" | "MetaRight";Usage Examples:
// Basic typing
await page.keyboard.type("Hello World", { delay: 100 });
// Key combinations
await page.keyboard.down("ControlLeft");
await page.keyboard.press("KeyA"); // Ctrl+A
await page.keyboard.up("ControlLeft");
// Navigation
await page.keyboard.press("Tab");
await page.keyboard.press("Enter");Simulate mouse interactions including clicks, movements, and drag operations.
/**
* Mouse input simulation
*/
class Mouse {
/** Reset mouse state */
reset(): Promise<void>;
/** Move mouse to coordinates */
move(x: number, y: number, options?: {steps?: number}): Promise<void>;
/** Click at coordinates */
click(x: number, y: number, options?: MouseClickOptions): Promise<void>;
/** Press mouse button down */
down(options?: MouseOptions): Promise<void>;
/** Release mouse button */
up(options?: MouseOptions): Promise<void>;
/** Scroll mouse wheel */
wheel(options?: MouseWheelOptions): Promise<void>;
/** Drag from start to target */
dragAndDrop(start: Point, target: Point, options?: {delay?: number}): Promise<void>;
}
interface MouseClickOptions {
button?: "left" | "right" | "middle";
clickCount?: number;
delay?: number;
}
interface MouseOptions {
button?: "left" | "right" | "middle";
clickCount?: number;
}
interface MouseWheelOptions {
deltaX?: number;
deltaY?: number;
}
interface Point {
x: number;
y: number;
}Usage Examples:
// Click at specific coordinates
await page.mouse.click(100, 200);
// Double click
await page.mouse.click(100, 200, { clickCount: 2 });
// Drag and drop
await page.mouse.dragAndDrop(
{ x: 100, y: 100 },
{ x: 200, y: 200 },
{ delay: 1000 }
);
// Scroll
await page.mouse.wheel({ deltaY: -100 }); // Scroll upSimulate touch interactions for mobile and tablet interfaces.
/**
* Touchscreen input simulation
*/
class Touchscreen {
/** Start touch at coordinates */
touchStart(x: number, y: number): Promise<TouchHandle>;
/** Move active touch */
touchMove(x: number, y: number): Promise<void>;
/** End active touch */
touchEnd(): Promise<void>;
/** Single tap at coordinates */
tap(x: number, y: number): Promise<void>;
}
interface TouchHandle {
move(point: Point): Promise<void>;
end(): Promise<void>;
}Usage Examples:
// Simple tap
await page.touchscreen.tap(100, 100);
// Swipe gesture
const touch = await page.touchscreen.touchStart(100, 100);
await touch.move({ x: 200, y: 100 }); // Swipe right
await touch.end();Install with Tessl CLI
npx tessl i tessl/npm-puppeteer