@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookies.js","sourceRoot":"","sources":["../../src/tools/cookies.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAA;AACrC,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAA;AACrB,OAAO,EAAC,mBAAmB,EAAE,UAAU,EAAC,MAAM,kBAAkB,CAAA;AAEhE;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACjC,IAAI,EAAE,SAAS;IACf,WAAW,EAAE,uBAAuB;IACpC,WAAW,EAAE;QACT,IAAI,EAAE,QAAiB;QACvB,UAAU,EAAE;YACR,MAAM,EAAE;gBACJ,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC;gBACvC,WAAW,EAAE,MAAM;aACtB;YACD,IAAI,EAAE;gBACF,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,0BAA0B;aAC1C;YACD,KAAK,EAAE;gBACH,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,eAAe;aAC/B;YACD,OAAO,EAAE;gBACL,IAAI,EAAE,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CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAA;IACrC,CAAC;AACL,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * evaluate 工具
3
+ *
4
+ * 在页面上下文执行 JavaScript
5
+ */
6
+ /**
7
+ * evaluate 工具定义
8
+ */
9
+ export declare const evaluateToolDefinition: {
10
+ name: string;
11
+ description: string;
12
+ inputSchema: {
13
+ type: "object";
14
+ properties: {
15
+ script: {
16
+ type: string;
17
+ description: string;
18
+ };
19
+ args: {
20
+ type: string;
21
+ description: string;
22
+ };
23
+ output: {
24
+ type: string;
25
+ description: string;
26
+ };
27
+ timeout: {
28
+ type: string;
29
+ description: string;
30
+ };
31
+ };
32
+ required: string[];
33
+ };
34
+ };
35
+ /**
36
+ * evaluate 工具处理器
37
+ */
38
+ export declare function handleEvaluate(params: unknown): Promise<{
39
+ content: Array<{
40
+ type: 'text';
41
+ text: string;
42
+ }>;
43
+ isError?: boolean;
44
+ }>;
45
+ //# sourceMappingURL=evaluate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/tools/evaluate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;CAyBlC,CAAA;AAcD;;GAEG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC;IAC3D,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC,CA4CD"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * evaluate 工具
3
+ *
4
+ * 在页面上下文执行 JavaScript
5
+ */
6
+ import { writeFile } from 'fs/promises';
7
+ import { z } from 'zod';
8
+ import { formatErrorResponse, getSession } from '../core/index.js';
9
+ /**
10
+ * evaluate 工具定义
11
+ */
12
+ export const evaluateToolDefinition = {
13
+ name: 'evaluate',
14
+ description: '在页面上下文执行 JavaScript',
15
+ inputSchema: {
16
+ type: 'object',
17
+ properties: {
18
+ script: {
19
+ type: 'string',
20
+ description: 'JavaScript 代码',
21
+ },
22
+ args: {
23
+ type: 'array',
24
+ description: '传递给脚本的参数',
25
+ },
26
+ output: {
27
+ type: 'string',
28
+ description: '输出文件路径(可选)。若指定,结果序列化为 JSON 写入文件',
29
+ },
30
+ timeout: {
31
+ type: 'number',
32
+ description: '脚本执行超时',
33
+ },
34
+ },
35
+ required: ['script'],
36
+ },
37
+ };
38
+ /**
39
+ * evaluate 参数 schema
40
+ */
41
+ const evaluateSchema = z.object({
42
+ script: z.string(),
43
+ args: z.array(z.unknown()).optional(),
44
+ output: z.string().optional(),
45
+ timeout: z.number().optional(),
46
+ });
47
+ /**
48
+ * evaluate 工具处理器
49
+ */
50
+ export async function handleEvaluate(params) {
51
+ try {
52
+ const args = evaluateSchema.parse(params);
53
+ const session = getSession();
54
+ const result = await session.evaluate(args.script, args.args, args.timeout);
55
+ if (args.output) {
56
+ await writeFile(args.output, JSON.stringify(result, null, 2), 'utf-8');
57
+ return {
58
+ content: [
59
+ {
60
+ type: 'text',
61
+ text: JSON.stringify({
62
+ success: true,
63
+ output: args.output,
64
+ }),
65
+ },
66
+ ],
67
+ };
68
+ }
69
+ return {
70
+ content: [
71
+ {
72
+ type: 'text',
73
+ text: JSON.stringify({
74
+ success: true,
75
+ result,
76
+ }, null, 2),
77
+ },
78
+ ],
79
+ };
80
+ }
81
+ catch (error) {
82
+ return formatErrorResponse(error);
83
+ }
84
+ }
85
+ //# sourceMappingURL=evaluate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../src/tools/evaluate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,SAAS,E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C,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;QAE3E,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,MAAM,SAAS,CACX,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAC/B,OAAO,CACV,CAAA;YACD,OAAO;gBACH,OAAO,EAAE;oBACL;wBACI,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;4BACI,OAAO,EAAE,IAAI;4BACb,MAAM,EAAE,IAAI,CAAC,MAAM;yBACtB,CAAC;qBAC1B;iBACJ;aACJ,CAAA;QACL,CAAC;QAED,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAChB;wBACI,OAAO,EAAE,IAAI;wBACb,MAAM;qBACT,EACD,IAAI,EACJ,CAAC,CACJ;iBACJ;aACJ;SACJ,CAAA;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAA;IACrC,CAAC;AACL,CAAC"}
@@ -0,0 +1,213 @@
1
+ /**
2
+ * extract 工具
3
+ *
4
+ * 提取页面内容:
5
+ * - text: 文本内容
6
+ * - html: HTML 源码
7
+ * - attribute: 元素属性
8
+ * - screenshot: 截图
9
+ * - state: 页面状态(精简的可交互元素列表)
10
+ */
11
+ /**
12
+ * extract 工具定义
13
+ */
14
+ export declare const extractToolDefinition: {
15
+ name: string;
16
+ description: string;
17
+ inputSchema: {
18
+ type: "object";
19
+ properties: {
20
+ type: {
21
+ type: string;
22
+ enum: string[];
23
+ description: string;
24
+ };
25
+ target: {
26
+ description: string;
27
+ oneOf: readonly [{
28
+ readonly type: "object";
29
+ readonly title: "可访问性树定位";
30
+ readonly description: "通过 ARIA role 和 name 定位元素";
31
+ readonly properties: {
32
+ readonly role: {
33
+ readonly type: "string";
34
+ readonly description: "ARIA role(如 button、link、textbox)";
35
+ };
36
+ readonly name: {
37
+ readonly type: "string";
38
+ readonly description: "可访问名称(可选)";
39
+ };
40
+ };
41
+ readonly required: readonly ["role"];
42
+ readonly additionalProperties: false;
43
+ }, {
44
+ readonly type: "object";
45
+ readonly title: "文本内容定位";
46
+ readonly description: "通过元素文本内容定位";
47
+ readonly properties: {
48
+ readonly text: {
49
+ readonly type: "string";
50
+ readonly description: "文本内容";
51
+ };
52
+ readonly exact: {
53
+ readonly type: "boolean";
54
+ readonly description: "是否精确匹配(默认 false)";
55
+ };
56
+ };
57
+ readonly required: readonly ["text"];
58
+ readonly additionalProperties: false;
59
+ }, {
60
+ readonly type: "object";
61
+ readonly title: "Label 定位";
62
+ readonly description: "通过表单 label 文本定位关联的输入元素";
63
+ readonly properties: {
64
+ readonly label: {
65
+ readonly type: "string";
66
+ readonly description: "label 文本";
67
+ };
68
+ readonly exact: {
69
+ readonly type: "boolean";
70
+ readonly description: "是否精确匹配(默认 false)";
71
+ };
72
+ };
73
+ readonly required: readonly ["label"];
74
+ readonly additionalProperties: false;
75
+ }, {
76
+ readonly type: "object";
77
+ readonly title: "Placeholder 定位";
78
+ readonly description: "通过输入框的 placeholder 属性定位";
79
+ readonly properties: {
80
+ readonly placeholder: {
81
+ readonly type: "string";
82
+ readonly description: "placeholder 文本";
83
+ };
84
+ readonly exact: {
85
+ readonly type: "boolean";
86
+ readonly description: "是否精确匹配(默认 false)";
87
+ };
88
+ };
89
+ readonly required: readonly ["placeholder"];
90
+ readonly additionalProperties: false;
91
+ }, {
92
+ readonly type: "object";
93
+ readonly title: "Title 属性定位";
94
+ readonly description: "通过元素的 title 属性定位";
95
+ readonly properties: {
96
+ readonly title: {
97
+ readonly type: "string";
98
+ readonly description: "title 属性值";
99
+ };
100
+ readonly exact: {
101
+ readonly type: "boolean";
102
+ readonly description: "是否精确匹配(默认 false)";
103
+ };
104
+ };
105
+ readonly required: readonly ["title"];
106
+ readonly additionalProperties: false;
107
+ }, {
108
+ readonly type: "object";
109
+ readonly title: "Alt 属性定位";
110
+ readonly description: "通过图片的 alt 属性定位";
111
+ readonly properties: {
112
+ readonly alt: {
113
+ readonly type: "string";
114
+ readonly description: "alt 属性值";
115
+ };
116
+ readonly exact: {
117
+ readonly type: "boolean";
118
+ readonly description: "是否精确匹配(默认 false)";
119
+ };
120
+ };
121
+ readonly required: readonly ["alt"];
122
+ readonly additionalProperties: false;
123
+ }, {
124
+ readonly type: "object";
125
+ readonly title: "TestId 定位";
126
+ readonly description: "通过 data-testid 属性定位";
127
+ readonly properties: {
128
+ readonly testId: {
129
+ readonly type: "string";
130
+ readonly description: "data-testid 值";
131
+ };
132
+ };
133
+ readonly required: readonly ["testId"];
134
+ readonly additionalProperties: false;
135
+ }, {
136
+ readonly type: "object";
137
+ readonly title: "CSS 选择器定位";
138
+ readonly description: "通过 CSS 选择器定位";
139
+ readonly properties: {
140
+ readonly css: {
141
+ readonly type: "string";
142
+ readonly description: "CSS 选择器";
143
+ };
144
+ };
145
+ readonly required: readonly ["css"];
146
+ readonly additionalProperties: false;
147
+ }, {
148
+ readonly type: "object";
149
+ readonly title: "XPath 定位";
150
+ readonly description: "通过 XPath 表达式定位";
151
+ readonly properties: {
152
+ readonly xpath: {
153
+ readonly type: "string";
154
+ readonly description: "XPath 表达式";
155
+ };
156
+ };
157
+ readonly required: readonly ["xpath"];
158
+ readonly additionalProperties: false;
159
+ }, {
160
+ readonly type: "object";
161
+ readonly title: "坐标定位";
162
+ readonly description: "通过页面坐标定位";
163
+ readonly properties: {
164
+ readonly x: {
165
+ readonly type: "number";
166
+ readonly description: "X 坐标(像素)";
167
+ };
168
+ readonly y: {
169
+ readonly type: "number";
170
+ readonly description: "Y 坐标(像素)";
171
+ };
172
+ };
173
+ readonly required: readonly ["x", "y"];
174
+ readonly additionalProperties: false;
175
+ }];
176
+ };
177
+ attribute: {
178
+ type: string;
179
+ description: string;
180
+ };
181
+ fullPage: {
182
+ type: string;
183
+ description: string;
184
+ };
185
+ selector: {
186
+ type: string;
187
+ description: string;
188
+ };
189
+ output: {
190
+ type: string;
191
+ description: string;
192
+ };
193
+ timeout: {
194
+ type: string;
195
+ description: string;
196
+ };
197
+ };
198
+ required: string[];
199
+ };
200
+ };
201
+ /**
202
+ * extract 工具处理器
203
+ */
204
+ export declare function handleExtract(params: unknown): Promise<{
205
+ content: Array<{
206
+ type: 'text' | 'image';
207
+ text?: string;
208
+ data?: string;
209
+ mimeType?: string;
210
+ }>;
211
+ isError?: boolean;
212
+ }>;
213
+ //# sourceMappingURL=extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/tools/extract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCjC,CAAA;AAiBD;;GAEG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC;IAC1D,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC5F,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC,CA2MD"}
@@ -0,0 +1,304 @@
1
+ /**
2
+ * extract 工具
3
+ *
4
+ * 提取页面内容:
5
+ * - text: 文本内容
6
+ * - html: HTML 源码
7
+ * - attribute: 元素属性
8
+ * - screenshot: 截图
9
+ * - state: 页面状态(精简的可交互元素列表)
10
+ */
11
+ import { writeFile } from 'fs/promises';
12
+ import { z } from 'zod';
13
+ import { formatErrorResponse, getSession } from '../core/index.js';
14
+ import { targetJsonSchema, targetZodSchema } from './schema.js';
15
+ /**
16
+ * extract 工具定义
17
+ */
18
+ export const extractToolDefinition = {
19
+ name: 'extract',
20
+ description: '提取页面内容:文本、HTML、属性、截图、状态',
21
+ inputSchema: {
22
+ type: 'object',
23
+ properties: {
24
+ type: {
25
+ type: 'string',
26
+ enum: ['text', 'html', 'attribute', 'screenshot', 'state'],
27
+ description: '提取类型',
28
+ },
29
+ target: {
30
+ ...targetJsonSchema,
31
+ description: '目标元素(attribute 必填;text/html 可选,省略则提取整个页面;screenshot/state 不需要)',
32
+ },
33
+ attribute: {
34
+ type: 'string',
35
+ description: '属性名(attribute)',
36
+ },
37
+ fullPage: {
38
+ type: 'boolean',
39
+ description: '是否全页面截图(screenshot)',
40
+ },
41
+ selector: {
42
+ type: 'string',
43
+ description: '限制范围(state)',
44
+ },
45
+ output: {
46
+ type: 'string',
47
+ description: '输出文件路径(可选)。若指定,结果写入文件;否则返回内容',
48
+ },
49
+ timeout: {
50
+ type: 'number',
51
+ description: '等待目标元素超时',
52
+ },
53
+ },
54
+ required: ['type'],
55
+ },
56
+ };
57
+ /**
58
+ * extract 参数 schema
59
+ */
60
+ const extractSchema = z.object({
61
+ type: z.enum(['text', 'html', 'attribute', 'screenshot', 'state']),
62
+ target: targetZodSchema.optional(),
63
+ attribute: z.string().optional(),
64
+ fullPage: z.boolean().optional(),
65
+ selector: z.string().optional(),
66
+ output: z.string().optional(),
67
+ timeout: z.number().optional(),
68
+ });
69
+ /**
70
+ * extract 工具处理器
71
+ */
72
+ export async function handleExtract(params) {
73
+ try {
74
+ const args = extractSchema.parse(params);
75
+ const session = getSession();
76
+ switch (args.type) {
77
+ case 'text': {
78
+ const text = await extractText(session, args.target);
79
+ if (args.output) {
80
+ await writeFile(args.output, text, 'utf-8');
81
+ return {
82
+ content: [
83
+ {
84
+ type: 'text',
85
+ text: JSON.stringify({
86
+ success: true,
87
+ type: 'text',
88
+ output: args.output,
89
+ size: text.length,
90
+ }),
91
+ },
92
+ ],
93
+ };
94
+ }
95
+ return {
96
+ content: [
97
+ {
98
+ type: 'text',
99
+ text: JSON.stringify({
100
+ success: true,
101
+ type: 'text',
102
+ content: text,
103
+ }),
104
+ },
105
+ ],
106
+ };
107
+ }
108
+ case 'html': {
109
+ const html = await extractHTML(session, args.target);
110
+ if (args.output) {
111
+ await writeFile(args.output, html, 'utf-8');
112
+ return {
113
+ content: [
114
+ {
115
+ type: 'text',
116
+ text: JSON.stringify({
117
+ success: true,
118
+ type: 'html',
119
+ output: args.output,
120
+ size: html.length,
121
+ }),
122
+ },
123
+ ],
124
+ };
125
+ }
126
+ return {
127
+ content: [
128
+ {
129
+ type: 'text',
130
+ text: JSON.stringify({
131
+ success: true,
132
+ type: 'html',
133
+ content: html,
134
+ }),
135
+ },
136
+ ],
137
+ };
138
+ }
139
+ case 'attribute': {
140
+ if (!args.target) {
141
+ return {
142
+ content: [
143
+ {
144
+ type: 'text',
145
+ text: JSON.stringify({
146
+ error: {
147
+ code: 'INVALID_ARGUMENT',
148
+ message: 'attribute 提取需要 target 参数',
149
+ },
150
+ }),
151
+ },
152
+ ],
153
+ isError: true,
154
+ };
155
+ }
156
+ if (!args.attribute) {
157
+ return {
158
+ content: [
159
+ {
160
+ type: 'text',
161
+ text: JSON.stringify({
162
+ error: {
163
+ code: 'INVALID_ARGUMENT',
164
+ message: 'attribute 提取需要 attribute 参数',
165
+ },
166
+ }),
167
+ },
168
+ ],
169
+ isError: true,
170
+ };
171
+ }
172
+ const value = await extractAttribute(session, args.target, args.attribute);
173
+ return {
174
+ content: [
175
+ {
176
+ type: 'text',
177
+ text: JSON.stringify({
178
+ success: true,
179
+ type: 'attribute',
180
+ attribute: args.attribute,
181
+ value,
182
+ }),
183
+ },
184
+ ],
185
+ };
186
+ }
187
+ case 'screenshot': {
188
+ const base64 = await session.screenshot(args.fullPage ?? false);
189
+ if (args.output) {
190
+ // 写入文件
191
+ await writeFile(args.output, Buffer.from(base64, 'base64'));
192
+ return {
193
+ content: [
194
+ {
195
+ type: 'text',
196
+ text: JSON.stringify({
197
+ success: true,
198
+ type: 'screenshot',
199
+ output: args.output,
200
+ }),
201
+ },
202
+ ],
203
+ };
204
+ }
205
+ // 返回 base64 图片
206
+ return {
207
+ content: [
208
+ {
209
+ type: 'image',
210
+ data: base64,
211
+ mimeType: 'image/png',
212
+ },
213
+ ],
214
+ };
215
+ }
216
+ case 'state': {
217
+ const state = await session.getPageState();
218
+ if (args.output) {
219
+ await writeFile(args.output, JSON.stringify(state, null, 2), 'utf-8');
220
+ return {
221
+ content: [
222
+ {
223
+ type: 'text',
224
+ text: JSON.stringify({
225
+ success: true,
226
+ type: 'state',
227
+ output: args.output,
228
+ }),
229
+ },
230
+ ],
231
+ };
232
+ }
233
+ return {
234
+ content: [
235
+ {
236
+ type: 'text',
237
+ text: JSON.stringify({
238
+ success: true,
239
+ type: 'state',
240
+ state,
241
+ }, null, 2),
242
+ },
243
+ ],
244
+ };
245
+ }
246
+ default:
247
+ return {
248
+ content: [
249
+ {
250
+ type: 'text',
251
+ text: JSON.stringify({
252
+ error: {
253
+ code: 'INVALID_ARGUMENT',
254
+ message: `未知提取类型: ${args.type}`,
255
+ },
256
+ }),
257
+ },
258
+ ],
259
+ isError: true,
260
+ };
261
+ }
262
+ }
263
+ catch (error) {
264
+ return formatErrorResponse(error);
265
+ }
266
+ }
267
+ /**
268
+ * 提取文本内容
269
+ */
270
+ async function extractText(session, target) {
271
+ if (target) {
272
+ // 定位元素并提取文本
273
+ const locator = session.createLocator(target);
274
+ const text = await locator.evaluateOn(`function() {
275
+ return this.textContent ?? '';
276
+ }`);
277
+ return text ?? '';
278
+ }
279
+ // 提取整个页面文本
280
+ return session.evaluate('document.body.innerText');
281
+ }
282
+ /**
283
+ * 提取 HTML
284
+ */
285
+ async function extractHTML(session, target) {
286
+ if (target) {
287
+ const locator = session.createLocator(target);
288
+ const html = await locator.evaluateOn(`function() {
289
+ return this.outerHTML;
290
+ }`);
291
+ return html;
292
+ }
293
+ return session.evaluate('document.documentElement.outerHTML');
294
+ }
295
+ /**
296
+ * 提取属性
297
+ */
298
+ async function extractAttribute(session, target, attribute) {
299
+ const locator = session.createLocator(target);
300
+ return locator.evaluateOn(`function() {
301
+ return this.getAttribute('${attribute}');
302
+ }`);
303
+ }
304
+ //# sourceMappingURL=extract.js.map