n8n-nodes-playwright-enhanced
v1.3.9
Published
n8n-community-node-package for browser automation using Playwright with persistent browser session support
Maintainers
Keywords
Readme
n8n-nodes-playwright-enhanced
An n8n community node for browser automation using Playwright — with persistent browser session support. Create named browser profiles, log in to services once, and reuse the authenticated session across any workflow.
Installation What's Different Operations Persistent Browser Workflow Custom Scripts Compatibility Troubleshooting
Installation
In your n8n instance go to Settings → Community Nodes → Install and enter:
n8n-nodes-playwright-enhancedThe package will automatically download and set up the required browser binaries during installation (~1GB disk space required).
What's Different
This package adds persistent named browser profiles on top of standard Playwright automation. The key problem it solves: logging in to a service once and reusing that session across multiple workflows, without re-authenticating every time.
New Operations
- Create Persistent Browser — Launch a named browser server that stays running between workflow executions
- List Persistent Browsers — View all named browsers and their status (online/offline)
- Destroy Persistent Browser — Shut down a named browser and remove it from the registry
Session Persistence
When using Run Custom Script in Persistent mode:
- On first run: the browser context is fresh
- After the script completes: cookies, localStorage, and session data are automatically saved to the browser's profile directory (
~/.n8n/browser-profiles/<name>/storage-state.json) - On every subsequent run: the saved session is automatically restored — no login required
Auto-Recovery
If a persistent browser server crashes or the EC2 instance restarts, it will automatically relaunch the next time a workflow tries to connect to it, restoring the same profile and session.
New Script Variable
Custom scripts now have access to $context (the Playwright BrowserContext) in addition to the existing $page, $browser, and $playwright variables.
Operations
Standard Operations
- Navigate — Go to a URL and return page content
- Take Screenshot — Capture a screenshot (full page or viewport)
- Get Text — Extract text from an element using CSS selector or XPath
- Click Element — Click an element using CSS selector or XPath
- Fill Form — Fill a form field using CSS selector or XPath
- Run Custom Script — Execute custom JavaScript with full Playwright API access
Browser Options
- Chromium, Firefox, or WebKit
- Headless mode toggle
- Slow motion (ms delay between operations)
Selector Options
- CSS Selector — e.g.
#submit-button,.my-class,button[type="submit"] - XPath — e.g.
//button[@id="submit"],//div[contains(@class, "content")]
Persistent Browser Workflow
Step 1 — Create a named browser (once)
Add a Playwright node and set:
- Operation →
Create Persistent Browser - Browser Name →
my-session(any name you choose) - Browser →
Chromium - Port →
0(auto-assign)
Run it once. The browser server starts and is registered.
Step 2 — Log in (once)
Add another Playwright node:
- Operation →
Run Custom Script - Browser Mode →
Persistent — Connect to Named Browser - Persistent Browser → select
my-session
await $page.goto('https://your-service.com/login');
await $page.fill('#email', '[email protected]');
await $page.fill('#password', 'yourpassword');
await $page.click('button[type="submit"]');
await $page.waitForURL('**/dashboard');
// Session state (cookies, localStorage) is automatically saved after this script exits
return [{ json: { status: 'logged in' } }];Run it once. The session is saved to the browser profile.
Step 3 — Use the session in any workflow
// No login needed — session is automatically restored from the profile
await $page.goto('https://your-service.com/protected-page');
const data = await $page.textContent('.some-element');
return [{ json: { data } }];Multiple Profiles
You can create as many named browsers as you need, each with its own isolated session:
| Browser Name | Purpose |
|---|---|
| shopify-prod | Shopify production account |
| shopify-staging | Shopify staging account |
| google-workspace | Google account |
Custom Scripts
Available Variables
| Variable | Description |
|---|---|
| $page | Current Playwright Page instance |
| $browser | Browser instance |
| $context | BrowserContext instance (persistent mode only) |
| $playwright | Playwright library |
| $helpers | n8n helpers including prepareBinaryData |
| $json | Current item's JSON data |
| $input | Input data from previous nodes |
Script Examples
Take a Screenshot
await $page.goto('https://example.com');
const screenshot = await $page.screenshot({ type: 'png', fullPage: true });
return [{
json: { url: $page.url() },
binary: {
screenshot: await $helpers.prepareBinaryData(
Buffer.from(screenshot), 'screenshot.png', 'image/png'
)
}
}];Scrape Data
await $page.goto('https://example.com/products');
await $page.waitForSelector('.product-item');
const products = await $page.$$eval('.product-item', items =>
items.map(item => ({
name: item.querySelector('.product-name')?.textContent,
price: item.querySelector('.product-price')?.textContent,
}))
);
return products.map(p => ({ json: p }));Generate a PDF
await $page.goto('https://example.com/report');
const pdf = await $page.pdf({ format: 'A4', printBackground: true });
return [{
json: { url: $page.url() },
binary: {
pdf: await $helpers.prepareBinaryData(Buffer.from(pdf), 'report.pdf', 'application/pdf')
}
}];Wait for Dynamic Content
await $page.goto('https://example.com');
await $page.waitForLoadState('networkidle');
await $page.waitForSelector('.dynamic-content', { timeout: 10000 });
const content = await $page.textContent('.dynamic-content');
return [{ json: { content } }];Script Tips
- Always return an array —
return [{ json: {...} }]; - Use
console.log()— output appears in the n8n UI during manual execution - Always use
await— all Playwright operations are async - In persistent mode —
$browser.close()disconnects without killing the server
Compatibility
- Requires n8n 1.0.0 or later
- Playwright 1.49.0
- Node.js 18.10 or later
- Supports Linux, macOS, and Windows
- ~1GB disk space for browser binaries
Troubleshooting
Browsers Not Installed
node node_modules/n8n-nodes-playwright-persistent/dist/nodes/scripts/setup-browsers.jsScript Errors
- Ensure your script returns an array:
return [{ json: {...} }]; - Use
console.log()to debug - Wrap code in
try/catchfor better error messages - Verify all Playwright operations use
await
Element Not Found
- Try XPath instead of CSS (or vice versa)
- Wait for the element:
await $page.waitForSelector('.my-element') - Check for iframes:
await $page.frameLocator('iframe').locator('.element') - Wait for page load:
await $page.waitForLoadState('networkidle')
Session Not Persisting
- Make sure you are using Persistent browser mode in Run Custom Script
- The session saves automatically after the script exits — no extra code needed
- Check that
~/.n8n/browser-profiles/<name>/storage-state.jsonexists after the first login run
License
MIT
