Files
obscura/crates/obscura/Cargo.toml
T
SGavrl 1f5066fc30 api: add request/response interception API to Page (#306)
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.
2026-06-24 21:36:01 +00:00

26 lines
711 B
TOML

[package]
name = "obscura"
version = "0.1.0"
edition = "2021"
description = "Rust API for the Obscura headless browser"
readme = "README.md"
repository = "https://github.com/h4ckf0r0day/obscura"
license = "Apache-2.0"
[features]
default = ["api"]
api = ["obscura-browser", "obscura-net", "tokio"]
[dependencies]
obscura-browser = { path = "../obscura-browser", optional = true }
obscura-net = { path = "../obscura-net", optional = true }
anyhow = "1"
tokio = { version = "1", features = ["rt"], optional = true }
thiserror = "1"
serde_json = "1"
serde = { version = "1", features = ["derive"] }
url = "2"
[dev-dependencies]
tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync", "time"] }