Overview
This node enables browser automation using the Playwright library within n8n workflows. It allows users to run custom Node.js scripts that control browsers such as Chromium, Firefox, and WebKit (Safari). The node supports multiple modes of operation including launching new browser sessions, interacting with existing sessions, closing sessions, running fully custom scripts with manual browser lifecycle management, and a managed mode where browser and page instances are automatically handled.
Common use cases include:
- Web scraping or data extraction from websites.
- Automated testing or interaction with web pages.
- Taking screenshots or generating PDFs of web content.
- Running complex browser automation workflows with reusable sessions.
Practical examples:
- Launch a new Chromium browser session, navigate to a URL, extract headings, and take a screenshot.
- Interact with an existing browser session to perform additional navigation or data extraction.
- Run a fully custom script controlling the entire browser lifecycle for advanced automation scenarios.
- Use the managed mode to simplify scripting by handling browser/page setup and cleanup automatically.
Properties
| Name | Meaning |
|---|---|
| Browser Type | Selects the browser engine to use: Chromium (fastest), Firefox, or WebKit (Safari). |
| Script Mode | Defines how browser instances are managed: - Browser Close: Manually close browser session(s). - Browser Interact: Interact with an existing browser session. - Browser Launch: Launch a new session and return its ID. - Custom Script: Full control over browser lifecycle in a user-provided script. - Managed Browser: Automatic management of browser and page instances with simplified scripting. |
| Node.js Script | Custom JavaScript code executed in Managed Browser mode. Provides ready-to-use page and browser instances along with input data variables. |
| Custom Script | Custom JavaScript code executed in Custom Script mode. User manages full browser lifecycle manually using Playwright API. |
| Session ID | Identifier of the browser session to interact with or close. Required for Browser Interact and Browser Close modes unless closing all sessions. |
| Interaction Script | JavaScript code executed on the page instance in Browser Interact mode. Allows navigation, interaction, and data extraction using the provided page and browser objects. |
| Close All Sessions | Boolean flag for Browser Close mode to close all active browser sessions, ignoring any specific session ID. |
| Reuse Pages | Boolean flag for Browser Interact mode to reuse page instances within the same session for performance optimization. |
| Browser Options | Collection of options to configure browser behavior: - Default Timeout (ms) - Headless mode (true/false) - Ignore HTTPS errors (true/false) - Navigation Timeout (ms) - User Agent string - Viewport Width & Height (pixels) |
| Reuse Browser | Boolean flag for Managed Browser mode to reuse the browser instance across multiple items for better performance. |
| Continue on Fail | Whether to continue processing subsequent items if the script fails on one item. |
Output
The node outputs an array of JSON objects, each corresponding to an input item processed. The structure of the output depends on the script mode and the user-defined scripts but generally includes:
success: Boolean indicating if the operation succeeded.resultor other custom fields returned by the user script.itemIndex: Index of the processed input item.- In case of failure (if "Continue on Fail" is enabled), an error message and timestamp.
Typical returned data may include:
- Extracted webpage data such as titles, headings, URLs.
- Base64-encoded screenshots.
- Session IDs when launching new browser sessions.
- Arbitrary JSON data returned by custom scripts.
If binary data like screenshots is produced, it is encoded as base64 strings in the JSON output.
Dependencies
- Requires the Playwright library installed in the n8n environment (
npm install playwright). - No internal credential types are exposed; however, users must ensure appropriate network access and permissions for browser automation.
- No external API keys are required by default, but custom scripts can integrate with other services as needed.
- The node uses standard n8n configurations and does not require special environment variables beyond those needed for Playwright.
Troubleshooting
- Playwright Not Installed Error: If the node throws an error about Playwright not being installed, run
npm install playwrightin your n8n environment. - Missing Session ID: For "Browser Interact" and "Browser Close" modes, a session ID must be provided unless closing all sessions. Omitting this will cause an error.
- Script Execution Failures: Errors in user-provided scripts will stop execution unless "Continue on Fail" is enabled. Check script syntax and runtime logic carefully.
- Resource Cleanup: When reusing browsers or pages, improper cleanup might lead to resource leaks. The node attempts automatic cleanup unless reuse flags are set.
- Timeouts: Adjust browser timeouts in "Browser Options" if pages load slowly or operations take longer than expected.
- Headless Mode Issues: Some websites detect headless browsers and block them. Try disabling headless mode or customizing the user agent string.