botbrowser-mcp 0.1.5 → 0.1.7

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.
@@ -1,178 +0,0 @@
1
- /**
2
- * 浏览器操作工具
3
- * 基于 Playwright API 实现常用浏览器操作
4
- */
5
- import { PlaywrightManager } from '../playwright/manager.js';
6
- export declare function setManager(m: PlaywrightManager): void;
7
- export declare const browserTools: {
8
- browser_navigate: {
9
- description: string;
10
- inputSchema: {
11
- type: string;
12
- properties: {
13
- url: {
14
- type: string;
15
- description: string;
16
- };
17
- };
18
- required: string[];
19
- };
20
- handler: (args: any) => Promise<{
21
- content: {
22
- type: string;
23
- text: string;
24
- }[];
25
- }>;
26
- };
27
- browser_click: {
28
- description: string;
29
- inputSchema: {
30
- type: string;
31
- properties: {
32
- selector: {
33
- type: string;
34
- description: string;
35
- };
36
- };
37
- required: string[];
38
- };
39
- handler: (args: any) => Promise<{
40
- content: {
41
- type: string;
42
- text: string;
43
- }[];
44
- }>;
45
- };
46
- browser_fill: {
47
- description: string;
48
- inputSchema: {
49
- type: string;
50
- properties: {
51
- selector: {
52
- type: string;
53
- description: string;
54
- };
55
- value: {
56
- type: string;
57
- description: string;
58
- };
59
- };
60
- required: string[];
61
- };
62
- handler: (args: any) => Promise<{
63
- content: {
64
- type: string;
65
- text: string;
66
- }[];
67
- }>;
68
- };
69
- browser_screenshot: {
70
- description: string;
71
- inputSchema: {
72
- type: string;
73
- properties: {
74
- path: {
75
- type: string;
76
- description: string;
77
- };
78
- fullPage: {
79
- type: string;
80
- description: string;
81
- };
82
- };
83
- required: string[];
84
- };
85
- handler: (args: any) => Promise<{
86
- content: {
87
- type: string;
88
- text: string;
89
- }[];
90
- }>;
91
- };
92
- browser_get_text: {
93
- description: string;
94
- inputSchema: {
95
- type: string;
96
- properties: {
97
- selector: {
98
- type: string;
99
- description: string;
100
- };
101
- };
102
- required: string[];
103
- };
104
- handler: (args: any) => Promise<{
105
- content: {
106
- type: string;
107
- text: string;
108
- }[];
109
- }>;
110
- };
111
- browser_wait: {
112
- description: string;
113
- inputSchema: {
114
- type: string;
115
- properties: {
116
- selector: {
117
- type: string;
118
- description: string;
119
- };
120
- timeout: {
121
- type: string;
122
- description: string;
123
- };
124
- };
125
- };
126
- handler: (args: any) => Promise<{
127
- content: {
128
- type: string;
129
- text: string;
130
- }[];
131
- }>;
132
- };
133
- browser_evaluate: {
134
- description: string;
135
- inputSchema: {
136
- type: string;
137
- properties: {
138
- script: {
139
- type: string;
140
- description: string;
141
- };
142
- };
143
- required: string[];
144
- };
145
- handler: (args: any) => Promise<{
146
- content: {
147
- type: string;
148
- text: string;
149
- }[];
150
- }>;
151
- };
152
- browser_new_page: {
153
- description: string;
154
- inputSchema: {
155
- type: string;
156
- properties: {};
157
- };
158
- handler: () => Promise<{
159
- content: {
160
- type: string;
161
- text: string;
162
- }[];
163
- }>;
164
- };
165
- browser_get_url: {
166
- description: string;
167
- inputSchema: {
168
- type: string;
169
- properties: {};
170
- };
171
- handler: () => Promise<{
172
- content: {
173
- type: string;
174
- text: string;
175
- }[];
176
- }>;
177
- };
178
- };
@@ -1,211 +0,0 @@
1
- let manager;
2
- export function setManager(m) {
3
- manager = m;
4
- }
5
- async function getActivePage() {
6
- const context = manager.getActiveContext();
7
- if (!context) {
8
- throw new Error('没有活跃的浏览器实例,请先使用 launch_browser 启动');
9
- }
10
- const pages = context.pages();
11
- if (pages.length === 0) {
12
- return await context.newPage();
13
- }
14
- return pages[pages.length - 1];
15
- }
16
- export const browserTools = {
17
- browser_navigate: {
18
- description: '导航到指定URL',
19
- inputSchema: {
20
- type: 'object',
21
- properties: {
22
- url: { type: 'string', description: 'URL地址' },
23
- },
24
- required: ['url'],
25
- },
26
- handler: async (args) => {
27
- const page = await getActivePage();
28
- await page.goto(args.url);
29
- return {
30
- content: [{
31
- type: 'text',
32
- text: `已导航到 ${args.url}`,
33
- }],
34
- };
35
- },
36
- },
37
- browser_click: {
38
- description: '点击页面元素',
39
- inputSchema: {
40
- type: 'object',
41
- properties: {
42
- selector: { type: 'string', description: 'CSS选择器或文本选择器' },
43
- },
44
- required: ['selector'],
45
- },
46
- handler: async (args) => {
47
- const page = await getActivePage();
48
- await page.click(args.selector);
49
- return {
50
- content: [{
51
- type: 'text',
52
- text: `已点击元素: ${args.selector}`,
53
- }],
54
- };
55
- },
56
- },
57
- browser_fill: {
58
- description: '填充输入框',
59
- inputSchema: {
60
- type: 'object',
61
- properties: {
62
- selector: { type: 'string', description: 'CSS选择器' },
63
- value: { type: 'string', description: '填充的值' },
64
- },
65
- required: ['selector', 'value'],
66
- },
67
- handler: async (args) => {
68
- const page = await getActivePage();
69
- await page.fill(args.selector, args.value);
70
- return {
71
- content: [{
72
- type: 'text',
73
- text: `已填充 ${args.selector}`,
74
- }],
75
- };
76
- },
77
- },
78
- browser_screenshot: {
79
- description: '截取页面截图',
80
- inputSchema: {
81
- type: 'object',
82
- properties: {
83
- path: { type: 'string', description: '保存路径' },
84
- fullPage: { type: 'boolean', description: '是否截取整个页面' },
85
- },
86
- required: ['path'],
87
- },
88
- handler: async (args) => {
89
- const page = await getActivePage();
90
- await page.screenshot({
91
- path: args.path,
92
- fullPage: args.fullPage || false
93
- });
94
- return {
95
- content: [{
96
- type: 'text',
97
- text: `截图已保存到 ${args.path}`,
98
- }],
99
- };
100
- },
101
- },
102
- browser_get_text: {
103
- description: '获取元素文本内容',
104
- inputSchema: {
105
- type: 'object',
106
- properties: {
107
- selector: { type: 'string', description: 'CSS选择器' },
108
- },
109
- required: ['selector'],
110
- },
111
- handler: async (args) => {
112
- const page = await getActivePage();
113
- const text = await page.textContent(args.selector);
114
- return {
115
- content: [{
116
- type: 'text',
117
- text: text || '',
118
- }],
119
- };
120
- },
121
- },
122
- browser_wait: {
123
- description: '等待指定时间或元素出现',
124
- inputSchema: {
125
- type: 'object',
126
- properties: {
127
- selector: { type: 'string', description: 'CSS选择器(等待元素出现)' },
128
- timeout: { type: 'number', description: '超时时间(毫秒)' },
129
- },
130
- },
131
- handler: async (args) => {
132
- const page = await getActivePage();
133
- if (args.selector) {
134
- await page.waitForSelector(args.selector, { timeout: args.timeout || 30000 });
135
- return {
136
- content: [{
137
- type: 'text',
138
- text: `元素 ${args.selector} 已出现`,
139
- }],
140
- };
141
- }
142
- else if (args.timeout) {
143
- await page.waitForTimeout(args.timeout);
144
- return {
145
- content: [{
146
- type: 'text',
147
- text: `已等待 ${args.timeout}ms`,
148
- }],
149
- };
150
- }
151
- throw new Error('必须提供 selector 或 timeout');
152
- },
153
- },
154
- browser_evaluate: {
155
- description: '在页面中执行JavaScript代码',
156
- inputSchema: {
157
- type: 'object',
158
- properties: {
159
- script: { type: 'string', description: 'JavaScript代码' },
160
- },
161
- required: ['script'],
162
- },
163
- handler: async (args) => {
164
- const page = await getActivePage();
165
- const result = await page.evaluate(args.script);
166
- return {
167
- content: [{
168
- type: 'text',
169
- text: JSON.stringify(result, null, 2),
170
- }],
171
- };
172
- },
173
- },
174
- browser_new_page: {
175
- description: '打开新标签页',
176
- inputSchema: {
177
- type: 'object',
178
- properties: {},
179
- },
180
- handler: async () => {
181
- const context = manager.getActiveContext();
182
- if (!context) {
183
- throw new Error('没有活跃的浏览器实例');
184
- }
185
- await context.newPage();
186
- return {
187
- content: [{
188
- type: 'text',
189
- text: '已打开新标签页',
190
- }],
191
- };
192
- },
193
- },
194
- browser_get_url: {
195
- description: '获取当前页面URL',
196
- inputSchema: {
197
- type: 'object',
198
- properties: {},
199
- },
200
- handler: async () => {
201
- const page = await getActivePage();
202
- return {
203
- content: [{
204
- type: 'text',
205
- text: page.url(),
206
- }],
207
- };
208
- },
209
- },
210
- };
211
- //# sourceMappingURL=browser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/tools/browser.ts"],"names":[],"mappings":"AAOA,IAAI,OAA0B,CAAC;AAE/B,MAAM,UAAU,UAAU,CAAC,CAAoB;IAC7C,OAAO,GAAG,CAAC,CAAC;AACd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