claude-chrome-parallel 2.1.0 → 2.2.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/README.md +187 -198
- package/dist/cdp/connection-pool.d.ts +88 -0
- package/dist/cdp/connection-pool.d.ts.map +1 -0
- package/dist/cdp/connection-pool.js +280 -0
- package/dist/cdp/connection-pool.js.map +1 -0
- package/dist/cli/index.js +166 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/session-manager.d.ts +55 -1
- package/dist/session-manager.d.ts.map +1 -1
- package/dist/session-manager.js +139 -4
- package/dist/session-manager.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/network.d.ts +6 -0
- package/dist/tools/network.d.ts.map +1 -0
- package/dist/tools/network.js +215 -0
- package/dist/tools/network.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,85 +1,82 @@
|
|
|
1
1
|
# Claude Chrome Parallel
|
|
2
2
|
|
|
3
|
-
> **Run multiple Claude Code sessions
|
|
3
|
+
> **Run multiple Claude Code browser sessions in parallel - no more "Detached" errors.**
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/claude-chrome-parallel)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Why This Exists
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
- **Browser Automation**: Independent CDP connections for parallel browser control
|
|
12
|
-
- **Auto Recovery**: Detects and recovers corrupted config files
|
|
10
|
+
[Claude Chrome](https://claude.ai/chrome) is a powerful tool that lets you debug **production environments while logged in** - no need to replicate auth states or mock sessions. But when you try to run multiple Claude Code sessions with browser automation simultaneously, you get:
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
```
|
|
13
|
+
Error: Detached while handling command
|
|
14
|
+
```
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
This happens because the Chrome extension uses **shared internal state**. When Session A takes a screenshot, Session B's connection gets "detached."
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
**Claude Chrome Parallel** solves this by creating **independent CDP connections** for each session:
|
|
19
19
|
|
|
20
20
|
```
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Result: {"key":"value"}{"key":"value"} ← Two JSON objects concatenated = CORRUPT
|
|
21
|
+
Claude Code 1 ──► Process 1 ──► CDP Connection 1 ──┐
|
|
22
|
+
├──► Chrome (port 9222)
|
|
23
|
+
Claude Code 2 ──► Process 2 ──► CDP Connection 2 ──┘
|
|
26
24
|
```
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
- Claude Code crashes on startup
|
|
30
|
-
- "Unexpected token" JSON parse errors
|
|
31
|
-
- Lost settings and preferences
|
|
26
|
+
Each session gets isolated browser control. No shared state = No conflicts.
|
|
32
27
|
|
|
33
|
-
|
|
28
|
+
---
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
# Instead of running claude directly...
|
|
37
|
-
claude-chrome-parallel launch
|
|
30
|
+
## Use Cases
|
|
38
31
|
|
|
39
|
-
|
|
40
|
-
Terminal 1: claude-chrome-parallel launch ──► ~/.claude-chrome-parallel/sessions/abc123/.claude.json
|
|
41
|
-
Terminal 2: claude-chrome-parallel launch ──► ~/.claude-chrome-parallel/sessions/def456/.claude.json
|
|
42
|
-
```
|
|
32
|
+
### Multi-Session QA Testing
|
|
43
33
|
|
|
44
|
-
|
|
34
|
+
Run parallel test scenarios against your production or staging environment:
|
|
45
35
|
|
|
46
36
|
```bash
|
|
47
|
-
|
|
48
|
-
claude-
|
|
49
|
-
claude-chrome-parallel launch -p "Fix the bug"
|
|
50
|
-
claude-chrome-parallel launch --model opus --resume
|
|
51
|
-
```
|
|
37
|
+
# Terminal 1: Test user login flow
|
|
38
|
+
claude -p "Test the login flow on https://myapp.com/login"
|
|
52
39
|
|
|
53
|
-
|
|
40
|
+
# Terminal 2: Test checkout process (simultaneously!)
|
|
41
|
+
claude -p "Test the checkout flow on https://myapp.com/cart"
|
|
42
|
+
|
|
43
|
+
# Terminal 3: Monitor admin dashboard
|
|
44
|
+
claude -p "Take screenshots of https://myapp.com/admin every 30 seconds"
|
|
45
|
+
```
|
|
54
46
|
|
|
55
|
-
|
|
47
|
+
### Parallel Debugging
|
|
56
48
|
|
|
57
|
-
|
|
49
|
+
Debug multiple pages or user journeys at the same time:
|
|
58
50
|
|
|
59
|
-
```
|
|
60
|
-
|
|
51
|
+
```bash
|
|
52
|
+
# Debug as different users
|
|
53
|
+
Terminal 1: "Log in as admin and check permissions on /settings"
|
|
54
|
+
Terminal 2: "Log in as regular user and verify they can't access /settings"
|
|
61
55
|
```
|
|
62
56
|
|
|
63
|
-
|
|
57
|
+
### Automated Regression Testing
|
|
64
58
|
|
|
65
|
-
|
|
59
|
+
Run comprehensive browser tests across multiple sessions:
|
|
66
60
|
|
|
61
|
+
```bash
|
|
62
|
+
# Run 5 parallel test sessions
|
|
63
|
+
for i in {1..5}; do
|
|
64
|
+
claude -p "Run test suite $i on https://staging.myapp.com" &
|
|
65
|
+
done
|
|
67
66
|
```
|
|
68
|
-
Claude Code 1 ──► puppeteer process 1 ──► CDP connection 1 ──┐
|
|
69
|
-
├──► Chrome
|
|
70
|
-
Claude Code 2 ──► puppeteer process 2 ──► CDP connection 2 ──┘
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
---
|
|
74
67
|
|
|
75
|
-
|
|
68
|
+
### Tested Concurrency
|
|
76
69
|
|
|
77
|
-
|
|
70
|
+
| Sessions | Success Rate |
|
|
71
|
+
|----------|-------------|
|
|
72
|
+
| 5 | 100% |
|
|
73
|
+
| 10 | 100% |
|
|
74
|
+
| 15 | 100% |
|
|
75
|
+
| 20 | 100% |
|
|
78
76
|
|
|
79
|
-
|
|
80
|
-
- Google Chrome (for browser automation)
|
|
77
|
+
---
|
|
81
78
|
|
|
82
|
-
|
|
79
|
+
## Installation
|
|
83
80
|
|
|
84
81
|
```bash
|
|
85
82
|
# From npm
|
|
@@ -89,207 +86,210 @@ npm install -g claude-chrome-parallel
|
|
|
89
86
|
npm install -g github:shaun0927/claude-chrome-parallel
|
|
90
87
|
```
|
|
91
88
|
|
|
89
|
+
### Configure Claude Code
|
|
90
|
+
|
|
91
|
+
Add to your Claude Code MCP settings (`~/.claude.json`):
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"mcpServers": {
|
|
96
|
+
"chrome-parallel": {
|
|
97
|
+
"command": "claude-chrome-parallel",
|
|
98
|
+
"args": ["serve"]
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Restart Claude Code for changes to take effect.
|
|
105
|
+
|
|
92
106
|
---
|
|
93
107
|
|
|
94
108
|
## Usage
|
|
95
109
|
|
|
96
|
-
###
|
|
110
|
+
### Basic Usage
|
|
97
111
|
|
|
98
|
-
|
|
99
|
-
# Start Claude Code with isolated config
|
|
100
|
-
claude-chrome-parallel launch
|
|
112
|
+
Once configured, browser automation works in any Claude Code session:
|
|
101
113
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
claude-chrome-parallel launch --resume <session-id>
|
|
105
|
-
claude-chrome-parallel launch -p "Your prompt here"
|
|
106
|
-
|
|
107
|
-
# Sync changes back to original config on exit
|
|
108
|
-
claude-chrome-parallel launch --sync-back
|
|
114
|
+
```
|
|
115
|
+
You: Take a screenshot of https://github.com
|
|
109
116
|
|
|
110
|
-
|
|
111
|
-
claude-chrome-parallel launch --keep-session
|
|
117
|
+
Claude: [Uses chrome-parallel tools automatically]
|
|
112
118
|
```
|
|
113
119
|
|
|
114
|
-
###
|
|
120
|
+
### Multiple Parallel Sessions
|
|
121
|
+
|
|
122
|
+
Run multiple Claude Code terminals simultaneously:
|
|
115
123
|
|
|
116
124
|
```bash
|
|
117
|
-
#
|
|
118
|
-
claude
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
claude
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
# Terminal 1
|
|
126
|
+
claude
|
|
127
|
+
> Navigate to myapp.com/dashboard and take a screenshot
|
|
128
|
+
|
|
129
|
+
# Terminal 2 (at the same time!)
|
|
130
|
+
claude
|
|
131
|
+
> Fill out the form on myapp.com/contact and submit
|
|
132
|
+
|
|
133
|
+
# Terminal 3 (also at the same time!)
|
|
134
|
+
claude
|
|
135
|
+
> Monitor network requests on myapp.com/api
|
|
125
136
|
```
|
|
126
137
|
|
|
127
|
-
|
|
138
|
+
All sessions work without conflicts!
|
|
128
139
|
|
|
129
|
-
|
|
130
|
-
# Check config health
|
|
131
|
-
claude-chrome-parallel doctor
|
|
140
|
+
### Available Browser Tools
|
|
132
141
|
|
|
133
|
-
|
|
134
|
-
|
|
142
|
+
| Tool | Description |
|
|
143
|
+
|------|-------------|
|
|
144
|
+
| `navigate` | Navigate to URL or use history |
|
|
145
|
+
| `computer` | Screenshots, mouse clicks, keyboard input, scrolling |
|
|
146
|
+
| `read_page` | Read page content via accessibility tree |
|
|
147
|
+
| `find` | Find elements by description |
|
|
148
|
+
| `form_input` | Fill form fields |
|
|
149
|
+
| `javascript_tool` | Execute JavaScript |
|
|
150
|
+
| `tabs_context_mcp` | Get available tabs |
|
|
151
|
+
| `tabs_create_mcp` | Create new tab |
|
|
152
|
+
| `network` | Simulate network conditions (3G, 4G, offline, custom) |
|
|
135
153
|
|
|
136
|
-
|
|
137
|
-
claude-chrome-parallel recover --list-backups
|
|
154
|
+
### Network Simulation
|
|
138
155
|
|
|
139
|
-
|
|
140
|
-
claude-chrome-parallel recover --backup ".claude.json.2024-01-15T10-30-00-000Z.bak"
|
|
156
|
+
Test how your app behaves under different network conditions:
|
|
141
157
|
|
|
142
|
-
|
|
143
|
-
|
|
158
|
+
```
|
|
159
|
+
You: Simulate 3G network and navigate to myapp.com
|
|
144
160
|
|
|
145
|
-
|
|
146
|
-
claude-chrome-parallel cleanup
|
|
147
|
-
claude-chrome-parallel cleanup --max-age 12 # Sessions older than 12 hours
|
|
148
|
-
claude-chrome-parallel cleanup --keep-backups 5 # Keep only 5 most recent backups
|
|
161
|
+
Claude: [Applies 3G throttling: 1.5Mbps down, 750Kbps up, 100ms latency]
|
|
149
162
|
```
|
|
150
163
|
|
|
151
|
-
|
|
164
|
+
Available presets: `offline`, `slow-2g`, `2g`, `3g`, `4g`, `fast-wifi`, `custom`, `clear`
|
|
152
165
|
|
|
153
|
-
|
|
166
|
+
---
|
|
154
167
|
|
|
155
|
-
|
|
156
|
-
{
|
|
157
|
-
"mcpServers": {
|
|
158
|
-
"chrome-parallel": {
|
|
159
|
-
"command": "claude-chrome-parallel",
|
|
160
|
-
"args": ["serve"]
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
```
|
|
168
|
+
## How It Works
|
|
165
169
|
|
|
166
|
-
|
|
170
|
+
### The Problem: Shared Extension State
|
|
167
171
|
|
|
168
|
-
|
|
169
|
-
You: Take a screenshot of https://github.com
|
|
172
|
+
The official Chrome extension maintains a single shared state:
|
|
170
173
|
|
|
171
|
-
|
|
174
|
+
```
|
|
175
|
+
Claude Code 1 ─┐
|
|
176
|
+
├─► Chrome Extension (shared state) ─► Chrome
|
|
177
|
+
Claude Code 2 ─┘
|
|
178
|
+
↑
|
|
179
|
+
State conflicts here!
|
|
172
180
|
```
|
|
173
181
|
|
|
174
|
-
|
|
182
|
+
### The Solution: Independent CDP Connections
|
|
175
183
|
|
|
176
|
-
|
|
177
|
-
# Terminal 1
|
|
178
|
-
claude-chrome-parallel launch
|
|
179
|
-
> Take a screenshot of github.com
|
|
184
|
+
Chrome's DevTools Protocol natively supports multiple simultaneous connections:
|
|
180
185
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
186
|
+
```
|
|
187
|
+
Claude Code 1 ─► Process 1 ─► CDP Connection 1 ─┐
|
|
188
|
+
├─► Chrome (port 9222)
|
|
189
|
+
Claude Code 2 ─► Process 2 ─► CDP Connection 2 ─┘
|
|
190
|
+
|
|
191
|
+
Independent connections, no shared state!
|
|
184
192
|
```
|
|
185
193
|
|
|
186
|
-
|
|
194
|
+
Each Claude Code session spawns its own MCP server process with a dedicated CDP connection.
|
|
187
195
|
|
|
188
196
|
---
|
|
189
197
|
|
|
190
|
-
## CLI
|
|
198
|
+
## CLI Commands
|
|
191
199
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
| `recover` | Recover corrupted .claude.json |
|
|
196
|
-
| `cleanup` | Clean up stale sessions and backups |
|
|
197
|
-
| `doctor` | Check installation and config health |
|
|
198
|
-
| `serve` | Start MCP server for browser automation |
|
|
199
|
-
| `install` | Install browser extension and native host |
|
|
200
|
-
| `uninstall` | Remove extension and native host |
|
|
200
|
+
```bash
|
|
201
|
+
# Start MCP server (used by Claude Code automatically)
|
|
202
|
+
claude-chrome-parallel serve
|
|
201
203
|
|
|
202
|
-
|
|
204
|
+
# Check Chrome connection status
|
|
205
|
+
claude-chrome-parallel check
|
|
203
206
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
| `--sync-back` | Sync config changes back to original on exit |
|
|
207
|
-
| `--keep-session` | Keep session directory after exit (debugging) |
|
|
207
|
+
# Use custom Chrome debugging port
|
|
208
|
+
claude-chrome-parallel serve --port 9223
|
|
208
209
|
|
|
209
|
-
|
|
210
|
+
# Check installation health
|
|
211
|
+
claude-chrome-parallel doctor
|
|
210
212
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
| `--list-backups` | List available backup files |
|
|
214
|
-
| `--backup <name>` | Restore from specific backup |
|
|
215
|
-
| `--force-new` | Create new empty config (loses all data) |
|
|
213
|
+
# View session status and statistics
|
|
214
|
+
claude-chrome-parallel status
|
|
216
215
|
|
|
217
|
-
|
|
216
|
+
# View status as JSON (for automation)
|
|
217
|
+
claude-chrome-parallel status --json
|
|
218
218
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
| `--keep-backups <n>` | Number of backups to keep (default: 10) |
|
|
219
|
+
# Clean up stale sessions and old backups
|
|
220
|
+
claude-chrome-parallel cleanup --max-age 24 --keep-backups 10
|
|
221
|
+
```
|
|
223
222
|
|
|
224
223
|
---
|
|
225
224
|
|
|
226
|
-
##
|
|
225
|
+
## Chrome Configuration
|
|
227
226
|
|
|
228
|
-
|
|
229
|
-
|------|-------------|
|
|
230
|
-
| `navigate` | Navigate to URL or use history |
|
|
231
|
-
| `tabs_context_mcp` | Get available tabs |
|
|
232
|
-
| `tabs_create_mcp` | Create new tab |
|
|
233
|
-
| `computer` | Screenshots, mouse/keyboard, scrolling |
|
|
234
|
-
| `read_page` | Read accessibility tree |
|
|
235
|
-
| `find` | Find elements by description |
|
|
236
|
-
| `form_input` | Fill form fields |
|
|
237
|
-
| `javascript_tool` | Execute JavaScript |
|
|
227
|
+
By default, connects to Chrome on port 9222.
|
|
238
228
|
|
|
239
|
-
|
|
229
|
+
**Auto-launch**: If Chrome isn't running with debugging enabled, the package will start it automatically.
|
|
240
230
|
|
|
241
|
-
|
|
231
|
+
**Manual start** (if needed):
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
# Windows
|
|
235
|
+
chrome.exe --remote-debugging-port=9222
|
|
242
236
|
|
|
243
|
-
|
|
237
|
+
# macOS
|
|
238
|
+
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
|
|
244
239
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
┌─────────────────────────────────────────────┐
|
|
248
|
-
│ Terminal 1: claude ──┐ │
|
|
249
|
-
│ ├─► ~/.claude.json │ ← Race condition!
|
|
250
|
-
│ Terminal 2: claude ──┘ │
|
|
251
|
-
└─────────────────────────────────────────────┘
|
|
252
|
-
|
|
253
|
-
After (Safe):
|
|
254
|
-
┌─────────────────────────────────────────────┐
|
|
255
|
-
│ Terminal 1: launch ─► sessions/abc/.claude.json │
|
|
256
|
-
│ │ ← No conflict!
|
|
257
|
-
│ Terminal 2: launch ─► sessions/def/.claude.json │
|
|
258
|
-
└─────────────────────────────────────────────┘
|
|
240
|
+
# Linux
|
|
241
|
+
google-chrome --remote-debugging-port=9222
|
|
259
242
|
```
|
|
260
243
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
3. Sets `HOME` environment variable to session directory
|
|
265
|
-
4. Runs `claude` with all your arguments
|
|
266
|
-
5. Cleans up session on exit
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Additional Features
|
|
267
247
|
|
|
268
|
-
###
|
|
248
|
+
### Session Isolation (Bonus)
|
|
269
249
|
|
|
270
|
-
|
|
250
|
+
When running multiple Claude Code instances, they can corrupt `~/.claude.json` due to race conditions. Use the `launch` command to run Claude with isolated config:
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
# Run Claude Code with isolated config directory
|
|
254
|
+
claude-chrome-parallel launch
|
|
271
255
|
|
|
256
|
+
# Pass any claude flags
|
|
257
|
+
claude-chrome-parallel launch --dangerously-skip-permissions
|
|
258
|
+
claude-chrome-parallel launch -p "Your prompt"
|
|
272
259
|
```
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
260
|
+
|
|
261
|
+
### Config Recovery
|
|
262
|
+
|
|
263
|
+
If your `.claude.json` gets corrupted:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
# Auto-recover corrupted config
|
|
267
|
+
claude-chrome-parallel recover
|
|
268
|
+
|
|
269
|
+
# List available backups
|
|
270
|
+
claude-chrome-parallel recover --list-backups
|
|
276
271
|
```
|
|
277
272
|
|
|
278
273
|
---
|
|
279
274
|
|
|
280
|
-
##
|
|
275
|
+
## Comparison
|
|
281
276
|
|
|
282
|
-
|
|
277
|
+
| Feature | Claude in Chrome (Extension) | Claude Chrome Parallel |
|
|
278
|
+
|---------|------------------------------|----------------------|
|
|
279
|
+
| Multiple sessions | ❌ Detached errors | ✅ Works perfectly |
|
|
280
|
+
| Parallel QA testing | ❌ | ✅ |
|
|
281
|
+
| Connection type | Shared extension state | Independent CDP |
|
|
282
|
+
| Max concurrent sessions | 1 | 20+ tested |
|
|
283
|
+
| Auto Chrome launch | ❌ | ✅ |
|
|
284
|
+
| Network simulation | ❌ | ✅ 3G/4G/offline presets |
|
|
285
|
+
| Session auto-cleanup | ❌ | ✅ TTL-based |
|
|
286
|
+
| Connection pooling | ❌ | ✅ Pre-warmed pages |
|
|
283
287
|
|
|
284
|
-
|
|
285
|
-
# Check health
|
|
286
|
-
claude-chrome-parallel doctor
|
|
288
|
+
---
|
|
287
289
|
|
|
288
|
-
|
|
289
|
-
claude-chrome-parallel recover
|
|
290
|
-
```
|
|
290
|
+
## Troubleshooting
|
|
291
291
|
|
|
292
|
-
### Chrome
|
|
292
|
+
### Chrome not connecting
|
|
293
293
|
|
|
294
294
|
```bash
|
|
295
295
|
# Check status
|
|
@@ -299,7 +299,7 @@ claude-chrome-parallel check
|
|
|
299
299
|
chrome --remote-debugging-port=9222
|
|
300
300
|
```
|
|
301
301
|
|
|
302
|
-
### Tools
|
|
302
|
+
### Tools not appearing in Claude Code
|
|
303
303
|
|
|
304
304
|
1. Check MCP config in `~/.claude.json`
|
|
305
305
|
2. Restart Claude Code
|
|
@@ -322,17 +322,6 @@ npm install -g .
|
|
|
322
322
|
|
|
323
323
|
---
|
|
324
324
|
|
|
325
|
-
## Comparison
|
|
326
|
-
|
|
327
|
-
| Feature | Plain `claude` | `claude-chrome-parallel launch` |
|
|
328
|
-
|---------|----------------|--------------------------------|
|
|
329
|
-
| Multiple instances | Config corruption risk | Safe (isolated) |
|
|
330
|
-
| Browser automation | Detached errors | Works perfectly |
|
|
331
|
-
| Auto backup | | Config backed up |
|
|
332
|
-
| Recovery tools | | Built-in |
|
|
333
|
-
|
|
334
|
-
---
|
|
335
|
-
|
|
336
325
|
## License
|
|
337
326
|
|
|
338
327
|
MIT License - see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CDP Connection Pool - Pre-allocate and manage page instances for faster session creation
|
|
3
|
+
*/
|
|
4
|
+
import { Page } from 'puppeteer-core';
|
|
5
|
+
import { CDPClient } from './client';
|
|
6
|
+
export interface PoolConfig {
|
|
7
|
+
/** Minimum number of pre-allocated pages to keep ready (default: 2) */
|
|
8
|
+
minPoolSize?: number;
|
|
9
|
+
/** Maximum number of pre-allocated pages (default: 10) */
|
|
10
|
+
maxPoolSize?: number;
|
|
11
|
+
/** Page idle timeout in ms before returning to pool (default: 5 minutes) */
|
|
12
|
+
pageIdleTimeout?: number;
|
|
13
|
+
/** Whether to pre-warm pages on startup (default: true) */
|
|
14
|
+
preWarm?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface PoolStats {
|
|
17
|
+
/** Number of pages currently in the pool (ready to use) */
|
|
18
|
+
availablePages: number;
|
|
19
|
+
/** Number of pages currently in use */
|
|
20
|
+
inUsePages: number;
|
|
21
|
+
/** Total pages created since pool initialization */
|
|
22
|
+
totalPagesCreated: number;
|
|
23
|
+
/** Number of pages reused from pool */
|
|
24
|
+
pagesReused: number;
|
|
25
|
+
/** Number of pages created on-demand (pool was empty) */
|
|
26
|
+
pagesCreatedOnDemand: number;
|
|
27
|
+
/** Average time to acquire a page (ms) */
|
|
28
|
+
avgAcquireTimeMs: number;
|
|
29
|
+
}
|
|
30
|
+
export declare class CDPConnectionPool {
|
|
31
|
+
private cdpClient;
|
|
32
|
+
private config;
|
|
33
|
+
private availablePages;
|
|
34
|
+
private inUsePages;
|
|
35
|
+
private maintenanceTimer;
|
|
36
|
+
private isInitialized;
|
|
37
|
+
private totalPagesCreated;
|
|
38
|
+
private pagesReused;
|
|
39
|
+
private pagesCreatedOnDemand;
|
|
40
|
+
private acquireTimes;
|
|
41
|
+
constructor(cdpClient?: CDPClient, config?: PoolConfig);
|
|
42
|
+
/**
|
|
43
|
+
* Initialize the pool with pre-warmed pages
|
|
44
|
+
*/
|
|
45
|
+
initialize(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Acquire a page from the pool
|
|
48
|
+
*/
|
|
49
|
+
acquirePage(): Promise<Page>;
|
|
50
|
+
/**
|
|
51
|
+
* Release a page back to the pool
|
|
52
|
+
*/
|
|
53
|
+
releasePage(page: Page): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Create a new page
|
|
56
|
+
*/
|
|
57
|
+
private createNewPage;
|
|
58
|
+
/**
|
|
59
|
+
* Ensure minimum number of pages in pool
|
|
60
|
+
*/
|
|
61
|
+
private ensureMinimumPages;
|
|
62
|
+
/**
|
|
63
|
+
* Replenish pool asynchronously
|
|
64
|
+
*/
|
|
65
|
+
private replenishPoolAsync;
|
|
66
|
+
/**
|
|
67
|
+
* Perform maintenance on the pool
|
|
68
|
+
*/
|
|
69
|
+
private performMaintenance;
|
|
70
|
+
/**
|
|
71
|
+
* Get pool statistics
|
|
72
|
+
*/
|
|
73
|
+
getStats(): PoolStats;
|
|
74
|
+
/**
|
|
75
|
+
* Get current configuration
|
|
76
|
+
*/
|
|
77
|
+
getConfig(): Required<PoolConfig>;
|
|
78
|
+
/**
|
|
79
|
+
* Update configuration
|
|
80
|
+
*/
|
|
81
|
+
updateConfig(config: Partial<PoolConfig>): void;
|
|
82
|
+
/**
|
|
83
|
+
* Shutdown the pool
|
|
84
|
+
*/
|
|
85
|
+
shutdown(): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
export declare function getCDPConnectionPool(config?: PoolConfig): CDPConnectionPool;
|
|
88
|
+
//# sourceMappingURL=connection-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-pool.d.ts","sourceRoot":"","sources":["../../src/cdp/connection-pool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,SAAS,EAAgB,MAAM,UAAU,CAAC;AAEnD,MAAM,WAAW,UAAU;IACzB,uEAAuE;IACvE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4EAA4E;IAC5E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,2DAA2D;IAC3D,cAAc,EAAE,MAAM,CAAC;IACvB,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,yDAAyD;IACzD,oBAAoB,EAAE,MAAM,CAAC;IAC7B,0CAA0C;IAC1C,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAeD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,cAAc,CAAoB;IAC1C,OAAO,CAAC,UAAU,CAAoC;IACtD,OAAO,CAAC,gBAAgB,CAA+B;IACvD,OAAO,CAAC,aAAa,CAAS;IAG9B,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,oBAAoB,CAAK;IACjC,OAAO,CAAC,YAAY,CAAgB;gBAExB,SAAS,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,UAAU;IAKtD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBjC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IA2ClC;;OAEG;IACG,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAmD5C;;OAEG;YACW,aAAa;IAM3B;;OAEG;YACW,kBAAkB;IAsBhC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAQ1B;;OAEG;YACW,kBAAkB;IAiChC;;OAEG;IACH,QAAQ,IAAI,SAAS;IAgBrB;;OAEG;IACH,SAAS,IAAI,QAAQ,CAAC,UAAU,CAAC;IAIjC;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI;IAI/C;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CA6BhC;AAKD,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,iBAAiB,CAK3E"}
|