pub struct Page<'b> { /* private fields */ }Expand description
A loaded page within the browser.
Implementations§
Source§impl<'b> Page<'b>
impl<'b> Page<'b>
Sourcepub async fn mouse_move(&self, x: f64, y: f64, steps: u32) -> Result<()>
pub async fn mouse_move(&self, x: f64, y: f64, steps: u32) -> Result<()>
Move mouse along a human-like bezier curve to (x, y).
Sourcepub async fn click(&self, x: f64, y: f64) -> Result<()>
pub async fn click(&self, x: f64, y: f64) -> Result<()>
Click at (x, y) with human-like mouse movement first.
Sourcepub async fn human_idle(&self, duration_ms: u64) -> Result<()>
pub async fn human_idle(&self, duration_ms: u64) -> Result<()>
Simulate idle human presence with random mouse movements.
Sourcepub async fn capture_mhtml(&self) -> Result<Vec<u8>>
pub async fn capture_mhtml(&self) -> Result<Vec<u8>>
Capture full page as MHTML (HTML + JS + CSS + images — everything). Save to .mhtml file, opens in Chrome with full fidelity.
Sourcepub async fn capture_html(&self) -> Result<String>
pub async fn capture_html(&self) -> Result<String>
Capture page HTML via DOM API (won’t break JS/special chars).
Returns outerHTML including all <script> tags intact.
Sourcepub async fn js(&self, code: &str) -> Result<String>
pub async fn js(&self, code: &str) -> Result<String>
Execute JavaScript and return the result as a string.
Examples found in repository?
examples/profile_reuse.rs (line 26)
11async fn main() {
12 println!("=== Profile Reuse Demo ===\n");
13
14 // --- Session 1: first visit ---
15 println!("[Session 1] First visit with profile({}, {})", PROFILE_INDEX, SEED);
16 let browser = Browser::builder()
17 .headful()
18 .profile(PROFILE_INDEX, SEED)
19 .build().await
20 .expect("failed to create browser");
21
22 let page = browser.navigate("https://www.youtube.com").await
23 .expect("navigate failed");
24 tokio::time::sleep(std::time::Duration::from_secs(3)).await;
25
26 let title = page.js("document.title").await.unwrap_or_default();
27 let cookies = browser.cookies("https://www.youtube.com").await.unwrap_or_default();
28 let fingerprint = page.js("navigator.hardwareConcurrency + 'c|' + screen.width + 'x' + screen.height + '|' + Intl.DateTimeFormat().resolvedOptions().timeZone").await.unwrap_or_default();
29
30 println!(" Title: {}", title);
31 println!(" Fingerprint: {}", fingerprint);
32 println!(" Cookies: {} total", cookies.len());
33 for c in cookies.iter().take(5) {
34 println!(" {} = {}...", c.name, &c.value[..c.value.len().min(30)]);
35 }
36
37 println!(" Shutting down session 1...\n");
38 browser.shutdown().await.expect("shutdown failed");
39
40 // --- Session 2: same profile, cookies should persist ---
41 println!("[Session 2] Reusing profile({}, {}) — cookies should persist", PROFILE_INDEX, SEED);
42 let browser = Browser::builder()
43 .headful()
44 .profile(PROFILE_INDEX, SEED)
45 .build().await
46 .expect("failed to create browser");
47
48 // Check cookies BEFORE navigating — they should be in the user-data-dir
49 let page = browser.navigate("https://www.youtube.com").await
50 .expect("navigate failed");
51 tokio::time::sleep(std::time::Duration::from_secs(3)).await;
52
53 let cookies2 = browser.cookies("https://www.youtube.com").await.unwrap_or_default();
54 let fingerprint2 = page.js("navigator.hardwareConcurrency + 'c|' + screen.width + 'x' + screen.height + '|' + Intl.DateTimeFormat().resolvedOptions().timeZone").await.unwrap_or_default();
55
56 println!(" Fingerprint: {}", fingerprint2);
57 println!(" Cookies: {} total", cookies2.len());
58 for c in cookies2.iter().take(5) {
59 println!(" {} = {}...", c.name, &c.value[..c.value.len().min(30)]);
60 }
61
62 // Verify
63 println!("\n--- Verification ---");
64 println!(" Fingerprint match: {}", fingerprint == fingerprint2);
65 println!(" Cookies persisted: {}", cookies2.len() >= cookies.len());
66
67 browser.shutdown().await.expect("shutdown failed");
68 println!("\n=== DONE ===");
69}Auto Trait Implementations§
impl<'b> Freeze for Page<'b>
impl<'b> !RefUnwindSafe for Page<'b>
impl<'b> Send for Page<'b>
impl<'b> Sync for Page<'b>
impl<'b> Unpin for Page<'b>
impl<'b> UnsafeUnpin for Page<'b>
impl<'b> !UnwindSafe for Page<'b>
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
Mutably borrows from an owned value. Read more