Appearance
date: 2026-06-12 tags: [pest-browser, playwright, javascript, footgun] status: active graduated_to:
pest-browser $page->script() runs raw JS — a top-level return is a SyntaxError
Symptom — a browser test failed with "SyntaxError: Illegal return statement" (then a generic 5s timeout on the next step), not an assertion failure. The offending call was $page->script("return Array.from(document.querySelectorAll('[tabindex]'))…").
Root cause — script() evaluates the string as a bare expression in the page (Playwright's evaluate), not as a function body, so a leading return is illegal JavaScript at the top level.
Fix — drop the return; pass the expression itself: $page->script("Array.from(...).map(...)"). Fixed in tests/Browser/LoginTabOrderTest.php and PeopleCategoryFilterTest.
Guard — this learning. The error is loud and immediate once you know the cause; the trap is mistaking it for a flaky timeout. Sibling: 2026-06-07-pest-browser-no-assert-see-in-order.md (use data-test + script for ordering).