@pyrokine/mcp-chrome 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.
Files changed (100) hide show
  1. package/README.md +333 -0
  2. package/dist/anti-detection/behavior.d.ts +58 -0
  3. package/dist/anti-detection/behavior.d.ts.map +1 -0
  4. package/dist/anti-detection/behavior.js +113 -0
  5. package/dist/anti-detection/behavior.js.map +1 -0
  6. package/dist/anti-detection/index.d.ts +6 -0
  7. package/dist/anti-detection/index.d.ts.map +1 -0
  8. package/dist/anti-detection/index.js +6 -0
  9. package/dist/anti-detection/index.js.map +1 -0
  10. package/dist/anti-detection/injection.d.ts +19 -0
  11. package/dist/anti-detection/injection.d.ts.map +1 -0
  12. package/dist/anti-detection/injection.js +270 -0
  13. package/dist/anti-detection/injection.js.map +1 -0
  14. package/dist/cdp/client.d.ts +73 -0
  15. package/dist/cdp/client.d.ts.map +1 -0
  16. package/dist/cdp/client.js +275 -0
  17. package/dist/cdp/client.js.map +1 -0
  18. package/dist/cdp/index.d.ts +6 -0
  19. package/dist/cdp/index.d.ts.map +1 -0
  20. package/dist/cdp/index.js +6 -0
  21. package/dist/cdp/index.js.map +1 -0
  22. package/dist/cdp/launcher.d.ts +42 -0
  23. package/dist/cdp/launcher.d.ts.map +1 -0
  24. package/dist/cdp/launcher.js +181 -0
  25. package/dist/cdp/launcher.js.map +1 -0
  26. package/dist/core/auto-wait.d.ts +71 -0
  27. package/dist/core/auto-wait.d.ts.map +1 -0
  28. package/dist/core/auto-wait.js +165 -0
  29. package/dist/core/auto-wait.js.map +1 -0
  30. package/dist/core/errors.d.ts +123 -0
  31. package/dist/core/errors.d.ts.map +1 -0
  32. package/dist/core/errors.js +226 -0
  33. package/dist/core/errors.js.map +1 -0
  34. package/dist/core/index.d.ts +10 -0
  35. package/dist/core/index.d.ts.map +1 -0
  36. package/dist/core/index.js +10 -0
  37. package/dist/core/index.js.map +1 -0
  38. package/dist/core/locator.d.ts +130 -0
  39. package/dist/core/locator.d.ts.map +1 -0
  40. package/dist/core/locator.js +402 -0
  41. package/dist/core/locator.js.map +1 -0
  42. package/dist/core/retry.d.ts +27 -0
  43. package/dist/core/retry.d.ts.map +1 -0
  44. package/dist/core/retry.js +51 -0
  45. package/dist/core/retry.js.map +1 -0
  46. package/dist/core/session.d.ts +254 -0
  47. package/dist/core/session.d.ts.map +1 -0
  48. package/dist/core/session.js +893 -0
  49. package/dist/core/session.js.map +1 -0
  50. package/dist/core/types.d.ts +263 -0
  51. package/dist/core/types.d.ts.map +1 -0
  52. package/dist/core/types.js +90 -0
  53. package/dist/core/types.js.map +1 -0
  54. package/dist/index.d.ts +14 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +121 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/tools/browse.d.ts +92 -0
  59. package/dist/tools/browse.d.ts.map +1 -0
  60. package/dist/tools/browse.js +368 -0
  61. package/dist/tools/browse.js.map +1 -0
  62. package/dist/tools/cookies.d.ts +75 -0
  63. package/dist/tools/cookies.d.ts.map +1 -0
  64. package/dist/tools/cookies.js +230 -0
  65. package/dist/tools/cookies.js.map +1 -0
  66. package/dist/tools/evaluate.d.ts +45 -0
  67. package/dist/tools/evaluate.d.ts.map +1 -0
  68. package/dist/tools/evaluate.js +85 -0
  69. package/dist/tools/evaluate.js.map +1 -0
  70. package/dist/tools/extract.d.ts +213 -0
  71. package/dist/tools/extract.d.ts.map +1 -0
  72. package/dist/tools/extract.js +304 -0
  73. package/dist/tools/extract.js.map +1 -0
  74. package/dist/tools/index.d.ts +13 -0
  75. package/dist/tools/index.d.ts.map +1 -0
  76. package/dist/tools/index.js +13 -0
  77. package/dist/tools/index.js.map +1 -0
  78. package/dist/tools/input.d.ts +241 -0
  79. package/dist/tools/input.d.ts.map +1 -0
  80. package/dist/tools/input.js +325 -0
  81. package/dist/tools/input.js.map +1 -0
  82. package/dist/tools/logs.d.ts +57 -0
  83. package/dist/tools/logs.d.ts.map +1 -0
  84. package/dist/tools/logs.js +165 -0
  85. package/dist/tools/logs.js.map +1 -0
  86. package/dist/tools/manage.d.ts +65 -0
  87. package/dist/tools/manage.d.ts.map +1 -0
  88. package/dist/tools/manage.js +270 -0
  89. package/dist/tools/manage.js.map +1 -0
  90. package/dist/tools/schema.d.ts +261 -0
  91. package/dist/tools/schema.d.ts.map +1 -0
  92. package/dist/tools/schema.js +151 -0
  93. package/dist/tools/schema.js.map +1 -0
  94. package/dist/tools/wait.d.ts +203 -0
  95. package/dist/tools/wait.d.ts.map +1 -0
  96. package/dist/tools/wait.js +254 -0
  97. package/dist/tools/wait.js.map +1 -0
  98. package/package.json +43 -0
  99. package/scripts/start-chrome-headless.sh +37 -0
  100. package/scripts/start-chrome.sh +41 -0
