code-playwright

n8n community node for browser automation using Playwright

Package Information

Downloads: 39 weekly / 165 monthly
Latest Version: 0.7.0
Author: warnyin

Documentation

@warnyin/n8n-nodes-code-playwright

npm version
npm downloads
License: MIT

n8n community node for browser automation using Playwright.

Package: @warnyin/n8n-nodes-code-playwright

Table of Contents

About

This n8n community node provides browser automation capabilities using Playwright. It allows you to automate web browsers (Chromium, Firefox, WebKit) directly within your n8n workflows.

Key Features

  • Multi-browser support: Chromium, Firefox, and WebKit
  • Headless or headful mode: Run browsers visibly or in the background
  • Screenshot capture: Take full-page or element screenshots
  • Form automation: Fill forms and click elements
  • Text extraction: Get text content from web pages
  • JavaScript evaluation: Execute custom JS code in page context
  • Wait for elements: Wait for selectors before proceeding

Installation

Option 1: Community Nodes (Recommended)

  1. Open n8n and go to Settings → Community Nodes
  2. Click Install
  3. Enter: @warnyin/n8n-nodes-code-playwright
  4. Accept the risks and install

Option 2: Manual Installation

cd ~/.n8n/nodes
npm install @warnyin/n8n-nodes-code-playwright
# Restart n8n

Option 3: Docker Installation

For Docker environments, ensure your n8n container has Chrome installed:

# Add this to your n8n Dockerfile
FROM node:18-alpine
RUN apk add --no-cache chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
    PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser

Or use the official n8n image with Chrome:

FROM n8nio/n8n
USER root
RUN apt-get update && apt-get install -y \
    google-chrome-stable \
    && rm -rf /var/lib/apt/lists/*
USER node

Then install the node:

docker exec -it <n8n-container> npm install @warnyin/n8n-nodes-code-playwright

Option 4: Local Development & Linking

# Clone, install, and build
git clone https://github.com/warnyin/n8n-nodes-code-playwright.git
cd n8n-nodes-code-playwright
pnpm install
pnpm build

# Link to n8n
npm link
cd ~/.n8n
npm link @warnyin/n8n-nodes-code-playwright
# Restart n8n

Usage

Basic Parameters

Parameter Description
Operation The browser action to perform
URL The webpage URL to navigate to
Browser Browser engine: Chromium, Firefox, or WebKit
Browser Options Headless mode, slow motion settings

Operations

Navigate

Navigate to a URL and return the page content.

Take Screenshot

Capture a screenshot of the webpage.

  • Full Page: Capture entire scrollable page
  • Property Name: Binary property name for the screenshot

Get Text

Extract text content from an element using CSS selector.

Click Element

Click on an element specified by CSS selector.

Fill Form

Fill a form field with a specified value.

Wait for Selector

Wait for an element to appear on the page.

Examples

Example 1: Take a Screenshot

{
  "operation": "takeScreenshot",
  "url": "https://example.com",
  "browser": "chromium",
  "screenshotOptions": {
    "fullPage": true
  },
  "dataPropertyName": "screenshot"
}

Example 2: Fill and Submit a Form

{
  "operation": "fillForm",
  "url": "https://example.com/login",
  "selector": "#username",
  "value": "myuser",
  "browser": "chromium"
}

Example 3: Extract Text

{
  "operation": "getText",
  "url": "https://example.com",
  "selector": "h1",
  "browser": "chromium"
}

Notes & Limitations

  • Browser Installation: Browsers are automatically installed during package installation
  • Docker Support: For Linux/Docker environments, the node will automatically fallback to system Chrome if Playwright Chromium fails
  • Resource Usage: Running browsers consumes significant memory
  • Headless Recommended: Use headless mode in production environments
  • Timeout: Default timeout for operations is 30 seconds
  • Network: Requires network access for navigation

Troubleshooting

Browser not found error

If you encounter "Browser not found" errors, try running the setup script manually:

cd ~/.n8n/nodes/node_modules/@warnyin/n8n-nodes-code-playwright
npm run setup

Linux/Docker GTK/GLib errors

If you see errors like Error relocating chrome: g_object_notify: symbol not found, this means Playwright Chromium requires system dependencies. The node will automatically:

  1. Try to detect and use system Chrome/Chromium
  2. Fall back to Playwright Chromium with alternative arguments
  3. If all fails, you need to install Chrome in your Docker container:
# For Debian/Ubuntu based images
apt-get update && apt-get install -y google-chrome-stable

# For Alpine images  
apk add --no-cache chromium

Permission issues on Linux

On Linux systems, you may need to install additional dependencies:

npx playwright install-deps

Memory issues

If n8n crashes due to memory issues when using Playwright:

  1. Ensure headless: true is enabled
  2. Close browser contexts properly
  3. Consider increasing n8n's memory allocation

Development

# Install dependencies
pnpm install

# Build
pnpm build

# Watch mode
pnpm dev

# Setup browsers manually
pnpm setup

# Lint code
pnpm lint

# Fix lint issues
pnpm lintfix

# Format code
pnpm format

Changelog

See CHANGELOG.md for release notes.

License

MIT License — see LICENSE.md.

Author

warnyin - GitHub

References


Made with ❤️ for the n8n community

Discussion