pub struct CloudScraper {
pub profile: BrowserProfile,
pub proxy: Option<Arc<TlsSpoofingProxy>>,
/* private fields */
}Expand description
The main entry point for managing a stealthy browser instance.
CloudScraper wraps a headless_chrome::Browser and injects stealth configurations
(via BrowserProfile and stealth JavaScript scripts) to make scraping tasks highly
undetectable by modern bot-protection systems.
Fields§
§profile: BrowserProfileThe browser profile (fingerprint) being used.
proxy: Option<Arc<TlsSpoofingProxy>>The local TLS MITM proxy instance (kept alive with the scraper)
Implementations§
Source§impl CloudScraper
impl CloudScraper
Sourcepub fn builder() -> CloudScraperBuilder
pub fn builder() -> CloudScraperBuilder
Start building a CloudScraper instance.
Sourcepub fn new_stealth_tab(&self) -> Result<Arc<Tab>, Error>
pub fn new_stealth_tab(&self) -> Result<Arc<Tab>, Error>
Creates a new stealthy tab ready for navigation.
Injects the stealth script (with navigator.languages matching the active
locale) and applies the locale’s Accept-Language/timezone/locale via CDP so
the browser’s geo signals stay coherent with the egress proxy’s country.
Sourcepub fn detect_challenge(&self, tab: &Arc<Tab>) -> Result<ChallengeSignal, Error>
pub fn detect_challenge(&self, tab: &Arc<Tab>) -> Result<ChallengeSignal, Error>
Classifies the challenge (if any) currently rendered in tab.
Detection runs over the tab’s rendered DOM. HTTP status/headers are not available from the DOM, so they are left unset — body markers are sufficient to recognise Cloudflare’s interstitial and Turnstile pages.
Sourcepub fn solve_challenge(&self, tab: &Arc<Tab>) -> Result<ChallengeSignal, Error>
pub fn solve_challenge(&self, tab: &Arc<Tab>) -> Result<ChallengeSignal, Error>
Detects and attempts to clear any bot-protection challenge on tab.
Loops according to the configured MitigationPolicy: it waits for
non-interactive challenges to auto-resolve in the real browser, and for
an interactive Turnstile it makes a best-effort click via GenericSolver
before waiting. Returns the final ChallengeSignal once the page is
clear, or Error::Challenge if the budget is exhausted or the page is
hard-blocked.
§Blocking
Like the rest of this CDP-driven API, this is a synchronous, blocking
call: it uses std::thread::sleep for back-off and blocks on CDP I/O. On
an async runtime, call it from a blocking context
(tokio::task::spawn_blocking), and run the TlsSpoofingProxy on a
multi-threaded runtime — otherwise a back-off can starve the executor that
serves the proxy the page is loading through.
Sourcepub fn domain_state(&self, host: &str) -> Result<Option<DomainState>, Error>
pub fn domain_state(&self, host: &str) -> Result<Option<DomainState>, Error>
Reads the persisted DomainState for host, if a store is configured
and a record exists.
Sourcepub fn record_outcome(&self, host: &str, outcome: Outcome) -> Result<(), Error>
pub fn record_outcome(&self, host: &str, outcome: Outcome) -> Result<(), Error>
Records outcome for host in the configured state store (no-op if none).
The current egress proxy is captured, and a Outcome::RateLimited sets a
cooldown so callers can back off via Self::cooldown_remaining.
Sourcepub fn cooldown_remaining(&self, host: &str) -> Result<Option<Duration>, Error>
pub fn cooldown_remaining(&self, host: &str) -> Result<Option<Duration>, Error>
Remaining rate-limit cooldown for host, if any.
Sourcepub fn rotate_profile(self) -> Result<CloudScraper, Error>
pub fn rotate_profile(self) -> Result<CloudScraper, Error>
Rotates the browser fingerprint by relaunching Chrome under a fresh random
BrowserProfile. See Self::rotate_profile_with.
Sourcepub fn rotate_profile_with(
self,
profile: BrowserProfile,
) -> Result<CloudScraper, Error>
pub fn rotate_profile_with( self, profile: BrowserProfile, ) -> Result<CloudScraper, Error>
Rotates the browser fingerprint to profile, keeping the same egress IP.
Profile rotation cannot be done in place — the User-Agent and other launch flags are fixed at process start — so this relaunches Chrome and returns a fresh scraper, discarding the old browser and all its tabs/session state. The MITM proxy (and its port) and the current upstream proxy are preserved; only the impersonation client and browser are rebuilt for the new identity.
Because it consumes self, it is necessarily caller-driven (it cannot run
inside the tab-scoped Self::solve_challenge). Use it when a site has
blocked the browser identity rather than the IP; for a burned IP the
automatic proxy rotation inside Self::solve_challenge handles it
without a relaunch.
Auto Trait Implementations§
impl !Freeze for CloudScraper
impl !RefUnwindSafe for CloudScraper
impl !UnwindSafe for CloudScraper
impl Send for CloudScraper
impl Sync for CloudScraper
impl Unpin for CloudScraper
impl UnsafeUnpin for CloudScraper
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more