Skip to content

evaluate_script doesn't report errors thrown by callbacks it schedules #3430

Description

@thomasbachem

Is your feature request related to a problem? Please describe.

evaluate_script reports only what its function returns or throws. An error thrown in a callback the function schedules, like a setTimeout, requestAnimationFrame or MutationObserver callback, never reaches the result. The tool answers as if the script ran fine, and the error only shows up in list_console_messages, which an agent has no reason to call after a successful evaluation.

Scripts that measure something over time run into this easily. One of ours collected timings in a MutationObserver callback that threw a ReferenceError on every mutation, so it came back with an empty result and nothing hinted at why.

() => new Promise(resolve => {
  setTimeout(() => {
    throw new Error('thrown in a timer');
  }, 0);
  setTimeout(() => resolve('done'), 50);
})

This returns "done", and the error is only listed by list_console_messages.

Describe the solution you'd like

List the errors the page throws or logs while the script runs in the evaluate_script response, the way list_console_messages lists them, so their msgid works with get_console_message.

Describe alternatives you've considered

A try/catch in every callback works, but nothing prompts an agent to write one, and it doesn't help when the error comes from the page's own handler for an event the script dispatches.

Additional context

Clicks and key presses have the same gap when a handler they trigger throws, and Playwright MCP links an action's new console entries, page errors included, in its response. I kept the PR to evaluate_script, where it's easiest to run into, but I'm happy to widen it if you'd rather have it for every action.

Activity

  1. OrKoN commented on Nov 9, 2026

    @OrKoN
    Collaborator

    Does this feature basically boil down to return any console logs that occurred during the evaluate call? Those might not be related to the evaluate call at all. Generally, this is how uncaught exception in JS work so ideally asking the agent to handle all uncaught rejections in their JS code should work. I think it would be useful to detect the console logs during a tool call and surface it to the agent.

  2. added theissue type on Nov 9, 2026
  3. thomasbachem commented on Nov 9, 2026

    @thomasbachem
    ContributorAuthor

    Yes, though only errors (what the error filter of list_console_messages covers), and some may well be unrelated, as you say. If you mean doing that for every tool call, that sounds better to me, as a click whose handler throws has the same gap.

    Would you keep it to errors? I'd lean that way, since every level after every call gets noisy on chatty pages and the rest is one list_console_messages call away. If that works for you, I'll rework #3431.

  4. added a commit that references this issue on Nov 13, 2026
    d5d30bd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions