Expose the interception infrastructure that already existed internally but was
private, so embedders can intercept, observe, mock, or block JS fetch()/XHR
without forking or unsafe casts.
On obscura::Page:
- add_preload_script: inject JS before any page <script> (CDP
Page.addScriptToEvaluateOnNewDocument). The field already ran the scripts;
this only adds the method.
- enable_interception: returns a receiver for every JS fetch()/XHR request;
resolve each through its resolver with InterceptResolution::{Continue,
Fulfill, Fail} to pass, mock, or block (CDP Fetch.enable equivalent).
- on_request / on_response: passive callbacks. on_response is the main path for
capturing API response payloads from SPAs.
on_request/on_response previously fired only for navigation; op_fetch_url now
invokes them for JS fetch()/XHR too (both reqwest and stealth paths), gated on
a non-empty callback vector so the common no-callback case pays nothing.
Re-export InterceptedRequest, InterceptResolution, RequestInfo, ResourceType,
RequestCallback, ResponseCallback, Response from the obscura crate.
Integration test tests/interception.rs exercises all three against a local echo
server.
26 lines
802 B
Rust
26 lines
802 B
Rust
pub mod client;
|
|
pub mod cookies;
|
|
pub mod encoding;
|
|
pub mod interceptor;
|
|
pub mod robots;
|
|
pub mod blocklist;
|
|
#[cfg(feature = "stealth")]
|
|
pub mod wreq_client;
|
|
|
|
pub use client::{
|
|
env_allows_private_network, is_forbidden_ip, ObscuraHttpClient, ObscuraNetError, RequestCallback,
|
|
RequestInfo, ResourceType, Response, ResponseCallback, SsrfGuardResolver,
|
|
};
|
|
pub use cookies::{CookieInfo, CookieJar};
|
|
pub use encoding::{
|
|
decode_non_html, decode_response, decode_response_with_name, decode_with_label, label_name,
|
|
url_encode_query,
|
|
};
|
|
pub use robots::RobotsCache;
|
|
pub use blocklist::is_blocked as is_tracker_blocked;
|
|
#[cfg(feature = "stealth")]
|
|
pub use wreq_client::{
|
|
StealthHttpClient, STEALTH_NAVIGATOR_PLATFORM, STEALTH_UA_PLATFORM,
|
|
STEALTH_UA_PLATFORM_VERSION, STEALTH_USER_AGENT,
|
|
};
|