pub struct BrowserBuilder { /* private fields */ }Expand description
Builder for creating a browser instance.
Implementations§
Source§impl BrowserBuilder
impl BrowserBuilder
Sourcepub fn headful(self) -> Self
pub fn headful(self) -> Self
Run with a visible browser window (default is headless).
Examples found in repository?
examples/profile_reuse.rs (line 17)
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}Sourcepub fn profile(self, profile_index: usize, seed_index: u64) -> Self
pub fn profile(self, profile_index: usize, seed_index: u64) -> Self
Use a specific profile (0..99) with a specific seed. Same (profile, seed) always produces the same fingerprint.
Examples found in repository?
examples/profile_reuse.rs (line 18)
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}Sourcepub async fn build(self) -> Result<Browser>
pub async fn build(self) -> Result<Browser>
Spawn chrome.exe and connect via CDP.
Examples found in repository?
examples/profile_reuse.rs (line 19)
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 Freeze for BrowserBuilder
impl RefUnwindSafe for BrowserBuilder
impl Send for BrowserBuilder
impl Sync for BrowserBuilder
impl Unpin for BrowserBuilder
impl UnsafeUnpin for BrowserBuilder
impl UnwindSafe for BrowserBuilder
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