package/README.md ADDED
@@ -0,0 +1,333 @@
1
+ # MCP-Chrome
2
+
3
+ English | [中文](README_zh.md)
4
+
5
+ Chrome browser automation MCP Server using Chrome DevTools Protocol (CDP).
6
+
7
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
8
+ [![Node](https://img.shields.io/badge/node-%3E%3D18-green.svg)](https://nodejs.org/)
9
+ [![MCP](https://img.shields.io/badge/MCP-compatible-purple.svg)](https://modelcontextprotocol.io/)
10
+
11
+ ## Features
12
+
13
+ - **Native CDP**: Direct Chrome DevTools Protocol communication, no Puppeteer/Playwright dependency
14
+ - **8 Unified Tools**: Reduced from 30+ granular tools to 8 action-based tools
15
+ - **Semantic Targeting**: 10 ways to locate elements (role, text, label, css, xpath, coordinates, etc.)
16
+ - **Auto-Wait**: Built-in clickability and input-ready detection
17
+ - **Structured Errors**: Every error includes code, message, suggestion, and context
18
+ - **Anti-Detection**: Optional fingerprint masking and behavior simulation
19
+
20
+ ## Compatible Clients
21
+
22
+ | Client | Status |
23
+ |---------------------------|--------|
24
+ | Claude Code | ✅ |
25
+ | Claude Desktop | ✅ |
26
+ | Cursor | ✅ |
27
+ | Windsurf | ✅ |
28
+ | Any MCP-compatible client | ✅ |
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ git clone https://github.com/Pyrokine/claude-mcp-tools.git
34
+ cd claude-mcp-tools/mcp-chrome
35
+ npm install
36
+ npm run build
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ### 1. Start Chrome with Remote Debugging
42
+
43
+ ```bash
44
+ # With UI
45
+ ./scripts/start-chrome.sh
46
+
47
+ # Headless mode
48
+ ./scripts/start-chrome-headless.sh
49
+
50
+ # Or manually:
51
+ google-chrome --remote-debugging-port=9222
52
+ ```
53
+
54
+ ### 2. Configure MCP Client
55
+
56
+ #### Claude Code
57
+
58
+ ```bash
59
+ claude mcp add chrome -- node /path/to/mcp-chrome/dist/index.js
60
+ ```
61
+
62
+ #### Claude Desktop / Other Clients
63
+
64
+ ```json
65
+ {
66
+ "mcpServers": {
67
+ "chrome": {
68
+ "command": "node",
69
+ "args": ["/path/to/mcp-chrome/dist/index.js"]
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ ## Available Tools (8 Tools)
76
+
77
+ ### browse - Browser Management & Navigation
78
+
79
+ | Action | Description |
80
+ |-----------|--------------------------------------------------------------|
81
+ | `launch` | Launch new Chrome instance |
82
+ | `connect` | Connect to running Chrome (requires --remote-debugging-port) |
83
+ | `list` | List all available pages/targets |
84
+ | `attach` | Attach to a specific page |
85
+ | `open` | Navigate to URL |
86
+ | `back` | Go back in history |
87
+ | `forward` | Go forward in history |
88
+ | `refresh` | Reload page |
89
+ | `close` | Close browser |
90
+
91
+ **Anti-detection modes** (for `launch`/`connect`):
92
+
93
+ | Mode | Description |
94
+ |--------------|-----------------------------------------------------------------------|
95
+ | `off` | Disabled - pure mode for testing/CI |
96
+ | `safe` | Minimal changes (default) - removes webdriver flag, cleans CDP traces |
97
+ | `aggressive` | Full masking - plugins, WebGL, languages (may have side effects) |
98
+
99
+ ### input - Keyboard & Mouse Input
100
+
101
+ Event sequence model supporting arbitrary combinations:
102
+
103
+ | Event Type | Description |
104
+ |-----------------------------------------|----------------------------|
105
+ | `keydown` / `keyup` | Key press/release |
106
+ | `mousedown` / `mouseup` | Mouse button press/release |
107
+ | `mousemove` | Mouse movement |
108
+ | `wheel` | Mouse wheel scroll |
109
+ | `touchstart` / `touchmove` / `touchend` | Touch events |
110
+ | `type` | Type text |
111
+ | `wait` | Pause between events |
112
+
113
+ ### extract - Content Extraction
114
+
115
+ | Type | Description |
116
+ |--------------|---------------------------------------------------|
117
+ | `text` | Extract text content |
118
+ | `html` | Extract HTML source |
119
+ | `attribute` | Extract element attribute |
120
+ | `screenshot` | Take screenshot |
121
+ | `state` | Get page state (URL, title, interactive elements) |
122
+
123
+ ### wait - Wait for Conditions
124
+
125
+ | For | Description |
126
+ |--------------|-----------------------------------------------------|
127
+ | `element` | Wait for element (visible/hidden/attached/detached) |
128
+ | `navigation` | Wait for navigation complete |
129
+ | `time` | Fixed delay |
130
+ | `idle` | Wait for network idle |
131
+
132
+ ### manage - Page & Environment Management
133
+
134
+ | Action | Description |
135
+ |--------------|---------------------------------------|
136
+ | `newPage` | Create new page/tab |
137
+ | `closePage` | Close page |
138
+ | `clearCache` | Clear cache/cookies/storage |
139
+ | `viewport` | Set viewport size |
140
+ | `userAgent` | Set User-Agent |
141
+ | `emulate` | Device emulation (iPhone, iPad, etc.) |
142
+
143
+ ### logs - Browser Logs
144
+
145
+ | Type | Description |
146
+ |-----------|----------------------------------------|
147
+ | `console` | Console logs (with level filter) |
148
+ | `network` | Network request logs (with URL filter) |
149
+
150
+ ### cookies - Cookie Management
151
+
152
+ | Action | Description |
153
+ |----------|-------------------|
154
+ | `get` | Get cookies |
155
+ | `set` | Set cookie |
156
+ | `delete` | Delete cookie |
157
+ | `clear` | Clear all cookies |
158
+
159
+ ### evaluate - JavaScript Execution
160
+
161
+ Execute arbitrary JavaScript in page context.
162
+
163
+ ## Target: Unified Element Locator
164
+
165
+ All tools use a unified `Target` type for element location:
166
+
167
+ ```typescript
168
+ // By accessibility (recommended - most stable)
169
+ { role: "button", name: "Submit" }
170
+
171
+ // By text content
172
+ { text: "Click here", exact: true }
173
+
174
+ // By form label
175
+ { label: "Email" }
176
+
177
+ // By placeholder
178
+ { placeholder: "Enter your name" }
179
+
180
+ // By title attribute
181
+ { title: "Close dialog" }
182
+
183
+ // By alt text (images)
184
+ { alt: "Profile picture" }
185
+
186
+ // By test ID
187
+ { testId: "submit-button" }
188
+
189
+ // By CSS selector
190
+ { css: "#login-form .submit-btn" }
191
+
192
+ // By XPath
193
+ { xpath: "//button[@type='submit']" }
194
+
195
+ // By coordinates
196
+ { x: 100, y: 200 }
197
+ ```
198
+
199
+ ## Usage Examples
200
+
201
+ ### Basic: Connect and Navigate
202
+
203
+ ```
204
+ browse(action="connect", port=9222)
205
+ browse(action="open", url="https://example.com")
206
+ extract(type="state")
207
+ ```
208
+
209
+ ### Click a Button
210
+
211
+ ```
212
+ input(events=[
213
+ { type: "mousedown", target: { role: "button", name: "Submit" } },
214
+ { type: "mouseup" }
215
+ ])
216
+ ```
217
+
218
+ ### Type in Input Field
219
+
220
+ ```
221
+ input(events=[
222
+ { type: "mousedown", target: { label: "Email" } },
223
+ { type: "mouseup" },
224
+ { type: "type", text: "user@example.com" }
225
+ ])
226
+ ```
227
+
228
+ ### Complex: Ctrl+Click with Human-like Movement
229
+
230
+ ```
231
+ input(events=[
232
+ { type: "keydown", key: "Control" },
233
+ { type: "mousedown", target: { css: ".item" }, button: "left" },
234
+ { type: "mouseup" },
235
+ { type: "keyup", key: "Control" }
236
+ ], humanize=true)
237
+ ```
238
+
239
+ ### Screenshot
240
+
241
+ ```
242
+ // Full page
243
+ extract(type="screenshot", fullPage=true)
244
+
245
+ // Specific element
246
+ extract(type="screenshot", target={ css: "#chart" })
247
+ ```
248
+
249
+ ### Wait for Element
250
+
251
+ ```
252
+ wait(for="element", target={ text: "Loading complete" }, state="visible")
253
+ ```
254
+
255
+ ## Architecture
256
+
257
+ ```
258
+ ┌─────────────────┐
259
+ │ MCP Client │
260
+ │ (Claude, etc.) │
261
+ └────────┬────────┘
262
+ │ stdio (JSON-RPC)
263
+
264
+ ┌─────────────────┐
265
+ │ MCP-Chrome │
266
+ │ (8 tools) │
267
+ │ ├─ core/ │ Session, Locator, AutoWait
268
+ │ ├─ cdp/ │ Native CDP client
269
+ │ └─ tools/ │ Tool implementations
270
+ └────────┬────────┘
271
+ │ WebSocket (CDP)
272
+
273
+ ┌─────────────────┐
274
+ │ Chrome Browser │
275
+ │ (port 9222) │
276
+ └─────────────────┘
277
+ ```
278
+
279
+ ## Project Structure
280
+
281
+ ```
282
+ mcp-chrome/
283
+ ├── src/
284
+ │ ├── index.ts # MCP Server entry
285
+ │ ├── tools/ # 8 MCP tools
286
+ │ │ ├── browse.ts
287
+ │ │ ├── input.ts
288
+ │ │ ├── extract.ts
289
+ │ │ ├── wait.ts
290
+ │ │ ├── manage.ts
291
+ │ │ ├── logs.ts
292
+ │ │ ├── cookies.ts
293
+ │ │ ├── evaluate.ts
294
+ │ │ └── schema.ts # Shared JSON Schema (Target oneOf)
295
+ │ ├── core/ # Core abstractions
296
+ │ │ ├── session.ts # Session management
297
+ │ │ ├── locator.ts # Element locator
298
+ │ │ ├── auto-wait.ts # Auto-wait mechanism
299
+ │ │ ├── retry.ts # Retry logic
300
+ │ │ ├── types.ts # Type definitions
301
+ │ │ └── errors.ts # Error types
302
+ │ ├── cdp/ # CDP layer
303
+ │ │ ├── client.ts # WebSocket CDP client
304
+ │ │ └── launcher.ts # Chrome launcher
305
+ │ └── anti-detection/ # Anti-detection (optional)
306
+ │ ├── injection.ts
307
+ │ └── behavior.ts
308
+ ├── scripts/
309
+ │ ├── start-chrome.sh
310
+ │ └── start-chrome-headless.sh
311
+ └── package.json
312
+ ```
313
+
314
+ ## Security Notes
315
+
316
+ - CDP provides full browser control - use only on trusted machines
317
+ - Default debugging port binds to 127.0.0.1 only
318
+ - The `evaluate` tool can execute arbitrary JavaScript
319
+ - Network logs may contain sensitive information
320
+
321
+ ## Known Limitations
322
+
323
+ - **Single session**: Currently supports one browser session at a time
324
+ - **Chrome only**: Only supports Chrome/Chromium browsers (no Firefox/Safari)
325
+
326
+ ## License
327
+
328
+ MIT License - see [LICENSE](LICENSE) for details.
329
+
330
+ ## Related Projects
331
+
332
+ - [Model Context Protocol](https://modelcontextprotocol.io/) - MCP specification
333
+ - [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) - CDP documentation
@@ -0,0 +1,58 @@
1
+ /**
2
+ * 行为模拟
3
+ *
4
+ * 模拟人类操作行为,包括:
5
+ * - 贝塞尔曲线鼠标移动
6
+ * - 随机延迟
7
+ * - 打字速度变化
8
+ *
9
+ * 注意:这些是可选功能,需要显式启用(humanize: true)
10
+ */
11
+ import type { Point } from '../core/types.js';
12
+ /**
13
+ * 随机延迟
14
+ */
15
+ export declare function randomDelay(min: number, max: number): Promise<void>;
16
+ /**
17
+ * 生成贝塞尔曲线路径点
18
+ *
19
+ * @param from 起点
20
+ * @param to 终点
21
+ * @param steps 步数(默认根据距离计算)
22
+ * @returns 路径点数组
23
+ */
24
+ export declare function generateBezierPath(from: Point, to: Point, steps?: number): Point[];
25
+ /**
26
+ * 获取随机打字延迟(模拟人类打字速度)
27
+ *
28
+ * @param baseDelay 基础延迟(毫秒)
29
+ * @returns 随机化后的延迟
30
+ */
31
+ export declare function getTypingDelay(baseDelay?: number): number;
32
+ /**
33
+ * 获取鼠标移动间隔延迟
34
+ */
35
+ export declare function getMouseMoveDelay(): number;
36
+ /**
37
+ * 行为模拟器
38
+ */
39
+ export declare class BehaviorSimulator {
40
+ private currentPosition;
41
+ /**
42
+ * 获取当前鼠标位置
43
+ */
44
+ getCurrentPosition(): Point;
45
+ /**
46
+ * 更新当前鼠标位置
47
+ */
48
+ setCurrentPosition(point: Point): void;
49
+ /**
50
+ * 生成人类化的鼠标移动路径
51
+ */
52
+ generateHumanMousePath(to: Point): Point[];
53
+ /**
54
+ * 生成人类化的打字延迟序列
55
+ */
56
+ generateTypingDelays(textLength: number, baseDelay?: number): number[];
57
+ }
58
+ //# sourceMappingURL=behavior.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"behavior.d.ts","sourceRoot":"","sources":["../../src/anti-detection/behavior.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,kBAAkB,CAAA;AAE3C;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGnE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAC9B,IAAI,EAAE,KAAK,EACX,EAAE,EAAE,KAAK,EACT,KAAK,CAAC,EAAE,MAAM,GACf,KAAK,EAAE,CA4BT;AAwBD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,SAAS,GAAE,MAAY,GAAG,MAAM,CAI9D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAG1C;AAED;;GAEG;AACH,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,eAAe,CAAsB;IAE7C;;OAEG;IACH,kBAAkB,IAAI,KAAK;IAI3B;;OAEG;IACH,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAItC;;OAEG;IACH,sBAAsB,CAAC,EAAE,EAAE,KAAK,GAAG,KAAK,EAAE;IAI1C;;OAEG;IACH,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,GAAE,MAAY,GAAG,MAAM,EAAE;CAO9E"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * 行为模拟
3
+ *
4
+ * 模拟人类操作行为,包括:
5
+ * - 贝塞尔曲线鼠标移动
6
+ * - 随机延迟
7
+ * - 打字速度变化
8
+ *
9
+ * 注意:这些是可选功能,需要显式启用(humanize: true)
10
+ */
11
+ /**
12
+ * 随机延迟
13
+ */
14
+ export function randomDelay(min, max) {
15
+ const ms = min + Math.random() * (max - min);
16
+ return new Promise((resolve) => setTimeout(resolve, ms));
17
+ }
18
+ /**
19
+ * 生成贝塞尔曲线路径点
20
+ *
21
+ * @param from 起点
22
+ * @param to 终点
23
+ * @param steps 步数(默认根据距离计算)
24
+ * @returns 路径点数组
25
+ */
26
+ export function generateBezierPath(from, to, steps) {
27
+ // 计算距离
28
+ const distance = Math.sqrt(Math.pow(to.x - from.x, 2) + Math.pow(to.y - from.y, 2));
29
+ // 根据距离计算步数,距离越远步数越多
30
+ const numSteps = steps ?? Math.max(20, Math.floor(distance / 10));
31
+ // 生成随机控制点
32
+ const control1 = {
33
+ x: from.x + (to.x - from.x) * 0.3 + (Math.random() - 0.5) * 50,
34
+ y: from.y + (to.y - from.y) * 0.1 + (Math.random() - 0.5) * 50,
35
+ };
36
+ const control2 = {
37
+ x: from.x + (to.x - from.x) * 0.7 + (Math.random() - 0.5) * 50,
38
+ y: from.y + (to.y - from.y) * 0.9 + (Math.random() - 0.5) * 50,
39
+ };
40
+ const points = [];
41
+ for (let i = 0; i <= numSteps; i++) {
42
+ const t = i / numSteps;
43
+ points.push(bezierPoint(from, control1, control2, to, t));
44
+ }
45
+ return points;
46
+ }
47
+ /**
48
+ * 计算三次贝塞尔曲线上的点
49
+ */
50
+ function bezierPoint(p0, p1, p2, p3, t) {
51
+ const u = 1 - t;
52
+ const tt = t * t;
53
+ const uu = u * u;
54
+ const uuu = uu * u;
55
+ const ttt = tt * t;
56
+ return {
57
+ x: uuu * p0.x + 3 * uu * t * p1.x + 3 * u * tt * p2.x + ttt * p3.x,
58
+ y: uuu * p0.y + 3 * uu * t * p1.y + 3 * u * tt * p2.y + ttt * p3.y,
59
+ };
60
+ }
61
+ /**
62
+ * 获取随机打字延迟(模拟人类打字速度)
63
+ *
64
+ * @param baseDelay 基础延迟(毫秒)
65
+ * @returns 随机化后的延迟
66
+ */
67
+ export function getTypingDelay(baseDelay = 100) {
68
+ // 添加 ±50% 的随机变化
69
+ const variation = baseDelay * 0.5;
70
+ return baseDelay + (Math.random() - 0.5) * 2 * variation;
71
+ }
72
+ /**
73
+ * 获取鼠标移动间隔延迟
74
+ */
75
+ export function getMouseMoveDelay() {
76
+ // 5-15ms 随机延迟
77
+ return 5 + Math.random() * 10;
78
+ }
79
+ /**
80
+ * 行为模拟器
81
+ */
82
+ export class BehaviorSimulator {
83
+ currentPosition = { x: 0, y: 0 };
84
+ /**
85
+ * 获取当前鼠标位置
86
+ */
87
+ getCurrentPosition() {
88
+ return { ...this.currentPosition };
89
+ }
90
+ /**
91
+ * 更新当前鼠标位置
92
+ */
93
+ setCurrentPosition(point) {
94
+ this.currentPosition = { ...point };
95
+ }
96
+ /**
97
+ * 生成人类化的鼠标移动路径
98
+ */
99
+ generateHumanMousePath(to) {
100
+ return generateBezierPath(this.currentPosition, to);
101
+ }
102
+ /**
103
+ * 生成人类化的打字延迟序列
104
+ */
105
+ generateTypingDelays(textLength, baseDelay = 100) {
106
+ const delays = [];
107
+ for (let i = 0; i < textLength; i++) {
108
+ delays.push(getTypingDelay(baseDelay));
109
+ }
110
+ return delays;
111
+ }
112
+ }
113
+ //# sourceMappingURL=behavior.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"behavior.js","sourceRoot":"","sources":["../../src/anti-detection/behavior.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,GAAW;IAChD,MAAM,EAAE,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAA;IAC5C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAC5D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAC9B,IAAW,EACX,EAAS,EACT,KAAc;IAEd,OAAO;IACP,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CACtB,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC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iB;IAC7B,cAAc;IACd,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAA;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAClB,eAAe,GAAU,EAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAC,CAAA;IAE7C;;OAEG;IACH,kBAAkB;QACd,OAAO,EAAC,GAAG,IAAI,CAAC,eAAe,EAAC,CAAA;IACpC,CAAC;IAED;;OAEG;IACH,kBAAkB,CAAC,KAAY;QAC3B,IAAI,CAAC,eAAe,GAAG,EAAC,GAAG,KAAK,EAAC,CAAA;IACrC,CAAC;IAED;;OAEG;IACH,sBAAsB,CAAC,EAAS;QAC5B,OAAO,kBAAkB,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC,CAAA;IACvD,CAAC;IAED;;OAEG;IACH,oBAAoB,CAAC,UAAkB,EAAE,YAAoB,GAAG;QAC5D,MAAM,MAAM,GAAa,EAAE,CAAA;QAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;YAClC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAA;QAC1C,CAAC;QACD,OAAO,MAAM,CAAA;IACjB,CAAC;CACJ"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 反检测模块导出
3
+ */
4
+ export { getAntiDetectionScript } from './injection.js';
5
+ export { randomDelay, generateBezierPath, getTypingDelay, getMouseMoveDelay, BehaviorSimulator, } from './behavior.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/anti-detection/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAC,sBAAsB,EAAC,MAAM,gBAAgB,CAAA;AACrD,OAAO,EACH,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,iBAAiB,GACpB,MAAM,eAAe,CAAA"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 反检测模块导出
3
+ */
4
+ export { getAntiDetectionScript } from './injection.js';
5
+ export { randomDelay, generateBezierPath, getTypingDelay, getMouseMoveDelay, BehaviorSimulator, } from './behavior.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/anti-detection/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAC,sBAAsB,EAAC,MAAM,gBAAgB,CAAA;AACrD,OAAO,EACH,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,iBAAiB,GACpB,MAAM,eAAe,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * 反检测注入脚本
3
+ *
4
+ * 在页面加载前注入,用于:
5
+ * - 移除 navigator.webdriver
6
+ * - 清理 CDP 痕迹
7
+ * - 模拟真实浏览器指纹
8
+ *
9
+ * 模式:
10
+ * - safe: 最小改动(移除 webdriver、清理 CDP 痕迹)
11
+ * - aggressive: 完整伪装(插件、WebGL、语言等)
12
+ */
13
+ type StealthMode = 'safe' | 'aggressive';
14
+ /**
15
+ * 获取反检测注入脚本
16
+ */
17
+ export declare function getAntiDetectionScript(mode?: StealthMode): string;
18
+ export {};
19
+ //# sourceMappingURL=injection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injection.d.ts","sourceRoot":"","sources":["../../src/anti-detection/injection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,KAAK,WAAW,GAAG,MAAM,GAAG,YAAY,CAAC;AAEzC;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,GAAE,WAAoB,GAAG,MAAM,CA+PzE"}