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!({