Overview
This node allows users to run custom JavaScript scripts using Puppeteer, a headless browser automation library. It is useful for web scraping, automated testing, or any scenario where browser interaction is needed programmatically. Users can write scripts that interact with web pages, extract data, take screenshots, or generate PDFs. For example, a user can navigate to a website, extract the IP address displayed on the page, and return it as output.
Use Case Examples
- Extracting IP address from a web page by navigating to an IP lookup service and returning the IP.
- Taking screenshots of web pages for visual testing or archiving.
- Generating PDFs of web pages for reporting or documentation.
Properties
| Name | Meaning |
|---|---|
| Script Code | JavaScript code to execute with Puppeteer. Provides access to Puppeteer's browser and page objects for custom automation tasks. |
| Batch Size | Maximum number of pages to open simultaneously, affecting memory and CPU usage. |
| Browser WebSocket Endpoint | WebSocket URL to connect to an existing browser instance, skipping browser launch. |
| Emulate Device | Option to emulate a specific device's viewport and user agent. |
| Executable path | Path to the browser executable to use with Puppeteer. |
| Extra Headers | Custom HTTP headers to send with requests. |
| File Name | File name for binary data outputs like screenshots or PDFs. |
| Launch Arguments | Additional command line arguments for the browser instance. |
| Timeout | Maximum navigation time in milliseconds; not applicable to custom script operation. |
| Wait Until | Event to consider navigation successful; not applicable to custom script operation. |
| Page Caching | Enable or disable page-level caching. |
| Headless mode | Run browser in headless mode (no UI). |
| Use Chrome Headless Shell | Run browser in headless shell mode, requires chrome-headless-shell in PATH. |
| Stealth mode | Apply techniques to make headless Puppeteer harder to detect. |
| Proxy Server | Custom proxy configuration for Puppeteer. |
| Add Container Arguments | Add recommended arguments for container environments to improve stability. |
Output
JSON
ip- Extracted IP address from the custom script example output.
Dependencies
- puppeteer-extra
- puppeteer-extra-plugin-stealth
- puppeteer
- vm2
Troubleshooting
- Ensure the custom script returns an array of items; otherwise, an error is thrown.
- Browser launch or connection failures may occur if executable path or WebSocket endpoint is incorrect.
- Invalid URLs in navigation operations will cause errors; validate URLs before use.
- Resource limits like batch size affect performance and stability; adjust accordingly.
Links
- Special vars/methods for Puppeteer in n8n - Documentation on special variables and methods available in Puppeteer scripts within n8n.