### Example Causes for Browser Launch/Connection Errors Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/errors.md Illustrates common error messages that indicate issues with launching or connecting to the browser. These can stem from missing browser installations, network problems, or protocol mismatches. ```text Failed to launch: Error: Failed to find Chromium Failed to launch/connect to browser: ECONNREFUSED - Connection refused at ws://localhost:9222 Failed to launch/connect to browser: protocol not supported ``` -------------------------------- ### HeaderObject Example Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/types.md An example of how to structure HTTP headers using the HeaderObject interface. ```json { "parameter": [ { "name": "Authorization", "value": "Bearer token" }, { "name": "User-Agent", "value": "Custom/1.0" } ] } ``` -------------------------------- ### QueryParameter Example Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/types.md An example of a single URL query parameter. ```json { "name": "search", "value": "puppeteer" } ``` -------------------------------- ### Example Query Parameters Configuration Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Demonstrates how to configure query parameters for a URL. These parameters are appended to the target URL when the operation is getPageContent, getScreenshot, or getPDF. ```javascript queryParameters.parameters = [ { name: "search", value: "puppeteer" }, { name: "page", value: "1" } ] ``` -------------------------------- ### Header/Footer Template Syntax Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md Shows an example HTML template for headers and footers, utilizing special placeholder classes for dynamic content. ```html
Document Title - Printed Date
``` -------------------------------- ### Script: File Download Capture Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md Example of initiating a file download and capturing it when the 'captureDownloads' option is enabled. Downloaded files are automatically attached as binary data. ```javascript await $page.goto('https://example.com/downloads'); // Click download button await $page.click('#download-pdf'); // Wait for download await $page.waitForTimeout(2000); // Downloaded files are automatically attached as binary data return [{ success: true }]; ``` -------------------------------- ### Proxy Server Configuration Examples Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Configure custom proxy settings for all browser connections. Supports various formats including HTTP, SOCKS, per-protocol mapping, and direct connections. ```string localhost:8080 ``` ```string socks5://localhost:1080 ``` ```string http=foopy:80;ftp=foopy2 ``` ```string direct:// ``` -------------------------------- ### Example Output for getScreenshot Operation Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/internal-functions.md This JSON structure shows the output for the `getScreenshot` operation. It contains metadata like headers and URL, along with binary image data. ```json { "json": { "headers": { ... }, "statusCode": 200, "url": "https://example.com" }, "binary": { "data": { "data": "", "mimeType": "image/png", "fileName": "..." } } } ``` -------------------------------- ### ErrorResponse Example Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/types.md An example of an error response structure, including error details and the input item index. ```json { "json": { "error": "Request failed with status code 404", "url": "https://example.com/missing", "statusCode": 404 }, "pairedItem": { "item": 0 } } ``` -------------------------------- ### Launch Local Browser Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/README.md Launches a local browser instance using Puppeteer. Recommended for Docker setups. Ensure Chrome dependencies are met. ```typescript browser = await puppeteer.launch({ headless: true, args: [...], executablePath: "/path/to/chromium" }); ``` -------------------------------- ### Example Causes for Invalid URL Errors Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/errors.md Shows examples of invalid URL strings that will trigger an error. This includes non-HTTP/HTTPS protocols, missing protocols, and non-URL strings. ```text Invalid URL: not a url Invalid URL: ftp://example.com (protocol not supported) Invalid URL: example (missing protocol) ``` -------------------------------- ### Example Output for getPDF Operation Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/internal-functions.md This JSON structure illustrates the output for the `getPDF` operation. It includes response metadata and the generated PDF as binary data. ```json { "json": { "headers": { ... }, "statusCode": 200, "url": "https://example.com" }, "binary": { "data": { "data": "", "mimeType": "application/pdf", "fileName": "..." } } } ``` -------------------------------- ### Setup Download Capture with CDP Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/internal-functions.md Sets up a Chrome DevTools Protocol (CDP) session to intercept and capture downloaded files. It creates a temporary directory for downloads and provides a cleanup function. ```typescript async function setupDownloadCapture( page: Page, ): Promise<{ downloadPath: string; cleanup: () => void }> { // ... implementation details ... return { downloadPath: '', cleanup: () => {} }; } ``` -------------------------------- ### Script with AI Agent Input Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md When used as an AI tool, receive input via `$input.query`. This example navigates to a URL and extracts the page title and all link data. ```javascript const url = $input.query || 'https://example.com'; await $page.goto(url); const data = await $page.evaluate(() => { return { title: document.title, links: Array.from(document.querySelectorAll('a')).map(a => ({ text: a.textContent, href: a.href })) }; }); return [data]; ``` -------------------------------- ### Install n8n-nodes-puppeteer Manually Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/README.md Installs the n8n-nodes-puppeteer package into an existing n8n installation. Ensure you are in the n8n root directory before running. ```bash # Navigate to your n8n root directory cd /path/to/n8n # Install the package npm install n8n-nodes-puppeteer ``` -------------------------------- ### PDF Footer Template Example Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Define an HTML template for the PDF footer, supporting special classes for dynamic content. ```html
``` -------------------------------- ### PDF Header Template Example Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Define an HTML template for the PDF header, supporting special classes for dynamic content. ```html
- Page
``` -------------------------------- ### Run n8n with Fresh Data using Docker Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/README.md Runs the n8n container without persistent data, providing a clean start for testing or development. All data will be lost upon container stop. ```bash npm run docker:run:fresh ``` -------------------------------- ### Run Browserless Chromium Docker Container Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/README.md This command starts a Docker container for Browserless Chromium, exposing it on port 3000. It's a self-hosted option for remote browser connections. ```bash docker run -p 3000:3000 -e "TOKEN=6R0W53R135510" ghcr.io/browserless/chromium ``` -------------------------------- ### Get PDF Operation Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/00-START-HERE.md Use this operation to generate a PDF document from a webpage. You can specify the paper format (e.g., A4). The output is the PDF document as binary data. ```json { "operation": "getPDF", "url": "https://example.com", "format": "A4" } ``` -------------------------------- ### Get Available Devices for Emulation Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/puppeteer-node.md Retrieves a list of device emulation profiles supported by Puppeteer. Use this to populate device selection options in your n8n workflow. ```typescript const devices = await node.methods.loadOptions.getDevices(); // Returns: [ // { name: "iPhone 12", value: "iPhone 12", description: "390 x 844 @ 3x" }, // { name: "iPad Pro", value: "iPad Pro", description: "1024 x 1366 @ 2x" }, // ... // ] ``` -------------------------------- ### Basic Script: Navigate and Extract Data Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md A fundamental example demonstrating navigation to a URL and extracting specific data from the page's DOM using Puppeteer's $page object. ```javascript // Navigate to page await $page.goto('https://example.com'); // Extract data const data = await $page.evaluate(() => { return { title: document.title, text: document.body.innerText }; }); // Return results return [{ data }]; ``` -------------------------------- ### Valid Script Return Values Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md Scripts must return an array of items. Examples show valid array formats, including empty arrays, and highlight invalid non-array return types. ```javascript // Valid returns: return [{ key: "value" }]; return [{ data: result, timestamp: new Date() }]; return [{ json: { nested: "data" } }]; return []; // empty array is valid // Invalid returns: return { key: "value" }; // NOT in array return "string"; // NOT an array return null; // NOT an array // Script fails with: "Custom script must return an array..." ``` -------------------------------- ### Get Screenshot Operation Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/00-START-HERE.md Use this operation to capture a screenshot of a webpage. You can specify the image type (e.g., png, jpeg, webp). The output is the image data in binary format. ```json { "operation": "getScreenshot", "url": "https://example.com", "imageType": "png" } ``` -------------------------------- ### Example Output for getPageContent Operation Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/internal-functions.md This JSON structure represents the output when using the `getPageContent` operation with `processPageOperation`. It includes the HTML body, response headers, status code, and the final URL. ```json { "json": { "body": "...", "headers": { "content-type": "text/html" }, "statusCode": 200, "url": "https://example.com" } } ``` -------------------------------- ### Recommended Container Arguments Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Automatically adds arguments suitable for containerized environments. Disable only if experiencing browser launch issues. ```bash --no-sandbox ``` ```bash --disable-setuid-sandbox ``` ```bash --disable-dev-shm-usage ``` ```bash --disable-gpu ``` -------------------------------- ### Get Page Content with Puppeteer Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/puppeteer-node.md Retrieves the full HTML content of a specified URL. Requires the URL and operation type. ```javascript { "operation": "getPageContent", "url": "https://example.com" } ``` -------------------------------- ### Basic PDF Configuration Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md A simple configuration to generate a PDF from a URL with basic formatting options. ```json { "operation": "getPDF", "url": "https://example.com", "dataPropertyName": "pdf", "options": { "format": "A4", "landscape": false } } ``` -------------------------------- ### Read and Prepare Downloaded Files Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/internal-functions.md Reads downloaded files from a specified directory and prepares them as binary data for n8n. This function is used after download capture to process the files into a usable format. ```typescript async function getDownloadedFiles( downloadPath: string, helpers: IExecuteFunctions["helpers"], ): Promise { // ... implementation details ... return {}; } ``` -------------------------------- ### Batch Processing Configuration Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md Configure batch processing for operations like getScreenshot using the 'batchSize' option. A smaller batch size increases stability but reduces speed, while a larger size risks higher resource usage. ```json { "operation": "getScreenshot", "url": "https://example.com", "dataPropertyName": "screenshot", "options": { "batchSize": 3 } } ``` -------------------------------- ### Device Emulation for getScreenshot Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md This configuration demonstrates capturing a screenshot with specific device emulation and quality settings. It captures only the viewport and sets a quality level for JPEG or WebP images. ```json { "operation": "getScreenshot", "url": "https://example.com", "imageType": "png", "dataPropertyName": "mobile_screenshot", "fullPage": false, "options": { "device": "iPhone 12", "quality": 85 } } ``` -------------------------------- ### Screenshot Full Page Configuration Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Capture the entire scrollable page content instead of just the viewport. ```json { "operation": "getScreenshot", "fullPage": true } ``` -------------------------------- ### PDF with Headers and Footers Configuration Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md Configuration for generating a PDF that includes custom headers, footers, and specific margins. ```json { "operation": "getPDF", "url": "https://example.com/report", "dataPropertyName": "pdf", "format": "A4", "landscape": false, "displayHeaderFooter": true, "headerTemplate": "
", "footerTemplate": "
Page of
", "margin": { "top": "1cm", "bottom": "1.5cm", "left": "1cm", "right": "1cm" }, "options": { "fileName": "report.pdf" } } ``` -------------------------------- ### Project File Structure Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/README.md Overview of the directory and file layout for the n8n-nodes-puppeteer project. ```bash /workspace/home/n8n-nodes-puppeteer/ ├── nodes/Puppeteer/ │ ├── Puppeteer.node.ts (844 lines, main node implementation) │ ├── Puppeteer.node.options.ts (910 lines, configuration definitions) │ ├── types.d.ts (module declarations) │ └── puppeteer.svg (node icon) ├── package.json (dependencies, scripts) ├── docker/ (Docker setup files) ├── README.md (user documentation) └── tsconfig.json (TypeScript configuration) ``` -------------------------------- ### Get Page Content Operation Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/00-START-HERE.md Use this operation to extract the HTML content of a given URL. It returns the HTML string along with response headers and the status code. ```json { "operation": "getPageContent", "url": "https://example.com" } ``` -------------------------------- ### Enable Automatic Container Arguments Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/README.md Setting `addContainerArgs` to `true` enables the automatic detection and optimization of container arguments for Puppeteer. This simplifies setup by handling environment-specific configurations. ```json { "addContainerArgs": true } // Auto-detects and optimizes ``` -------------------------------- ### Script: Form Interaction and Login Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md Illustrates how to interact with web forms, including typing into input fields, clicking buttons, and waiting for navigation after submission. ```javascript await $page.goto('https://example.com/login'); // Fill form await $page.type('#email', 'user@example.com'); await $page.type('#password', 'password123'); // Submit await $page.click('#submit-button'); // Wait for navigation await $page.waitForNavigation(); // Extract logged-in content const content = await $page.evaluate(() => { return document.querySelector('.user-profile').innerText; }); return [{ loggedInContent: content }]; ``` -------------------------------- ### Common Launch Arguments for Puppeteer Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Pass these command line arguments to the browser instance for specific behaviors. Ensure they are compatible with your browser version. ```bash --window-size=1920,1080 ``` ```bash --disable-notifications ``` ```bash --disable-popup-blocking ``` ```bash --no-first-run ``` -------------------------------- ### File Name Configuration for PDF/Screenshot Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Specify the output filename for PDF or screenshot operations. ```json { "operation": "getPDF", "fileName": "my-document.pdf" } ``` -------------------------------- ### PDF Scale Configuration Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Set the rendering scale for the PDF. Must be between 0.1 and 2. ```json { "operation": "getPDF", "scale": 0.8 } ``` -------------------------------- ### NodeVM Options Interface Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/types.md Defines the configuration options for the NodeVM constructor, used for executing custom scripts in a sandboxed environment. Options control console output, available global variables, module resolution, and WebAssembly support. ```typescript interface NodeVMOptions { console?: "inherit" | "redirect"; sandbox?: Record; require?: VMRequire; wasm?: boolean; } ``` -------------------------------- ### Browser Connection Error Response Example Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/errors.md This JSON structure shows an error when the node fails to connect to or launch the browser. The 'ECONNREFUSED' error commonly points to issues with the browser service. ```json { "json": { "error": "Failed to launch/connect to browser: ECONNREFUSED" }, "pairedItem": { "item": 0 } } ``` -------------------------------- ### Container Optimized Launch Arguments Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/internal-functions.md Chrome command-line arguments optimized for containerized environments such as Docker or Kubernetes. ```typescript const CONTAINER_LAUNCH_ARGS = [ "--no-sandbox", "--disable-setuid-sandbox", "--disable-dev-shm-usage", "--disable-gpu", ]; ``` -------------------------------- ### Get Page Content Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md Navigates to a URL and retrieves the full HTML content, response headers, status code, and final URL. Use this for extracting raw HTML for parsing or auditing. ```json { "json": { "body": "...[full HTML content]...", "headers": { "content-type": "text/html; charset=utf-8", "content-length": "12345", "server": "nginx/1.19.0", "[other headers]": "[values]" }, "statusCode": 200, "url": "https://example.com?search=puppeteer&page=1" }, "pairedItem": { "item": 0 } } ``` ```json { "json": { "searchTerm": "puppeteer" } } ``` ```json { "operation": "getPageContent", "url": "https://example.com/search", "queryParameters": { "parameters": [ { "name": "q", "value": "puppeteer" } ] }, "options": { "timeout": 30000, "waitUntil": "load" } } ``` ```json { "json": { "body": "Search Results...", "headers": { "content-type": "text/html" }, "statusCode": 200, "url": "https://example.com/search?q=puppeteer" } } ``` -------------------------------- ### Script Execution Error Response Example Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/errors.md This JSON structure indicates an error during custom script execution, typically when the script does not return data in the expected format. It highlights the specific error message. ```json { "json": { "error": "Custom script must return an array of items..." }, "pairedItem": { "item": 0 } } ``` -------------------------------- ### Margin Specification with Units Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md Demonstrates how to specify margins with different unit types like centimeters, inches, and millimeters. ```json { "margin": { "top": "1cm", // cm (centimeters) "bottom": "0.5in", // in (inches) "left": "10mm", // mm (millimeters) "right": "1.5cm" // mixed units } } ``` -------------------------------- ### PDF Landscape Orientation Configuration Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Enable landscape orientation for the PDF output. ```json { "operation": "getPDF", "landscape": true } ``` -------------------------------- ### HTTP Status Code Error Response Example Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/errors.md This JSON structure represents an error response when an HTTP request fails due to a non-2xx status code. It includes details like the error message, URL, status code, and response headers. ```json { "json": { "error": "Request failed with status code 404", "url": "https://example.com/nonexistent", "statusCode": 404, "headers": { "content-type": "text/html" } }, "pairedItem": { "item": 0 } } ``` -------------------------------- ### Configure Navigation Wait Condition Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Specify when a navigation is considered successful. Options include 'load', 'domcontentloaded', 'networkidle0', and 'networkidle2'. This setting is ignored for 'Run Custom Script'. ```javascript options.waitUntil = "networkidle2"; ``` -------------------------------- ### Set Browser Executable Path Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Provide a direct path to the browser executable if not using a WebSocket endpoint. If omitted, the bundled Chromium will be used. ```javascript options.executablePath = "/usr/bin/google-chrome"; ``` -------------------------------- ### Configure Remote Firefox via Environment Variables Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/README.md Sets environment variables to configure the n8n-puppeteer container to connect to a remote Firefox instance using the WebDriver BiDi protocol. This is the recommended global configuration method. ```bash docker run -it -p 5678:5678 \ -e PUPPETEER_BROWSER_WS_ENDPOINT=ws://firefox:4444 \ -e PUPPETEER_PROTOCOL=webDriverBiDi \ n8n-puppeteer ``` -------------------------------- ### Enable Container Arguments Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/README.md When running in a container, set `addContainerArgs: true` to enable container arguments for the browser. ```json addContainerArgs: true ``` -------------------------------- ### Test Responsive Design with Screenshot Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/00-START-HERE.md Capture a screenshot of a webpage, emulating a specific device like the 'iPhone 12', to test its responsive design. The 'fullPage' option captures the entire scrollable page. ```json { "operation": "getScreenshot", "url": "https://example.com", "imageType": "png", "fullPage": true, "options": { "device": "iPhone 12" } } ``` -------------------------------- ### Screenshot Image Type Configuration (PNG) Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Set the image format for screenshots to PNG. ```json { "operation": "getScreenshot", "imageType": "png" } ``` -------------------------------- ### Human Typing Options Configuration Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Fine-tune the human typing simulation for input elements. Adjust delays, typo probabilities, and keyboard layout. ```json { "minimumDelayInMs": 150, "maximumDelayInMs": 650, "backspaceMinimumDelayInMs": 750, "backspaceMaximumDelayInMs": 1500, "typoChanceInPercent": 15, "chanceToKeepATypoInPercent": 0, "keyboardLayout": "en" } ``` -------------------------------- ### Generate PDF Invoices Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/00-START-HERE.md Configure the node to generate a PDF document from a given URL, suitable for tasks like creating invoices. Options include paper format, header/footer display, and margins. ```json { "operation": "getPDF", "url": "https://example.com/invoice", "format": "A4", "displayHeaderFooter": true, "headerTemplate": "
Invoice
", "margin": { "top": "1cm", "bottom": "1cm" } } ``` -------------------------------- ### Generate PDF with Headers and Footers Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/README.md Use the 'getPDF' operation to generate a PDF document from a URL. Customize the PDF with display options for headers and footers. ```javascript operation: "getPDF" url: "https://example.com/report" options: { format: "A4", displayHeaderFooter: true, headerTemplate: "...", footerTemplate: "..." } ``` -------------------------------- ### PDF Print Background Configuration Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Include background graphics and images in the PDF output. ```json { "operation": "getPDF", "printBackground": true } ``` -------------------------------- ### Enable Production Logging Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/README.md Set the CODE_ENABLE_STDOUT environment variable to true to enable production logging. Logs will include workflow context. ```bash CODE_ENABLE_STDOUT=true ``` -------------------------------- ### File Download Output Format Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md Shows the structure of the output when files are captured during a download operation, including binary data, mime type, and file name. ```json { "json": { "success": true }, "binary": { "document.pdf": { "data": "", "mimeType": "application/pdf", "fileName": "document.pdf" } } } ``` -------------------------------- ### PDF Omit Background Configuration Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Hide the default white background to allow for transparent PDF generation. ```json { "operation": "getPDF", "omitBackground": true } ``` -------------------------------- ### Screenshot with Device Emulation Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Capture a screenshot of a webpage, emulating a specific device. Supports various image formats and options for full-page screenshots and image quality. ```json { "operation": "getScreenshot", "url": "https://example.com", "dataPropertyName": "screenshot", "imageType": "png", "fullPage": true, "options": { "device": "iPhone 12", "quality": 90 } } ``` -------------------------------- ### Configure Remote Chrome via Environment Variables Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/README.md Sets environment variables to configure the n8n-puppeteer container to connect to a remote Chrome instance using the CDP protocol. This is the recommended global configuration method. ```bash docker run -it -p 5678:5678 \ -e PUPPETEER_BROWSER_WS_ENDPOINT=ws://browserless:3000 \ -e PUPPETEER_PROTOCOL=cdp \ n8n-puppeteer ``` -------------------------------- ### AI Agent Provides Dynamic Input Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/README.md This snippet shows how an AI agent can provide input dynamically to a reusable script. The 'query' parameter is populated by the AI, specifying the website URL to scrape. ```javascript query: $fromAI('url', 'The website URL to scrape') ``` -------------------------------- ### Firefox with WebDriver BiDi Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Connect to a Firefox browser using the WebDriver BiDi protocol. This enables advanced debugging and control capabilities for Firefox instances. ```json { "operation": "runCustomScript", "scriptCode": "await $page.goto('https://example.com');\nreturn [{ success: true }];", "options": { "browserWSEndpoint": "ws://firefox:4444", "protocol": "webDriverBiDi" } } ``` -------------------------------- ### Custom Headers and Proxy Server Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Configure custom HTTP headers and a proxy server for requests. This is useful for authentication, setting user agents, or routing traffic through a proxy. ```json { "operation": "getPageContent", "url": "https://api.example.com/data", "options": { "headers": { "parameter": [ { "name": "Authorization", "value": "Bearer token123" }, { "name": "User-Agent", "value": "CustomBot/1.0" } ] }, "proxyServer": "localhost:8080" } } ``` -------------------------------- ### Run n8n with Persistent Data using Docker Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/README.md Runs the n8n container with a persistent data volume, ensuring workflow data is saved between restarts. Recommended for development and production. ```bash npm run docker:run ``` -------------------------------- ### Output Item Normalization Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md Demonstrates how the script's returned array is normalized into n8n's standard output item format, including 'json' and 'pairedItem' properties. ```json [ { "json": { "key": "value", "anotherKey": "anotherValue" }, "pairedItem": { "item": 0 } } ] ``` -------------------------------- ### getDevices() Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/puppeteer-node.md Retrieves a list of device emulation profiles available in Puppeteer. This method is useful for configuring device settings in browser automation tasks. ```APIDOC ## getDevices() ### Description Retrieves a list of device emulation profiles available in Puppeteer. ### Method `getDevices` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Returns `Promise` - An array of device options, each containing `name`, `value`, and `description`. ### Example ```javascript const devices = await node.methods.loadOptions.getDevices(); // Returns: [ // { name: "iPhone 12", value: "iPhone 12", description: "390 x 844 @ 3x" }, // { name: "iPad Pro", value: "iPad Pro", description: "1024 x 1366 @ 2x" }, // ... // ] ``` ``` -------------------------------- ### Screenshot Image Type Configuration (JPEG) Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Set the image format for screenshots to JPEG. ```json { "operation": "getScreenshot", "imageType": "jpeg" } ``` -------------------------------- ### PDFOptions Interface Definition Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/types.md Configuration options for generating PDFs using `page.pdf()`. Customize scale, format, margins, headers/footers, and output path. ```typescript interface PDFOptions { scale?: number; displayHeaderFooter?: boolean; headerTemplate?: string; footerTemplate?: string; printBackground?: boolean; landscape?: boolean; pageRanges?: string; format?: PaperFormat; width?: string | number; height?: string | number; margin?: { top?, bottom?, left?, right? }; path?: string; omitBackground?: boolean; preferCSSPageSize?: boolean; } ``` -------------------------------- ### Script: Human-like Typing Simulation Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md Demonstrates using the `typeHuman` function, available when the `humanTyping` option is enabled, to simulate natural typing with delays and potential typos. ```javascript await $page.goto('https://example.com/form'); // When humanTyping option is enabled, this function available: await $page.typeHuman('#search-input', 'search query'); // typeHuman() simulates natural typing with delays and typos return [{ success: true }]; ``` -------------------------------- ### Screenshot Quality Configuration Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/configuration.md Set the image quality for JPEG or WebP screenshots. Range is 0-100. ```json { "operation": "getScreenshot", "imageType": "jpeg", "quality": 80 } ``` -------------------------------- ### Return Value Structure Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md Illustrates the expected JSON structure for the return value, including status, headers, URL, and the binary PDF data. ```json { "json": { "statusCode": 200, "headers": { "[response headers]": "[values]" }, "url": "https://example.com" }, "binary": { "[dataPropertyName]": { "data": "%PDF-1.4...[PDF binary data]...", "mimeType": "application/pdf", "fileName": "document.pdf" } }, "pairedItem": { "item": 0 } } ``` -------------------------------- ### Script: Error Handling and Conditional Logic Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/operations.md Shows how to implement robust error handling using try-catch blocks and conditional logic to check for element existence before extraction. ```javascript try { await $page.goto('https://example.com', { timeout: 5000 }); const exists = await $page.$('.target-element') !== null; if (!exists) { return [{ error: 'Element not found', success: false }]; } const data = await $page.evaluate(() => { return document.querySelector('.target-element').textContent; }); return [{ data, success: true }]; } catch (error) { return [{ error: error.message, success: false }]; } ``` -------------------------------- ### Capture Screenshot with Device Emulation Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/README.md Use the 'getScreenshot' operation to capture an image of a webpage. Configure device emulation and full page capture for visual testing. ```javascript operation: "getScreenshot" url: "https://example.com" options: { device: "iPhone 12", fullPage: true } ``` -------------------------------- ### Default User Agent String Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/api-reference/internal-functions.md The default user agent string used for requests when no custom user agent is provided. ```typescript const DEFAULT_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36"; ``` -------------------------------- ### Manual Retry Logic Implementation Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/errors.md This JavaScript code demonstrates how to implement a manual retry mechanism for operations that might fail. It includes a loop with a maximum number of attempts and a delay between retries. ```javascript let maxRetries = 3; let attempts = 0; let success = false; while (!success && attempts < maxRetries) { try { // Node execution success = true; } catch (error) { attempts++; if (attempts < maxRetries) { // Wait before retry await new Promise(r => setTimeout(r, 1000 * attempts)); } } } ``` -------------------------------- ### getPDF Source: https://github.com/drudge/n8n-nodes-puppeteer/blob/main/_autodocs/00-START-HERE.md Generates a PDF document from a given URL. ```APIDOC ## getPDF ### Description Generates a PDF document from a given URL. ### Method POST ### Endpoint /execute ### Parameters #### Request Body - **operation** (string) - Required - The name of the operation to perform. Should be "getPDF". - **url** (string) - Required - The URL of the page to generate a PDF from. - **format** (string) - Optional - The paper format for the PDF. Defaults to "A4". ### Request Example ```json { "operation": "getPDF", "url": "https://example.com", "format": "A4" } ``` ### Response #### Success Response (200) - **data** (binary) - The generated PDF document as binary data. #### Response Example (Binary PDF data) ```