n8n-nodes-playwright-chromium-cdp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,25 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 rctphone
4
+ Copyright (c) 2022-2024 Nicholas Penree <nick@penree.com>
5
+
6
+ This project is a fork of [n8n-nodes-puppeteer](https://github.com/drudge/n8n-nodes-puppeteer)
7
+ by Nicholas Penree, modified to use Playwright with CDP connection instead of Puppeteer.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,186 @@
1
+ # n8n-nodes-playwright-chromium-cdp
2
+
3
+ This is an n8n community node for browser automation using [Playwright](https://playwright.dev/) with a **remote browser via CDP (Chrome DevTools Protocol)**.
4
+
5
+ Unlike other browser automation nodes, this one does **not** install or launch browsers locally. Instead, it connects to an already running browser instance via CDP endpoint.
6
+
7
+ ## Credits
8
+
9
+ This project is based on [n8n-nodes-puppeteer](https://github.com/drudge/n8n-nodes-puppeteer) by [Nicholas Penree](https://github.com/drudge). The original Puppeteer implementation has been replaced with Playwright, focusing on remote browser connection via CDP.
10
+
11
+ ## Features
12
+
13
+ - **Remote Browser Connection**: Connect to any browser that exposes a CDP endpoint
14
+ - **No Local Browser Installation**: Perfect for containerized environments
15
+ - **Full Playwright API Access**: Use the powerful Playwright API for automation
16
+ - **Device Emulation**: Emulate various devices (mobile, tablet, desktop)
17
+ - **Screenshot & PDF Generation**: Capture pages as images or PDFs
18
+ - **Custom Scripts**: Run custom JavaScript code with full Playwright access
19
+
20
+ ## Installation
21
+
22
+ Follow the [installation guide](https://docs.n8n.io/integrations/community-nodes/installation/) in the n8n community nodes documentation.
23
+
24
+ ```bash
25
+ npm install n8n-nodes-playwright-chromium-cdp
26
+ ```
27
+
28
+ ## Prerequisites
29
+
30
+ You need a running browser with CDP enabled. Here are some options:
31
+
32
+ ### Option 1: Run Chrome/Chromium with CDP
33
+
34
+ ```bash
35
+ # macOS
36
+ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
37
+
38
+ # Linux
39
+ google-chrome --remote-debugging-port=9222
40
+
41
+ # Windows
42
+ "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
43
+ ```
44
+
45
+ ### Option 2: Use Docker
46
+
47
+ ```bash
48
+ docker run -d -p 9222:9222 zenika/alpine-chrome --no-sandbox --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222
49
+ ```
50
+
51
+ ### Option 3: Use browserless.io or similar services
52
+
53
+ Many services provide remote browsers with CDP access.
54
+
55
+ ## Credentials
56
+
57
+ Create credentials with the CDP endpoint URL:
58
+
59
+ - **CDP Endpoint URL**: The URL to connect to (e.g., `http://localhost:9222`)
60
+ - **Timeout**: Connection timeout in milliseconds
61
+
62
+ ## Operations
63
+
64
+ ### Get Page Content
65
+ Retrieves the full HTML content of a page.
66
+
67
+ ### Get Screenshot
68
+ Captures a screenshot of the page (PNG or JPEG).
69
+
70
+ ### Get PDF
71
+ Generates a PDF from the page (Chromium-based browsers only).
72
+
73
+ ### Run Custom Script
74
+ Execute custom JavaScript code with access to Playwright objects:
75
+
76
+ ```javascript
77
+ // Available variables:
78
+ // $browser - Browser instance (connected via playwright.chromium.connectOverCDP())
79
+ // $context - Browser context
80
+ // $page - Page instance
81
+ // $playwright - Playwright module with { chromium, devices }
82
+
83
+ // Navigate and extract data
84
+ await $page.goto('https://example.com');
85
+
86
+ const title = await $page.title();
87
+ const content = await $page.textContent('body');
88
+
89
+ // Return data (must be an array)
90
+ return [{ title, content, ...$json }];
91
+ ```
92
+
93
+ ## Options
94
+
95
+ - **Batch Size**: Process multiple items in parallel
96
+ - **Emulate Device**: Emulate specific devices (iPhone, Pixel, etc.)
97
+ - **Viewport**: Set custom viewport dimensions
98
+ - **User Agent**: Custom user agent string
99
+ - **Locale/Timezone**: Set browser locale and timezone
100
+ - **Geolocation**: Set fake geolocation
101
+ - **Extra Headers**: Add custom HTTP headers
102
+ - **Wait Until**: Navigation wait strategy (load, domcontentloaded, networkidle, commit)
103
+ - **Timeout**: Navigation timeout
104
+ - **Ignore HTTPS Errors**: Bypass SSL certificate errors
105
+ - **JavaScript Enabled**: Toggle JavaScript execution
106
+ - **Bypass CSP**: Bypass Content Security Policy
107
+
108
+ ## Example: Storing and Reusing Cookies
109
+
110
+ ### Node 1: Login and save cookies
111
+
112
+ ```javascript
113
+ await $page.goto('https://example.com/login');
114
+
115
+ await $page.fill('#username', 'user');
116
+ await $page.fill('#password', 'pass');
117
+ await $page.click('#login-button');
118
+
119
+ // Wait for navigation
120
+ await $page.waitForLoadState('networkidle');
121
+
122
+ // Get cookies from context
123
+ const cookies = await $context.cookies();
124
+
125
+ return [{ cookies }];
126
+ ```
127
+
128
+ ### Node 2: Use saved cookies
129
+
130
+ ```javascript
131
+ const { cookies } = $input.first().json;
132
+
133
+ // Set cookies
134
+ await $context.addCookies(cookies);
135
+
136
+ // Navigate to authenticated page
137
+ await $page.goto('https://example.com/dashboard');
138
+
139
+ const data = await $page.textContent('.dashboard-content');
140
+
141
+ return [{ data }];
142
+ ```
143
+
144
+ ## Example: Taking Screenshots
145
+
146
+ ```javascript
147
+ await $page.goto('https://example.com');
148
+
149
+ // Wait for content to load
150
+ await $page.waitForSelector('.main-content');
151
+
152
+ // Take screenshot as base64
153
+ const screenshot = await $page.screenshot({
154
+ type: 'png',
155
+ fullPage: true
156
+ });
157
+
158
+ return [{
159
+ binary: {
160
+ screenshot: {
161
+ data: screenshot.toString('base64'),
162
+ mimeType: 'image/png',
163
+ fileName: 'screenshot.png',
164
+ },
165
+ },
166
+ }];
167
+ ```
168
+
169
+ ## Development
170
+
171
+ ```bash
172
+ # Install dependencies
173
+ npm install
174
+
175
+ # Build the node
176
+ npm run build
177
+
178
+ # Watch for changes
179
+ npm run dev
180
+ ```
181
+
182
+ ## License
183
+
184
+ MIT License - see [LICENSE.md](LICENSE.md)
185
+
186
+ Based on [n8n-nodes-puppeteer](https://github.com/drudge/n8n-nodes-puppeteer) by Nicholas Penree.
@@ -0,0 +1,9 @@
1
+ import { ICredentialType, INodeProperties } from 'n8n-workflow';
2
+ export declare class PlaywrightCdpApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ documentationUrl: string;
6
+ icon: "file:playwright.svg";
7
+ properties: INodeProperties[];
8
+ }
9
+ //# sourceMappingURL=PlaywrightCdpApi.credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlaywrightCdpApi.credentials.d.ts","sourceRoot":"","sources":["../../credentials/PlaywrightCdpApi.credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EACf,eAAe,EACf,MAAM,cAAc,CAAC;AAEtB,qBAAa,gBAAiB,YAAW,eAAe;IACvD,IAAI,SAAsB;IAC1B,WAAW,SAAoB;IAC/B,gBAAgB,SAAqF;IACrG,IAAI,EAAG,qBAAqB,CAAU;IACtC,UAAU,EAAE,eAAe,EAAE,CAgB3B;CACF"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlaywrightCdpApi = void 0;
4
+ class PlaywrightCdpApi {
5
+ constructor() {
6
+ this.name = 'playwrightCdpApi';
7
+ this.displayName = 'Playwright CDP';
8
+ this.documentationUrl = 'https://playwright.dev/docs/api/class-browsertype#browser-type-connect-over-cdp';
9
+ this.icon = 'file:playwright.svg';
10
+ this.properties = [
11
+ {
12
+ displayName: 'CDP Endpoint URL',
13
+ name: 'cdpEndpoint',
14
+ type: 'string',
15
+ default: 'http://localhost:9222',
16
+ placeholder: 'http://localhost:9222',
17
+ description: 'The CDP endpoint URL to connect to the remote browser. Can be HTTP or WebSocket URL (e.g., http://localhost:9222 or ws://localhost:9222/devtools/browser/xxx)',
18
+ },
19
+ {
20
+ displayName: 'Timeout (ms)',
21
+ name: 'timeout',
22
+ type: 'number',
23
+ default: 30000,
24
+ description: 'Maximum time in milliseconds to wait for the connection to be established',
25
+ },
26
+ ];
27
+ }
28
+ }
29
+ exports.PlaywrightCdpApi = PlaywrightCdpApi;
30
+ //# sourceMappingURL=PlaywrightCdpApi.credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlaywrightCdpApi.credentials.js","sourceRoot":"","sources":["../../credentials/PlaywrightCdpApi.credentials.ts"],"names":[],"mappings":";;;AAKA,MAAa,gBAAgB;IAA7B;QACC,SAAI,GAAG,kBAAkB,CAAC;QAC1B,gBAAW,GAAG,gBAAgB,CAAC;QAC/B,qBAAgB,GAAG,iFAAiF,CAAC;QACrG,SAAI,GAAG,qBAA8B,CAAC;QACtC,eAAU,GAAsB;YAC/B;gBACC,WAAW,EAAE,kBAAkB;gBAC/B,IAAI,EAAE,aAAa;gBACnB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,uBAAuB;gBAChC,WAAW,EAAE,uBAAuB;gBACpC,WAAW,EAAE,+JAA+J;aAC5K;YACD;gBACC,WAAW,EAAE,cAAc;gBAC3B,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,KAAK;gBACd,WAAW,EAAE,2EAA2E;aACxF;SACD,CAAC;IACH,CAAC;CAAA;AAtBD,4CAsBC"}
@@ -0,0 +1,14 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400">
2
+ <defs>
3
+ <linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="100%">
4
+ <stop offset="0%" style="stop-color:#2EAD33;stop-opacity:1" />
5
+ <stop offset="100%" style="stop-color:#45BF55;stop-opacity:1" />
6
+ </linearGradient>
7
+ </defs>
8
+ <circle cx="200" cy="200" r="180" fill="url(#grad1)"/>
9
+ <g fill="#fff">
10
+ <path d="M120 140 L120 260 L160 260 L160 220 L200 220 L200 260 L240 260 L240 140 L200 140 L200 180 L160 180 L160 140 Z"/>
11
+ <circle cx="280" cy="200" r="40"/>
12
+ </g>
13
+ </svg>
14
+
@@ -0,0 +1,12 @@
1
+ import { type IExecuteFunctions, type ILoadOptionsFunctions, type INodeExecutionData, type INodePropertyOptions, type INodeType, type INodeTypeDescription } from 'n8n-workflow';
2
+ export declare const vmResolver: import("@n8n/vm2").Resolver;
3
+ export declare class Playwright implements INodeType {
4
+ description: INodeTypeDescription;
5
+ methods: {
6
+ loadOptions: {
7
+ getDevices(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
8
+ };
9
+ };
10
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
11
+ }
12
+ //# sourceMappingURL=Playwright.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Playwright.node.d.ts","sourceRoot":"","sources":["../../../nodes/Playwright/Playwright.node.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,SAAS,EACd,KAAK,oBAAoB,EAEzB,MAAM,cAAc,CAAC;AAatB,eAAO,MAAM,UAAU,6BAQrB,CAAC;AA6ZH,qBAAa,UAAW,YAAW,SAAS;IAC3C,WAAW,EAAE,oBAAoB,CAAmB;IAEpD,OAAO;;6BAGE,qBAAqB,GACzB,OAAO,CAAC,oBAAoB,EAAE,CAAC;;MAkBlC;IAEI,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;CAwOvE"}