page, context, and a persistent state object.
Parameters
JavaScript Playwright code to execute. Has
{page, state, context} in scope.Should be one line, using ; to execute multiple statements. You MUST call execute multiple times instead of writing complex scripts in a single tool call.Timeout in milliseconds for code execution.Default:
10000 (10 seconds)Response
Array of content items returned from the execution.
Whether the execution resulted in an error
Usage Examples
Navigate to a page
Click an element
Get text content
Take a screenshot
Use persistent state
state object persists across execute calls until reset.
Multiple statements
Error Handling
Timeout errors
If code execution exceeds the timeout, an error response is returned:Connection errors
If there are CDP connection issues or the browser/page is closed:reset tool to re-establish the connection.
Code execution errors
If the JavaScript code throws an error:Best Practices
- Keep code simple - one logical operation per execute call
- Use appropriate timeouts for slow operations (e.g., navigation, network requests)
- Store intermediate results in
statefor multi-step workflows - Handle errors appropriately - use
resetonly for connection issues - Use semicolons to chain multiple statements on one line when needed