Run Custom Script
AI-generatedSummary
Execute custom JavaScript code within a remote Playwright browser context, using provided special variables to interact directly with the Playwright API for complex browser automation tasks.
Inputs
- Script Code (required) — JavaScript code to execute with access to Playwright objects $page (web page), $browser (Playwright browser instance), $playwright (Playwright API), and all n8n Code node variables. Your script must return an array of item objects to produce output.
Output shape
a list of items matching n8n's data structure, where each item can contain JSON data and optionally binary data such as screenshots or other files.
The script must return an array of item objects (each with a json property, optionally binary) exactly. Console.log output from the script is redirected and can be viewed for debugging. Errors during execution throw a node operation error unless 'continue on fail' is set, in which case an error item is returned.
Examples
Example 1: Run a script that navigates programmatically, extracts data, and takes a screenshot, then returns JSON and binary results.
Provide JavaScript code in the Script Code parameter that uses $page to control navigation and capture data, and returns an array of item objects with JSON and binary properties.