User Agents

Web browsers and everyday web tech, explained

Install Puppeteer in n8n for Browser Automation

· 4 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to install Puppeteer in n8n so you can automate browser tasks like taking screenshots, scraping dynamic pages, and filling forms. You'll use n8n's Execute Command node to run npm commands inside the n8n container or on your self-hosted server. By the end, you'll have a working Puppeteer setup that can run scripts directly from your n8n workflows.

What You'll Need

  • An n8n instance (self-hosted or Docker) where you have terminal or command-line access.
  • Node.js and npm already installed in the environment where n8n runs (n8n includes these, but you may need to verify).
  • Basic familiarity with n8n workflows and the Execute Command node.
  • For Docker users: a running n8n container with a mounted volume for persistent storage.

Step-by-Step

  1. Access your n8n environment. If using Docker, open a terminal and run docker exec -it /bin/bash to get a shell inside the container. For a local install, open a terminal in the directory where n8n is installed.
  2. Check Node.js and npm versions. Run node -v and npm -v. Ensure Node.js is version 12 or higher. If not, update Node.js before proceeding.
  3. Navigate to the n8n installation directory. In Docker, this is usually /usr/local/lib/node_modules/n8n or wherever npm global packages are stored. For local installs, find the n8n package folder with npm root -g.
  4. Install Puppeteer. Run npm install puppeteer in that directory. This downloads the Puppeteer library and a compatible Chromium browser. Wait for the installation to complete.
  5. Verify installation. Run node -e "const pptr = require('puppeteer'); console.log('Puppeteer version:', pptr.default ? pptr.default.executablePath() : pptr.executablePath())" to confirm Puppeteer is accessible and locate the browser executable.
  6. Handle missing system libraries (Linux only). If you get errors about missing shared libraries when launching Chromium, install them using your package manager. For Ubuntu/Debian, run apt-get update && apt-get install -y libnss3 libatk-bridge2.0-0 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 libgbm1 libasound2.
  7. Create a Puppeteer script. Write a JavaScript file (e.g., screenshot.js) that uses Puppeteer to open a page and take a screenshot. Save it in a location n8n can access, like /home/node in Docker or your n8n working directory.
  8. Test the script manually. Run node screenshot.js in the terminal to ensure it works. Verify that the screenshot file is created.
  9. Add an Execute Command node to your n8n workflow. Drag the Execute Command node onto the canvas. In its configuration, set the command to node /path/to/screenshot.js (or the appropriate path).
  10. Pass parameters dynamically (optional). Use the Execute Command node's "Command" field with a template like and modify your script to accept command-line arguments.
  11. Execute the workflow. Run the workflow to test. Check the output of the Execute Command node for any errors. If successful, the screenshot will be saved to the specified path.

Common Mistakes

  • Installing Puppeteer in the wrong directory – n8n must be able to require it from its own module context.
  • Forgetting to install system dependencies for Chromium on Linux, leading to launch failures.
  • Using puppeteer-core instead of puppeteer – the core version doesn't download Chromium.
  • Running the Execute Command node with a relative path that doesn't exist from n8n's working directory.
  • Not handling asynchronous code properly in the script – ensure you await Puppeteer calls.

Tips

  • Use a Docker volume to persist your scripts and screenshots so they survive container restarts.
  • Set --no-sandbox in Puppeteer launch options if you run as root in Docker (common in containers).
  • Use --disable-dev-shm-usage to avoid shared memory issues in small containers.
  • Keep your Puppeteer scripts in a separate folder and reference them with absolute paths.
  • Test your script outside n8n first to isolate issues.

Troubleshooting

  • Error: "Cannot find module 'puppeteer'" – Reinstall Puppeteer in the correct n8n module directory. Use npm root -g to find the global path.
  • Error: "Failed to launch the browser process" – Install missing system libraries as shown in Step 6. Also try adding --no-sandbox and --disable-setuid-sandbox to the Puppeteer launch options.
  • Error: "Running as root without --no-sandbox is not supported" – Add --no-sandbox to your Puppeteer launch arguments.
  • Screenshots are blank or white – Increase the waitUntil option to 'networkidle0' or add a delay before taking the screenshot.
  • Execute Command node times out – Increase the timeout in the node's settings. Puppeteer scripts can take longer than the default 30 seconds.
  • Puppeteer works in terminal but not in n8n – Check the working directory in the Execute Command node. Use absolute paths for both the script and any output files.

Frequently Asked Questions

Can I use Puppeteer with n8n Cloud?

No, n8n Cloud does not allow custom npm packages or system-level installations. You need a self-hosted n8n instance.

Do I need to install Chromium separately?

No, the puppeteer npm package automatically downloads a compatible Chromium version during installation.

How do I pass data from n8n to my Puppeteer script?

Use command-line arguments in the Execute Command node, like , and parse them in your script.

Can I take screenshots of pages that require login?

Yes, you can use Puppeteer to fill login forms or set cookies before navigating to the target page.

Is Puppeteer the only option for browser automation in n8n?

No, you can also use Playwright or Selenium, but Puppeteer is lightweight and well-documented.

How do I update Puppeteer after n8n updates?

After updating n8n, re-run npm install puppeteer in the n8n module directory to ensure compatibility.