Module session

Module session 

Source
Expand description

Session persistence for long-running scraping campaigns.

Save and restore browser state (cookies and localStorage) across runs so you can login once and reuse the authenticated session without repeating the authentication flow.

§Use case

use stygian_browser::{BrowserPool, BrowserConfig, WaitUntil};
use stygian_browser::session::{save_session, restore_session, SessionSnapshot};
use std::time::Duration;

let pool = BrowserPool::new(BrowserConfig::default()).await?;
let handle = pool.acquire().await?;
let mut page = handle.browser().expect("valid browser").new_page().await?;

// First run: login and save
page.navigate("https://example.com/login", WaitUntil::Selector("body".to_string()), Duration::from_secs(30)).await?;
// …perform login…
let snapshot = save_session(&page).await?;
snapshot.save_to_file("session.json")?;

// Later run: restore
let snapshot = SessionSnapshot::load_from_file("session.json")?;
restore_session(&page, &snapshot).await?;
// Now the page has the saved cookies + localStorage

Structs§

SessionCookie
A serialisable browser cookie.
SessionSnapshot
A point-in-time snapshot of a browser session.

Functions§

restore_session
Restore a previously saved session into page.
save_session
Capture the current session state from page.