From afdf9be26189c16bd48c78730b60e9868fedba22 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 23 Oct 2026 07:18:08 +0530 Subject: [PATCH] fix(browser): classify page script errors before keyword matches An evaluation error's text comes from the page, so a script that throws "TimeoutError" or quotes the allowed-domains refusal was classified as a retryable timeout or a policy block. Check the evaluation-error prefix right after the stale-ref prefixes, before any substring match. --- crates/tinycomputer-browser/src/reply/mod.rs | 8 +++++--- .../src/reply/reply_tests.rs | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/tinycomputer-browser/src/reply/mod.rs b/crates/tinycomputer-browser/src/reply/mod.rs index 2eaeb95c1..ba633429d 100644 --- a/crates/tinycomputer-browser/src/reply/mod.rs +++ b/crates/tinycomputer-browser/src/reply/mod.rs @@ -44,6 +44,11 @@ pub(crate) fn classify(message: &str) -> Error { reference: message.to_owned(), }; } + // A script error carries text the page controls, so it is classified + // before any keyword below can read that text as a timeout or a refusal. + if lower.starts_with("evaluation error") { + return Error::page(message); + } if lower.contains("is not in the allowed domains list") { return Error::BlockedByPolicy { url: quoted(message).unwrap_or(message).to_owned(), @@ -93,9 +98,6 @@ pub(crate) fn classify(message: &str) -> Error { if lower.contains("dialog is blocking the page") { return Error::not_actionable(message); } - if lower.starts_with("evaluation error") { - return Error::page(message); - } Error::failed(message) } diff --git a/crates/tinycomputer-browser/src/reply/reply_tests.rs b/crates/tinycomputer-browser/src/reply/reply_tests.rs index 60ee68164..acd6089b3 100644 --- a/crates/tinycomputer-browser/src/reply/reply_tests.rs +++ b/crates/tinycomputer-browser/src/reply/reply_tests.rs @@ -113,6 +113,23 @@ fn engine_messages_map_to_what_the_caller_should_do() { } } +#[test] +fn page_script_error_text_cannot_change_the_error_class() { + for message in [ + "Evaluation error: TimeoutError: slow", + "Evaluation error: Error: Domain 'x' is not in the allowed domains list", + "Evaluation error: Error: Element not found: #pay", + "Evaluation error: Error: Browser not launched", + "Evaluation error: Error: Invalid URL: nope", + ] { + let error = classify(message); + assert!( + matches!(error, Error::PageError { .. }), + "{message} became {error:?}" + ); + } +} + #[test] fn a_snapshot_lists_refs_in_document_order_and_caps_the_tree() { let reply = json!({