Skip to content

The headless browser for AI agents and web scraping

fix: gate renderer-only helpers in no-render builds (#1559)

Daniel Senften5e526a03220f
diff --git a/crates/obscura-browser/src/page.rs b/crates/obscura-browser/src/page.rs
index 2b1afb46..cf9e9020 100644
--- a/crates/obscura-browser/src/page.rs
+++ b/crates/obscura-browser/src/page.rs
@@ -612,6 +612,7 @@ fn rebase_css_urls(css: &str, base: &url::Url) -> String {
/// Extract network-backed `url(...)` assets while respecting CSS comments and
/// strings. Linked sheets have already been rebased before materialization;
/// inline declarations are resolved against the document base here.
+#[cfg(any(feature = "render", test))]
fn css_resource_urls(css: &str, base: &url::Url) -> Vec<String> {
let mut urls = Vec::new();
let mut index = 0usize;
@@ -704,6 +705,7 @@ fn css_resource_urls(css: &str, base: &url::Url) -> Vec<String> {
///
/// Shared by the generic scan and the `@font-face` path so the two cannot
/// disagree about quoting, fragments, `data:` or an unresolved `var()`.
+#[cfg(any(feature = "render", test))]
fn push_css_url(raw: &str, base: &url::Url, urls: &mut Vec<String>) {
let raw = raw.trim();
let value = if raw.len() >= 2
@@ -742,6 +744,7 @@ fn push_css_url(raw: &str, base: &url::Url, urls: &mut Vec<String>) {
///
/// A malformed block is left to the normal scanner, so this cannot swallow the
/// rules that follow it.
+#[cfg(any(feature = "render", test))]
fn css_font_face_rule(css: &str, base: &url::Url) -> Option<(usize, Vec<String>)> {
if !css.get(..10)?.eq_ignore_ascii_case("@font-face") {
return None;
@@ -766,6 +769,7 @@ fn css_font_face_rule(css: &str, base: &url::Url) -> Option<(usize, Vec<String>)
/// Byte offset of the brace closing the block that `css` opens, or `None` when
/// the block is unterminated. Braces inside strings do not count.
+#[cfg(any(feature = "render", test))]
fn css_block_end(css: &str) -> Option<usize> {
let mut depth = 0usize;
let mut quote: Option<char> = None;
@@ -803,6 +807,7 @@ fn css_block_end(css: &str) -> Option<usize> {
/// Value of the last declaration named `name` in a declaration block. Last
/// rather than first, because that is what the cascade resolves to and what
/// `obscura-render` reads.
+#[cfg(any(feature = "render", test))]
fn css_last_declaration<'a>(block: &'a str, name: &str) -> Option<&'a str> {
let mut found = None;
let mut start = 0usize;
@@ -848,6 +853,7 @@ fn css_last_declaration<'a>(block: &'a str, name: &str) -> Option<&'a str> {
}
/// The `url(...)` values of one declaration, unquoted, in source order.
+#[cfg(any(feature = "render", test))]
fn css_url_values(value: &str) -> Vec<&str> {
let lower = value.to_ascii_lowercase();
let mut out = Vec::new();
@@ -877,6 +883,7 @@ fn css_url_values(value: &str) -> Vec<&str> {
/// Whether the renderer can decode a font source, by the same extension rule
/// `obscura-render` applies before it will even consider one.
+#[cfg(any(feature = "render", test))]
fn font_source_is_decodable(src: &str) -> bool {
let path = src
.split(['?', '#'])
@@ -890,6 +897,7 @@ fn font_source_is_decodable(src: &str) -> bool {
/// terminating semicolon. Semicolons inside quoted URLs, comments, or `url()`
/// parentheses do not end the rule. A malformed import is left to the normal
/// scanner so this helper cannot swallow following declarations.
+#[cfg(any(feature = "render", test))]
fn css_import_rule_len(css: &str) -> Option<usize> {
let prefix = css.get(..7)?;
if !prefix.eq_ignore_ascii_case("@import") {
@@ -941,6 +949,7 @@ fn css_import_rule_len(css: &str) -> Option<usize> {
None
}
+#[cfg(any(feature = "render", test))]
fn render_resource_is_font(url: &url::Url) -> bool {
let path = url.path().to_ascii_lowercase();
[".woff", ".woff2", ".ttf", ".otf", ".eot"]
diff --git a/crates/obscura-cli/src/main.rs b/crates/obscura-cli/src/main.rs
index 4831405e..f12649dd 100644
--- a/crates/obscura-cli/src/main.rs
+++ b/crates/obscura-cli/src/main.rs
@@ -1333,6 +1333,7 @@ async fn run_fetch(
// pages stay fast.
settle_page(&mut page, wait_secs, wait_is_fixed).await;
+ #[cfg(feature = "render")]
let mut deferred_eval_output = None;
let initial_controlled_scroll = if eval_at_capture_boundary {
controlled_scroll_request.as_ref().map(|(x, requested_y)| {
@@ -1377,6 +1378,7 @@ async fn run_fetch(
context.save_storage();
return Ok(());
}
+ #[cfg(feature = "render")]
if screenshot.is_some() {
deferred_eval_output = Some(result);
}