
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
node-red-contrib-playwright-automation
Advanced tools
Node-RED nodes for browser automation with Playwright
A collection of Node-RED nodes for web automation using Playwright. This package includes nodes for capturing website screenshots and generating PDFs directly from your Node-RED flows.
~/.node-red
):npm install node-red-contrib-playwright-automation
# Install Playwright
pip install playwright
# Install browser binaries
python -m playwright install
Capture full-page screenshots of websites.
msg.payload
msg.payload
if the screenshot failsGenerate PDFs from web pages with customizable options.
{"top": "1cm", "right": "1cm", "bottom": "1cm", "left": "1cm"}
)msg
propertiesmsg.url
, msg.format
, msg.margin
, etc.msg.payload
msg.payload
if PDF generation fails// Convert base64 to data URL
msg.payload = {
topic: 'Screenshot',
payload: `data:image/jpeg;base64,${msg.payload}`
};
return msg;
pdfs/{{payload.title || 'document'}}.pdf
pdfs
directory existsTo serve a PDF as a download:
// Convert base64 to buffer
msg.payload = Buffer.from(msg.payload, 'base64');
msg.headers = {
'Content-Type': 'application/pdf',
'Content-Disposition': 'attachment; filename=document.pdf'
};
return msg;
For better dependency management, it's recommended to use a Python virtual environment:
Create and activate a virtual environment:
# Create
python -m venv venv
# Activate (Windows)
.\venv\Scripts\activate
# Or activate (macOS/Linux)
# source venv/bin/activate
Install Playwright:
pip install playwright
python -m playwright install
python -m playwright install-deps # Install system dependencies (Linux only)
Use the virtual environment in Node-RED:
./venv
(relative to your Node-RED user directory) or /path/to/venv
(absolute path)If you're using Docker, you'll need to ensure the container has all required dependencies:
# Example Dockerfile for Node-RED with Playwright
FROM nodered/node-red:latest
# Install Python and Playwright dependencies
RUN apt-get update && apt-get install -y \
python3 \
python3-pip \
&& rm -rf /var/lib/apt/lists/*
# Install Playwright and browsers
RUN pip3 install playwright \
&& playwright install \
&& playwright install-deps
# Copy your Node-RED project files
COPY . /data
# Install Node-RED dependencies
RUN cd /data && npm install
For the PDF node, you can use the following special classes in your header/footer templates:
date
: The current datetitle
: The page titleurl
: The page URLpageNumber
: Current page numbertotalPages
: Total number of pagesExample footer template:
<div style="font-size: 10px; margin: 0 1cm; text-align: center; width: 100%;">
Page <span class="pageNumber"></span> of <span class="totalPages"></span>
</div>
Browser not found
python -m playwright install
python -m playwright install-deps
Screenshot/PDF generation fails
Python not found
PDF generation errors
settings.js
:
logging: {
console: {
level: "debug"
}
}
python -c "import playwright; print('Playwright version:', playwright.__version__)"
python -m playwright install
python -m playwright install-deps # Linux only
To contribute to this project:
npm install
Install test dependencies:
npm install -D node-red-node-test-helper
Run tests:
npm test
This project is licensed under the MIT License - see the LICENSE file for details.
If you find this project useful, please consider giving it a ⭐️ on GitHub!
MIT - See LICENSE for more information.
For support, please open an issue on GitHub.
Browser doesn't start:
python -m playwright install
Element not found:
page.wait_for_selector()
before interacting with elementsTimeout errors:
page.wait_for_selector(..., timeout=10000)
Docker issues:
def main(msg):
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
page.goto('https://example.com')
# Take a screenshot
screenshot = page.screenshot(type='png')
browser.close()
msg.payload = {
'screenshot': f"data:image/png;base64,{screenshot.decode('latin1')}",
'timestamp': str(datetime.utcnow())
}
return msg
Resource Management:
with
statements) when possibleError Handling:
Performance:
Security:
This project is licensed under the MIT License - see the LICENSE file for details.
This node configures a Playwright browser instance.
This node performs browser automation actions.
Navigate to URL
msg.url
or msg.payload
as the URLClick Element
Fill Form
Take Screenshot
Evaluate JavaScript
msg.payload
https://example.com
)browser
property with a Playwright browser instanceurl
in the message to navigate before taking the screenshotmsg.screenshot
as a base64-encoded data URLExample message to the node:
{
"browser": browserInstance, // From Playwright browser launch
"url": "https://example.com", // Optional: URL to navigate to
"payload": {
// Your custom data
}
}
Output message will include:
{
"screenshot": "data:image/png;base64,...", // Base64 encoded image
"screenshotTakenAt": "2025-06-21T10:42:33.123Z",
"payload": {
// Your original payload with additional processing
"processedAt": "2025-06-21T10:42:33.123Z"
}
}
To display the screenshot in the Node-RED Dashboard:
<div ng-if="msg.screenshot">
<h3>Screenshot taken at {{msg.screenshotTakenAt}}</h3>
<img ng-src="{{msg.screenshot}}" style="max-width: 100%;">
</div>
## Message Properties
### Input
- `msg.url`: URL to navigate to (for "navigate" action)
- `msg.selector`: CSS selector (for "click" and "fill" actions)
- `msg.value`: Value to fill (for "fill" action)
- `msg.payload`: Can be used as URL or value depending on the action
### Output
- `msg.payload`: Contains screenshot buffer (for "screenshot" action) or evaluation result (for "evaluate" action)
- `msg.screenshot`: Alternative property containing screenshot buffer
- `msg.page`: Reference to the Playwright Page object (advanced usage)
## Advanced Usage
### Screenshot Options
- **Take Screenshot**: Enable/disable screenshot functionality
- **Screenshot Delay**: Time to wait (in milliseconds) before taking the screenshot
- **Require Browser Instance**: When enabled, the node will only take screenshots if a browser instance is provided in the message. When disabled, the node will attempt to create a new browser instance if needed.
### Accessing Playwright API
You can access the Playwright Page object directly in function nodes:
```javascript
const page = msg._browserPage; // Available after any Playwright Automation node
// Use any Playwright Page API
const title = await page.title();
msg.payload = { title };
return msg;
// In a function node before navigation
msg._playwrightAuth = {
username: 'user',
password: 'pass',
url: 'https://example.com/login'
};
return msg;
npx playwright install
.This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
Node-RED nodes for browser automation with Playwright
We found that node-red-contrib-playwright-automation demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.