Skip to content

The headless browser for AI agents and web scraping

Merge stealth-overhaul into main

SGavrl8582fccecabb
diff --cc crates/obscura-browser/src/page.rs
index 32649051,95ad7ae4..393ca9ce
--- a/crates/obscura-browser/src/page.rs
+++ b/crates/obscura-browser/src/page.rs
@@@ -316,7 -319,10 +318,11 @@@ impl Page
rt.set_cookie_jar(self.context.cookie_jar.clone());
rt.set_http_client(self.http_client.clone());
+ rt.set_blocked_urls(self.blocked_url_patterns.clone());
+ #[cfg(feature = "stealth")]
+ if let Some(ref stealth) = self.stealth_client {
+ rt.set_stealth_client(stealth.clone());
+ }
if let Some(tx) = &self.intercept_tx {
rt.set_intercept_tx(tx.clone());
diff --cc crates/obscura-js/js/bootstrap.js
index f364f545,5c433b3b..acc29125
--- a/crates/obscura-js/js/bootstrap.js
+++ b/crates/obscura-js/js/bootstrap.js
@@@ -2764,29 -2665,30 +2805,26 @@@ globalThis.navigator =
connection: new NetworkInformation(),
pdfViewerEnabled: true,
get plugins() {
- const p = new PluginArray([
- { name: "PDF Viewer", filename: "internal-pdf-viewer", description: "Portable Document Format", length: 1, [Symbol.toStringTag]: "Plugin" },
- { name: "Chrome PDF Viewer", filename: "internal-pdf-viewer", description: "Portable Document Format", length: 1, [Symbol.toStringTag]: "Plugin" },
- { name: "Chromium PDF Viewer", filename: "internal-pdf-viewer", description: "Portable Document Format", length: 1, [Symbol.toStringTag]: "Plugin" },
- { name: "Microsoft Edge PDF Viewer", filename: "internal-pdf-viewer", description: "Portable Document Format", length: 1, [Symbol.toStringTag]: "Plugin" },
- { name: "WebKit built-in PDF", filename: "internal-pdf-viewer", description: "Portable Document Format", length: 1, [Symbol.toStringTag]: "Plugin" },
+ return new PluginArray([
+ new Plugin("PDF Viewer", "internal-pdf-viewer", "Portable Document Format", []),
+ new Plugin("Chrome PDF Viewer", "internal-pdf-viewer", "Portable Document Format", []),
+ new Plugin("Chromium PDF Viewer", "internal-pdf-viewer", "Portable Document Format", []),
+ new Plugin("Microsoft Edge PDF Viewer", "internal-pdf-viewer", "Portable Document Format", []),
+ new Plugin("WebKit built-in PDF", "internal-pdf-viewer", "Portable Document Format", []),
]);
- return p;
},
get mimeTypes() {
- const m = [
- { type: "application/pdf", description: "Portable Document Format", suffixes: "pdf", enabledPlugin: null },
- { type: "text/pdf", description: "Portable Document Format", suffixes: "pdf", enabledPlugin: null },
- ];
- m.item = (i) => m[i] || null;
- m.namedItem = (name) => m.find(x => x.type === name) || null;
- return m;
+ return new MimeTypeArray([
+ new MimeType("application/pdf", "Portable Document Format", "pdf", null),
+ new MimeType("text/pdf", "Portable Document Format", "pdf", null),
+ ]);
},
userAgentData: {
- brands: [
- {brand: "Google Chrome", version: "145"},
- {brand: "Chromium", version: "145"},
- {brand: "Not;A=Brand", version: "24"},
- ],
mobile: false,
+ get brands() { return _uaBrands(); },
get platform() { return globalThis.__obscura_ua_platform || "Windows"; },
getHighEntropyValues(hints) {
+ var brands = _uaBrands();
return Promise.resolve({
architecture: "x86",
bitness: "64",
@@@ -6420,10 -6374,13 +6523,11 @@@ if (!globalThis.crypto) globalThis.cryp
if (!globalThis.crypto.subtle) {
globalThis.crypto.subtle = {
async digest(algorithm, data) {
- // Real WebCrypto digest. Delegates to `op_subtle_digest` which runs
- // the actual SHA-1/256/384/512 via Rust's `sha1` and `sha2` crates.
- // The previous JS implementation was a custom FNV variant that
- // produced bytes shaped like the hash but with wrong contents, so
- // SRI checks, JWS signature verification, and OAuth PKCE silently
- // accepted invalid input.
- const name = (typeof algorithm === 'string' ? algorithm : algorithm?.name) || 'SHA-256';
+ const name = (typeof algorithm === 'string' ? algorithm : algorithm?.name || '').toUpperCase().replace('_', '-');
- if (name !== 'SHA-1' && name !== 'SHA-256' && name !== 'SHA-384' && name !== 'SHA-512') {
++ if (name !== 'SHA-1' && name !== 'SHA-256' && name !== 'SHA-384' && name !== 'SHA-512' &&
++ name !== 'SHA-512/224' && name !== 'SHA-512/256') {
+ throw new DOMException('Unrecognized algorithm name', 'NotSupportedError');
+ }
let bytes;
if (data instanceof ArrayBuffer) bytes = new Uint8Array(data);
else if (ArrayBuffer.isView(data)) bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
diff --cc crates/obscura-js/src/ops.rs
index 6ae576bf,752f47e4..c33958f3
--- a/crates/obscura-js/src/ops.rs
+++ b/crates/obscura-js/src/ops.rs
@@@ -1107,9 -1218,10 +1258,10 @@@ fn op_binding_called(state: &OpState, #
}
/// Real WebCrypto `crypto.subtle.digest`. `algorithm` is the SubtleCrypto
- /// algorithm name (`SHA-1` / `SHA-256` / `SHA-384` / `SHA-512`). The JS shim
- /// validates the name before calling this op; any other value is unreachable.
+ /// algorithm name (`SHA-1` / `SHA-256` / `SHA-384` / `SHA-512`, plus the
-/// FIPS 180-4 truncated variants `SHA-512/224` and `SHA-512/256`). Other
-/// names fall back to SHA-256. Returns the raw digest bytes so the JS shim
-/// can hand them back as an ArrayBuffer.
++/// FIPS 180-4 truncated variants `SHA-512/224` and `SHA-512/256`). The JS
++/// shim validates the name; any other value is unreachable.
+/// Returns the raw digest bytes so the JS shim can hand them back as an ArrayBuffer.
#[op2]
#[buffer]
fn op_subtle_digest(#[string] algorithm: &str, #[buffer] data: &[u8]) -> Vec<u8> {
@@@ -1120,7 -1232,9 +1272,9 @@@
"SHA-256" => sha2::Sha256::digest(data).to_vec(),
"SHA-384" => sha2::Sha384::digest(data).to_vec(),
"SHA-512" => sha2::Sha512::digest(data).to_vec(),
+ "SHA-512/224" => sha2::Sha512_224::digest(data).to_vec(),
+ "SHA-512/256" => sha2::Sha512_256::digest(data).to_vec(),
- _ => sha2::Sha256::digest(data).to_vec(),
+ _ => vec![],
}
}