Overview
This node allows users to run custom JavaScript scripts using Puppeteer, a 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 navigate web pages, extract data, take screenshots, or perform other browser-based tasks. For example, a user can write a script to visit a website, extract the IP address shown on the page, and return it as output.
Use Case Examples
- Extracting IP address from a web service by navigating to the page and parsing the response.
- Taking screenshots of web pages automatically for monitoring or testing purposes.
- Running custom scripts to interact with web pages, fill forms, or scrape data.
Properties
| Name | Meaning |
|---|---|
| Script Code | JavaScript code to execute with Puppeteer. This script has access to Puppeteer's $browser and $page objects to control the browser and page. The script must return an array of items as output. |
| Query (AI Agent Input) | Input query for AI agents. When used as a tool by an AI agent, the agent's query or instruction is passed here and can be accessed in the script via $input.query. |
| Options | Various Puppeteer launch and page options such as batch size, browser WebSocket endpoint, protocol, device emulation, executable path, headers, launch arguments, timeout settings, headless mode, stealth mode, human typing mode, proxy server, download capture, and container arguments. |
Output
JSON
ip- Extracted IP address or other data returned by the custom script.
Dependencies
- puppeteer-extra
- puppeteer-extra-plugin-stealth
- puppeteer-extra-plugin-human-typing
- puppeteer
- vm2
Troubleshooting
- Ensure the custom script returns an array of items; otherwise, an error is thrown.
- If the browser fails to launch, check the executable path, launch arguments, and container environment settings.
- Timeouts and navigation errors may occur if the target page is slow or unreachable; adjust timeout settings accordingly.
- When using browser WebSocket endpoint, ensure the URL is correct and the browser instance is accessible.
- If downloads are not captured, verify that 'Capture Downloads' option is enabled and the script triggers downloads properly.
Links
- Special vars/methods for Puppeteer in n8n - Documentation on special variables and methods available in Puppeteer scripts within n8n.