Playwright Automation icon

Playwright Automation

Playwright Automation for n8n

Script → Run Script

AI-generated

Summary

Execute custom JavaScript within an active Playwright session; the script's return value is captured and included in the output.

Inputs

  • sessionId (required) — Identifier of an existing Playwright session. The script executes within the page and context associated with this session.
  • scriptCode (required) — Custom JavaScript code to execute. Has access to 'page' and 'context' objects. The return value of this code becomes the 'returnValue' in the operation output.
  • errorHandling — Reserved for error handling configuration; not actively used in the core execution of the Run Script operation.
  • screenshotOnFail — If enabled, a screenshot will be captured and attached to any error that occurs during script execution, linked to the error in the n8n workflow.

Output shape

object

Each output item's 'json' field contains the result from the executed script. The returned object always includes 'success': true, 'action': 'runScript', 'returnValue' (the value returned by the script code), and 'executionTimeMs' (time in milliseconds). If the script throws, the error is propagated per n8n error handling rules, and 'screenshotOnFail' determines whether an error screenshot is attached.

Examples

Example 1: Return the page title

Set sessionId to an existing session ID and scriptCode to 'return await page.title();'. The operation returns { success: true, action: 'runScript', returnValue: 'Page Title', executionTimeMs: }.

Links

Discussion