Skip to main content
python_script_action lets you run arbitrary Python code against the live Playwright page object—covering anything that standard interaction actions cannot express.

Overview

  • Use when: Built-in actions are insufficient (complex DOM manipulation, custom scrolling, dispatching browser events, reading element properties).
  • Execution: The runner execs your script, finds an async function named code_fn, and calls it with the current Playwright page.
  • No output: This action does not return or store data. To extract data with custom code, use extraction_action.python_script.

Properties

Script Contract

Your script must define an async function named code_fn that accepts a single page argument (a Playwright Page):
The function is called as await code_fn(page). Any return value is ignored.

JSON Example

Common Patterns

Scroll to the bottom of the page

Wait for a custom JavaScript condition

Dispatch a custom browser event

Interact with a shadow DOM element

execution_code is evaluated with exec(). Only run scripts from trusted sources.

Python Script Extraction

To extract data from the page using custom code, use python_script inside an extraction_action instead. The contract is different: the function receives (axtree, browser) and must return a dict containing the extracted values.

Properties

Script Contract

The returned dict is stored as OutputData and, if output_variable_names is set, the specified keys are promoted to generated_variables for use in later nodes.
All keys in output_variable_names must exist in extraction_format, or schema validation will fail.

Action vs Extraction — Which to Use