Skip to content

The headless browser for AI agents and web scraping

Merge pull request #1205 from vvinayakkk/emulated-color-scheme

SGavrl6cca1d9adda1
diff --cc crates/obscura-js/src/ops.rs
index 2a523998,1e6f3bd5..f0c3a892
--- a/crates/obscura-js/src/ops.rs
+++ b/crates/obscura-js/src/ops.rs
@@@ -333,11 -159,9 +333,13 @@@ pub struct ObscuraState
/// "UTF-8", "EUC-JP"). Backs `document.characterSet` and the URL query
/// encoding override for `<a>`/`<area>` hrefs in legacy-charset documents.
pub encoding: String,
+ /// MIME type of the document's main resource, lowercased and without
+ /// parameters. Backs `document.contentType`; a `text/plain` navigation
+ /// must not report `text/html` just because the URL has no extension.
+ pub content_type: String,
pub title: String,
+ /// (reduced motion, dark scheme), shared by every document in this page.
+ pub(crate) media_preferences: Rc<Cell<(bool, bool)>>,
/// URL of the document that initiated this document's navigation. Direct
/// browser/API navigations leave this empty; document-initiated
/// navigations set it to the source document URL.
@@@ -586,12 -399,13 +588,18 @@@ pub struct PendingFrameMessage
impl ObscuraState {
pub(crate) fn inherit_resources(&mut self, parent: &Self) {
+ self.media_preferences = parent.media_preferences.clone();
+ #[cfg(feature = "render")]
+ {
+ let (reduce, dark) = parent.media_preferences.get();
+ self.render_media = self.render_media.with_reduced_motion(reduce).with_dark_color_scheme(dark);
+ }
self.cookie_jar = parent.cookie_jar.clone();
+ // A frame shares its page's Web Storage Arcs. The ops key by the frame
+ // realm's own document URL, so a cross-origin frame still lands in its
+ // own bucket instead of the top document's.
+ self.local_storage = parent.local_storage.clone();
+ self.session_storage = parent.session_storage.clone();
self.http_client = parent.http_client.clone();
self.callbacks = parent.callbacks.clone();
self.encoding = parent.encoding.clone();
@@@ -616,10 -430,9 +624,11 @@@
url: "about:blank".to_string(),
about_base_url: None,
inherited_origin: None,
+ storage_origin_cache: RefCell::new(StorageOriginCache { origin: "null".into(), ..Default::default() }),
encoding: "UTF-8".to_string(),
+ content_type: String::new(),
title: String::new(),
+ media_preferences: Rc::new(Cell::new((false, false))),
referrer: String::new(),
navigation_timing: NavigationTiming::default(),
blocked_urls: Vec::new(),