guise 0.1.2

Canonical browser fingerprint bundles, human-behavior timing, and TLS profile re-exports for the Santh fleet
Documentation
//! Browser typing compatibility wrappers backed by canonical human-typing
//! primitives.

use rand::SeedableRng;
use runtime_foxdriver::Page;
use std::time::Duration;

/// Type text with human-like cadence via [`crate::human::HumanTyper`].
///
/// This legacy convenience wrapper keeps the old
/// `guise::human::behavior::type_realistic` path while routing execution
/// through the canonical configurable browser typer.
///
/// # Example
///
/// ```rust,no_run
/// use guise::human::behavior::type_realistic;
/// # async fn example(page: &runtime_foxdriver::Page) -> anyhow::Result<()> {
/// type_realistic(page, "hello world").await?;
/// # Ok(()) }
/// ```
pub async fn type_realistic(page: &Page, text: &str) -> anyhow::Result<()> {
    crate::human::HumanTyper::default()
        .type_text(page, text)
        .await
}

/// Type text with bigram-aware human keystroke timing.
///
/// Uses [`crate::human::plan_keystrokes`] (re-exported from [`crate::human::keystroke`]) to produce a
/// schedule whose per-bigram inter-key gaps and per-character
/// hold-times match real-human envelopes (Dhakal et al. CHI 2018
/// envelope), then dispatches each keydown/keyup with the planned
/// timing.
///
/// Compared to the older uniform-delay implementation this replaced:
///
/// - Hot bigrams (`th`, `he`, `in`, ...) are typed at 60–110ms
///   intervals - over-trained motor programs are FAST.
/// - Cold bigrams (`qz`, `xj`, ...) are typed at 180–320ms intervals.
/// - Digit-pairs use a slower envelope because the number row is
///   not over-trained.
/// - Optional typo injection: at low probability (1.5% by default),
///   types a QWERTY-neighbour wrong character then a backspace then
///   the correct character - exactly the pattern detectors look for
///   to confirm a human typist.
/// - Optional thinking pauses (200–600ms) at the configured rate.
///
/// Backspaces (Unicode BS, `\u{0008}`) emitted by the planner are
/// dispatched as the `Backspace` named key via BiDi.
///
/// # Example
///
/// ```rust,no_run
/// use guise::human::behavior::type_human;
/// # async fn example(page: &runtime_foxdriver::Page) -> anyhow::Result<()> {
/// type_human(page, "the quick brown fox").await?;
/// # Ok(()) }
/// ```
pub async fn type_human(page: &Page, text: &str) -> anyhow::Result<()> {
    use crate::human::{plan_keystrokes, TypingPlan};
    let mut rng = rand::rngs::StdRng::from_entropy();
    let plan = plan_keystrokes(text, TypingPlan::default(), &mut rng);
    let mut key_buf = String::with_capacity(4);
    for k in plan {
        if k.gap_ms_before > 0 {
            tokio::time::sleep(Duration::from_millis(k.gap_ms_before as u64)).await;
        }
        let key = if k.ch == '\u{0008}' {
            "Backspace"
        } else {
            key_buf.clear();
            key_buf.push(k.ch);
            key_buf.as_str()
        };
        page.key_down(key).await?;
        tokio::time::sleep(Duration::from_millis(k.hold_ms as u64)).await;
        page.key_up(key).await?;
    }
    Ok(())
}