Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions crates/tinycomputer-browser/src/reply/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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)
}

Expand Down
17 changes: 17 additions & 0 deletions crates/tinycomputer-browser/src/reply/reply_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!({
Expand Down
Loading