Skip to content

The headless browser for AI agents and web scraping

fix(cli): await promise-returning --eval expressions

Suydev8e0a3197c27a
diff --git a/crates/obscura-cli/src/worker.rs b/crates/obscura-cli/src/worker.rs
index 2b6964b3..4f6cbb7e 100644
--- a/crates/obscura-cli/src/worker.rs
+++ b/crates/obscura-cli/src/worker.rs
@@ -106,7 +106,22 @@ async fn main() {
}
}
WorkerCommand::Evaluate { expression } => {
- let result = page.evaluate(&expression);
+ // Await promise-returning expressions so async IIFEs resolve
+ // before serialization. Previously the sync path serialized an
+ // unresolved Promise as `{}`, making single-invocation flows
+ // that call async app APIs impossible (issue #693). A 30s cap
+ // matches the CDP await timeout so a never-settling promise
+ // cannot hang the worker.
+ let result = match page
+ .evaluate_for_cdp_with_timeout(&expression, true, true, 30_000)
+ .await
+ {
+ Ok(info) => match info.value {
+ Some(v) => v,
+ None => serde_json::Value::String(info.description),
+ },
+ Err(_) => serde_json::Value::Null,
+ };
WorkerResponse::success(result)
}
WorkerCommand::Title => {