pub struct TypingSimulator { /* private fields */ }Expand description
Simulates human-like typing using Input.dispatchKeyEvent CDP commands.
Each character is dispatched as a keyDown → char → keyUp sequence.
Capital letters include the Shift modifier mask (modifiers = 8). A
configurable error rate causes occasional typos that are corrected via
Backspace before the intended character is retyped. Inter-key delays
follow a Gaussian distribution (~80 ms mean, 25 ms σ) clamped to
30–200 ms.
§Example
use stygian_browser::behavior::TypingSimulator;
let mut typer = TypingSimulator::new();
typer.type_text(page, "Hello, world!").await?;Implementations§
Source§impl TypingSimulator
impl TypingSimulator
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a typing simulator seeded from wall-clock time.
§Example
use stygian_browser::behavior::TypingSimulator;
let typer = TypingSimulator::new();Sourcepub const fn with_seed(seed: u64) -> Self
pub const fn with_seed(seed: u64) -> Self
Create a typing simulator with a fixed seed (useful for testing).
§Example
use stygian_browser::behavior::TypingSimulator;
let typer = TypingSimulator::with_seed(42);Sourcepub const fn with_error_rate(self, rate: f64) -> Self
pub const fn with_error_rate(self, rate: f64) -> Self
Set the per-character typo probability (clamped to 0.0–1.0).
Default is 0.015 (1.5 %).
§Example
use stygian_browser::behavior::TypingSimulator;
let typer = TypingSimulator::new().with_error_rate(0.0);Sourcepub fn keystroke_delay(&mut self) -> Duration
pub fn keystroke_delay(&mut self) -> Duration
Sample a realistic inter-keystroke delay (Gaussian, ~80 ms mean).
The returned value is clamped to the range 30–200 ms.
§Example
use stygian_browser::behavior::TypingSimulator;
let mut typer = TypingSimulator::with_seed(1);
let delay = typer.keystroke_delay();
assert!(delay.as_millis() >= 30 && delay.as_millis() <= 200);Sourcepub async fn type_text(&mut self, page: &Page, text: &str) -> Result<()>
pub async fn type_text(&mut self, page: &Page, text: &str) -> Result<()>
Type text into the focused element with human-like keystrokes.
Each character produces keyDown → char → keyUp events. With
probability error_rate a wrong adjacent key is typed first, then
corrected with Backspace. Word boundaries (space or newline) receive an
additional 100–400 ms pause to simulate natural word-completion rhythm.
§Errors
Returns BrowserError::CdpError if any CDP call fails.