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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TypingSimulator
impl RefUnwindSafe for TypingSimulator
impl Send for TypingSimulator
impl Sync for TypingSimulator
impl Unpin for TypingSimulator
impl UnsafeUnpin for TypingSimulator
impl UnwindSafe for TypingSimulator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more