Skip to main content

BrowserBuilder

Struct BrowserBuilder 

Source
pub struct BrowserBuilder { /* private fields */ }
Expand description

Builder for creating a browser instance.

Implementations§

Source§

impl BrowserBuilder

Source

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}
Source

pub fn headless(self) -> Self

Run headless (no window). This is the default.

Source

pub fn config(self, path: &str) -> Self

Path to clawser config JSON (antidetect profile).

Source

pub fn random(self) -> Self

Use a random profile from the 100 built-in device profiles.

Source

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}
Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more