@darbotlabs/darbot-browser-mcp 0.1.1 → 1.3.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 +1 -1
- package/README.md +249 -158
- package/cli.js +1 -1
- package/config.d.ts +77 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/ai/context.js +150 -0
- package/lib/ai/guardrails.js +382 -0
- package/lib/ai/integration.js +397 -0
- package/lib/ai/intent.js +237 -0
- package/lib/ai/manualPromise.js +111 -0
- package/lib/ai/memory.js +273 -0
- package/lib/ai/ml-scorer.js +265 -0
- package/lib/ai/orchestrator-tools.js +292 -0
- package/lib/ai/orchestrator.js +473 -0
- package/lib/ai/planner.js +300 -0
- package/lib/ai/reporter.js +493 -0
- package/lib/ai/workflow.js +407 -0
- package/lib/auth/apiKeyAuth.js +46 -0
- package/lib/auth/entraAuth.js +110 -0
- package/lib/auth/entraJwtVerifier.js +117 -0
- package/lib/auth/index.js +210 -0
- package/lib/auth/managedIdentityAuth.js +175 -0
- package/lib/auth/mcpOAuthProvider.js +186 -0
- package/lib/auth/tunnelAuth.js +120 -0
- package/lib/browserContextFactory.js +1 -1
- package/lib/browserServer.js +1 -1
- package/lib/cdpRelay.js +2 -2
- package/lib/common.js +68 -0
- package/lib/config.js +62 -3
- package/lib/connection.js +1 -1
- package/lib/context.js +1 -1
- package/lib/fileUtils.js +1 -1
- package/lib/guardrails.js +382 -0
- package/lib/health.js +178 -0
- package/lib/httpServer.js +1 -1
- package/lib/index.js +1 -1
- package/lib/javascript.js +1 -1
- package/lib/manualPromise.js +1 -1
- package/lib/memory.js +273 -0
- package/lib/openapi.js +373 -0
- package/lib/orchestrator.js +473 -0
- package/lib/package.js +1 -1
- package/lib/pageSnapshot.js +17 -2
- package/lib/planner.js +302 -0
- package/lib/program.js +17 -5
- package/lib/reporter.js +493 -0
- package/lib/resources/resource.js +1 -1
- package/lib/server.js +5 -3
- package/lib/tab.js +1 -1
- package/lib/tools/ai-native.js +298 -0
- package/lib/tools/autonomous.js +147 -0
- package/lib/tools/clock.js +183 -0
- package/lib/tools/common.js +1 -1
- package/lib/tools/console.js +1 -1
- package/lib/tools/diagnostics.js +132 -0
- package/lib/tools/dialogs.js +1 -1
- package/lib/tools/emulation.js +155 -0
- package/lib/tools/files.js +1 -1
- package/lib/tools/install.js +1 -1
- package/lib/tools/keyboard.js +1 -1
- package/lib/tools/navigate.js +1 -1
- package/lib/tools/network.js +1 -1
- package/lib/tools/pageSnapshot.js +58 -0
- package/lib/tools/pdf.js +1 -1
- package/lib/tools/profiles.js +76 -25
- package/lib/tools/screenshot.js +1 -1
- package/lib/tools/scroll.js +93 -0
- package/lib/tools/snapshot.js +1 -1
- package/lib/tools/storage.js +328 -0
- package/lib/tools/tab.js +16 -0
- package/lib/tools/tabs.js +1 -1
- package/lib/tools/testing.js +1 -1
- package/lib/tools/tool.js +1 -1
- package/lib/tools/utils.js +1 -1
- package/lib/tools/vision.js +1 -1
- package/lib/tools/wait.js +1 -1
- package/lib/tools.js +22 -1
- package/lib/transport.js +251 -31
- package/package.json +54 -21
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) DarbotLabs.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { defineTool } from './tool.js';
|
|
18
|
+
/**
|
|
19
|
+
* Mouse wheel scrolling tool - uses Playwright 1.15+ mouse.wheel() API
|
|
20
|
+
* Allows precise scrolling by delta values, useful for:
|
|
21
|
+
* - Testing infinite scroll pages
|
|
22
|
+
* - Revealing lazy-loaded content
|
|
23
|
+
* - Navigating long pages
|
|
24
|
+
*/
|
|
25
|
+
const mouseWheel = captureSnapshot => defineTool({
|
|
26
|
+
capability: 'core',
|
|
27
|
+
schema: {
|
|
28
|
+
name: 'browser_scroll',
|
|
29
|
+
title: 'Autonomous page scrolling',
|
|
30
|
+
description: 'Autonomously scroll the page using mouse wheel. Positive deltaY scrolls down, negative scrolls up. Positive deltaX scrolls right, negative scrolls left.',
|
|
31
|
+
inputSchema: z.object({
|
|
32
|
+
deltaX: z.number().optional().default(0).describe('Horizontal scroll amount in pixels. Positive scrolls right, negative scrolls left.'),
|
|
33
|
+
deltaY: z.number().optional().default(0).describe('Vertical scroll amount in pixels. Positive scrolls down, negative scrolls up.'),
|
|
34
|
+
}),
|
|
35
|
+
type: 'readOnly',
|
|
36
|
+
},
|
|
37
|
+
handle: async (context, params) => {
|
|
38
|
+
const tab = context.currentTabOrDie();
|
|
39
|
+
const deltaX = params.deltaX ?? 0;
|
|
40
|
+
const deltaY = params.deltaY ?? 0;
|
|
41
|
+
const code = [
|
|
42
|
+
`// Scroll page by (${deltaX}, ${deltaY}) pixels`,
|
|
43
|
+
`await page.mouse.wheel(${deltaX}, ${deltaY});`,
|
|
44
|
+
];
|
|
45
|
+
const action = async () => {
|
|
46
|
+
await tab.page.mouse.wheel(deltaX, deltaY);
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
code,
|
|
50
|
+
action,
|
|
51
|
+
captureSnapshot,
|
|
52
|
+
waitForNetwork: true,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* Scroll to element tool - scrolls an element into view
|
|
58
|
+
*/
|
|
59
|
+
const scrollToElement = captureSnapshot => defineTool({
|
|
60
|
+
capability: 'core',
|
|
61
|
+
schema: {
|
|
62
|
+
name: 'browser_scroll_to_element',
|
|
63
|
+
title: 'Autonomous scroll to element',
|
|
64
|
+
description: 'Autonomously scroll an element into view. Useful for revealing elements before interacting with them.',
|
|
65
|
+
inputSchema: z.object({
|
|
66
|
+
element: z.string().describe('Human-readable element description for permission'),
|
|
67
|
+
ref: z.string().describe('Exact target element reference from the page snapshot'),
|
|
68
|
+
}),
|
|
69
|
+
type: 'readOnly',
|
|
70
|
+
},
|
|
71
|
+
handle: async (context, params) => {
|
|
72
|
+
const tab = context.currentTabOrDie();
|
|
73
|
+
const snapshot = tab.snapshotOrDie();
|
|
74
|
+
const locator = snapshot.refLocator(params);
|
|
75
|
+
const code = [
|
|
76
|
+
`// Scroll ${params.element} into view`,
|
|
77
|
+
`await page.locator('[ref="${params.ref}"]').scrollIntoViewIfNeeded();`,
|
|
78
|
+
];
|
|
79
|
+
const action = async () => {
|
|
80
|
+
await locator.scrollIntoViewIfNeeded();
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
code,
|
|
84
|
+
action,
|
|
85
|
+
captureSnapshot,
|
|
86
|
+
waitForNetwork: true,
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
export default (captureSnapshot) => [
|
|
91
|
+
mouseWheel(captureSnapshot),
|
|
92
|
+
scrollToElement(captureSnapshot),
|
|
93
|
+
];
|
package/lib/tools/snapshot.js
CHANGED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) DarbotLabs.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { defineTool } from './tool.js';
|
|
18
|
+
import { outputFile } from '../config.js';
|
|
19
|
+
/**
|
|
20
|
+
* Storage state tools - IndexedDB support from Playwright 1.51+
|
|
21
|
+
* Allows saving and restoring browser state including:
|
|
22
|
+
* - Cookies
|
|
23
|
+
* - Local storage
|
|
24
|
+
* - IndexedDB (for apps like Firebase Auth)
|
|
25
|
+
*/
|
|
26
|
+
const saveStorageState = defineTool({
|
|
27
|
+
capability: 'core',
|
|
28
|
+
schema: {
|
|
29
|
+
name: 'browser_save_storage_state',
|
|
30
|
+
title: 'Autonomous storage state saving',
|
|
31
|
+
description: 'Autonomously save browser storage state (cookies, localStorage, and optionally IndexedDB) to a file. Useful for persisting authentication and session state.',
|
|
32
|
+
inputSchema: z.object({
|
|
33
|
+
filename: z.string().optional().describe('File name to save storage state to. Defaults to storage-state-{timestamp}.json'),
|
|
34
|
+
includeIndexedDB: z.boolean().optional().default(false).describe('Whether to include IndexedDB contents (useful for Firebase Auth and similar apps)'),
|
|
35
|
+
}),
|
|
36
|
+
type: 'readOnly',
|
|
37
|
+
},
|
|
38
|
+
handle: async (context, params) => {
|
|
39
|
+
const tab = context.currentTabOrDie();
|
|
40
|
+
const browserContext = tab.page.context();
|
|
41
|
+
const fileName = await outputFile(context.config, params.filename ?? `storage-state-${new Date().toISOString().replace(/[:.]/g, '-')}.json`);
|
|
42
|
+
const code = [
|
|
43
|
+
`// Save storage state${params.includeIndexedDB ? ' (including IndexedDB)' : ''} to ${fileName}`,
|
|
44
|
+
`await context.storageState({ path: '${fileName}'${params.includeIndexedDB ? ', indexedDB: true' : ''} });`,
|
|
45
|
+
];
|
|
46
|
+
const action = async () => {
|
|
47
|
+
const options = { path: fileName };
|
|
48
|
+
if (params.includeIndexedDB) {
|
|
49
|
+
options.indexedDB = true;
|
|
50
|
+
}
|
|
51
|
+
await browserContext.storageState(options);
|
|
52
|
+
return {
|
|
53
|
+
content: [{ type: 'text', text: `Storage state saved to: ${fileName}` }]
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
code,
|
|
58
|
+
action,
|
|
59
|
+
captureSnapshot: false,
|
|
60
|
+
waitForNetwork: false,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* Get cookies with filtering
|
|
66
|
+
*/
|
|
67
|
+
const getCookies = defineTool({
|
|
68
|
+
capability: 'core',
|
|
69
|
+
schema: {
|
|
70
|
+
name: 'browser_get_cookies',
|
|
71
|
+
title: 'Autonomous cookie retrieval',
|
|
72
|
+
description: 'Autonomously retrieve browser cookies, optionally filtered by URL or domain.',
|
|
73
|
+
inputSchema: z.object({
|
|
74
|
+
urls: z.array(z.string()).optional().describe('URLs to get cookies for. If not specified, returns all cookies.'),
|
|
75
|
+
}),
|
|
76
|
+
type: 'readOnly',
|
|
77
|
+
},
|
|
78
|
+
handle: async (context, params) => {
|
|
79
|
+
const tab = context.currentTabOrDie();
|
|
80
|
+
const browserContext = tab.page.context();
|
|
81
|
+
const code = params.urls
|
|
82
|
+
? [
|
|
83
|
+
`// Get cookies for specified URLs`,
|
|
84
|
+
`const cookies = await context.cookies(${JSON.stringify(params.urls)});`,
|
|
85
|
+
]
|
|
86
|
+
: [
|
|
87
|
+
`// Get all cookies`,
|
|
88
|
+
`const cookies = await context.cookies();`,
|
|
89
|
+
];
|
|
90
|
+
const action = async () => {
|
|
91
|
+
const cookies = params.urls
|
|
92
|
+
? await browserContext.cookies(params.urls)
|
|
93
|
+
: await browserContext.cookies();
|
|
94
|
+
if (cookies.length === 0) {
|
|
95
|
+
return {
|
|
96
|
+
content: [{ type: 'text', text: 'No cookies found.' }]
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const output = cookies.map(cookie => {
|
|
100
|
+
return [
|
|
101
|
+
`🍪 ${cookie.name}`,
|
|
102
|
+
` Value: ${cookie.value.substring(0, 50)}${cookie.value.length > 50 ? '...' : ''}`,
|
|
103
|
+
` Domain: ${cookie.domain}`,
|
|
104
|
+
` Path: ${cookie.path}`,
|
|
105
|
+
` Expires: ${cookie.expires === -1 ? 'Session' : new Date(cookie.expires * 1000).toISOString()}`,
|
|
106
|
+
` Secure: ${cookie.secure}, HttpOnly: ${cookie.httpOnly}`,
|
|
107
|
+
].join('\n');
|
|
108
|
+
}).join('\n\n');
|
|
109
|
+
return {
|
|
110
|
+
content: [{ type: 'text', text: `Found ${cookies.length} cookies:\n\n${output}` }]
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
code,
|
|
115
|
+
action,
|
|
116
|
+
captureSnapshot: false,
|
|
117
|
+
waitForNetwork: false,
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
/**
|
|
122
|
+
* Set cookies
|
|
123
|
+
*/
|
|
124
|
+
const setCookie = defineTool({
|
|
125
|
+
capability: 'core',
|
|
126
|
+
schema: {
|
|
127
|
+
name: 'browser_set_cookie',
|
|
128
|
+
title: 'Autonomous cookie setting',
|
|
129
|
+
description: 'Autonomously set a browser cookie.',
|
|
130
|
+
inputSchema: z.object({
|
|
131
|
+
name: z.string().describe('Cookie name'),
|
|
132
|
+
value: z.string().describe('Cookie value'),
|
|
133
|
+
url: z.string().optional().describe('URL to associate the cookie with (either url or domain+path required)'),
|
|
134
|
+
domain: z.string().optional().describe('Cookie domain'),
|
|
135
|
+
path: z.string().optional().default('/').describe('Cookie path'),
|
|
136
|
+
expires: z.number().optional().describe('Unix timestamp when the cookie expires'),
|
|
137
|
+
httpOnly: z.boolean().optional().default(false).describe('Whether the cookie is HTTP-only'),
|
|
138
|
+
secure: z.boolean().optional().default(false).describe('Whether the cookie requires HTTPS'),
|
|
139
|
+
sameSite: z.enum(['Strict', 'Lax', 'None']).optional().describe('SameSite attribute'),
|
|
140
|
+
}),
|
|
141
|
+
type: 'destructive',
|
|
142
|
+
},
|
|
143
|
+
handle: async (context, params) => {
|
|
144
|
+
const tab = context.currentTabOrDie();
|
|
145
|
+
const browserContext = tab.page.context();
|
|
146
|
+
const cookie = {
|
|
147
|
+
name: params.name,
|
|
148
|
+
value: params.value,
|
|
149
|
+
};
|
|
150
|
+
if (params.url)
|
|
151
|
+
cookie.url = params.url;
|
|
152
|
+
if (params.domain)
|
|
153
|
+
cookie.domain = params.domain;
|
|
154
|
+
if (params.path)
|
|
155
|
+
cookie.path = params.path;
|
|
156
|
+
if (params.expires)
|
|
157
|
+
cookie.expires = params.expires;
|
|
158
|
+
if (params.httpOnly)
|
|
159
|
+
cookie.httpOnly = params.httpOnly;
|
|
160
|
+
if (params.secure)
|
|
161
|
+
cookie.secure = params.secure;
|
|
162
|
+
if (params.sameSite)
|
|
163
|
+
cookie.sameSite = params.sameSite;
|
|
164
|
+
const code = [
|
|
165
|
+
`// Set cookie: ${params.name}`,
|
|
166
|
+
`await context.addCookies([${JSON.stringify(cookie)}]);`,
|
|
167
|
+
];
|
|
168
|
+
const action = async () => {
|
|
169
|
+
await browserContext.addCookies([cookie]);
|
|
170
|
+
return {
|
|
171
|
+
content: [{ type: 'text', text: `Cookie '${params.name}' has been set.` }]
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
return {
|
|
175
|
+
code,
|
|
176
|
+
action,
|
|
177
|
+
captureSnapshot: false,
|
|
178
|
+
waitForNetwork: false,
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
/**
|
|
183
|
+
* Clear cookies with optional filtering
|
|
184
|
+
*/
|
|
185
|
+
const clearCookies = defineTool({
|
|
186
|
+
capability: 'core',
|
|
187
|
+
schema: {
|
|
188
|
+
name: 'browser_clear_cookies',
|
|
189
|
+
title: 'Autonomous cookie clearing',
|
|
190
|
+
description: 'Autonomously clear browser cookies, optionally filtered by name, domain, or path.',
|
|
191
|
+
inputSchema: z.object({
|
|
192
|
+
name: z.string().optional().describe('Only clear cookies with this name'),
|
|
193
|
+
domain: z.string().optional().describe('Only clear cookies for this domain'),
|
|
194
|
+
path: z.string().optional().describe('Only clear cookies with this path'),
|
|
195
|
+
}),
|
|
196
|
+
type: 'destructive',
|
|
197
|
+
},
|
|
198
|
+
handle: async (context, params) => {
|
|
199
|
+
const tab = context.currentTabOrDie();
|
|
200
|
+
const browserContext = tab.page.context();
|
|
201
|
+
const hasFilter = params.name || params.domain || params.path;
|
|
202
|
+
const filterDesc = hasFilter
|
|
203
|
+
? `(${[
|
|
204
|
+
params.name ? `name: ${params.name}` : '',
|
|
205
|
+
params.domain ? `domain: ${params.domain}` : '',
|
|
206
|
+
params.path ? `path: ${params.path}` : '',
|
|
207
|
+
].filter(Boolean).join(', ')})`
|
|
208
|
+
: '(all)';
|
|
209
|
+
const code = [
|
|
210
|
+
`// Clear cookies ${filterDesc}`,
|
|
211
|
+
`await context.clearCookies(${hasFilter ? JSON.stringify(params) : ''});`,
|
|
212
|
+
];
|
|
213
|
+
const action = async () => {
|
|
214
|
+
if (hasFilter) {
|
|
215
|
+
await browserContext.clearCookies(params);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
await browserContext.clearCookies();
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
content: [{ type: 'text', text: `Cookies cleared ${filterDesc}` }]
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
return {
|
|
225
|
+
code,
|
|
226
|
+
action,
|
|
227
|
+
captureSnapshot: false,
|
|
228
|
+
waitForNetwork: false,
|
|
229
|
+
};
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
/**
|
|
233
|
+
* Local storage operations
|
|
234
|
+
*/
|
|
235
|
+
const getLocalStorage = defineTool({
|
|
236
|
+
capability: 'core',
|
|
237
|
+
schema: {
|
|
238
|
+
name: 'browser_get_local_storage',
|
|
239
|
+
title: 'Autonomous localStorage retrieval',
|
|
240
|
+
description: 'Autonomously retrieve all localStorage items for the current page.',
|
|
241
|
+
inputSchema: z.object({}),
|
|
242
|
+
type: 'readOnly',
|
|
243
|
+
},
|
|
244
|
+
handle: async (context) => {
|
|
245
|
+
const tab = context.currentTabOrDie();
|
|
246
|
+
const code = [
|
|
247
|
+
`// Get all localStorage items`,
|
|
248
|
+
`const storage = await page.evaluate(() => JSON.stringify(localStorage));`,
|
|
249
|
+
];
|
|
250
|
+
const action = async () => {
|
|
251
|
+
const storage = await tab.page.evaluate(() => {
|
|
252
|
+
const items = {};
|
|
253
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
254
|
+
const key = localStorage.key(i);
|
|
255
|
+
if (key) {
|
|
256
|
+
items[key] = localStorage.getItem(key) || '';
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return items;
|
|
260
|
+
});
|
|
261
|
+
const keys = Object.keys(storage);
|
|
262
|
+
if (keys.length === 0) {
|
|
263
|
+
return {
|
|
264
|
+
content: [{ type: 'text', text: 'localStorage is empty.' }]
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
const output = keys.map(key => {
|
|
268
|
+
const value = storage[key];
|
|
269
|
+
const displayValue = value.length > 100 ? value.substring(0, 100) + '...' : value;
|
|
270
|
+
return `📦 ${key}\n ${displayValue}`;
|
|
271
|
+
}).join('\n\n');
|
|
272
|
+
return {
|
|
273
|
+
content: [{ type: 'text', text: `Found ${keys.length} localStorage items:\n\n${output}` }]
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
return {
|
|
277
|
+
code,
|
|
278
|
+
action,
|
|
279
|
+
captureSnapshot: false,
|
|
280
|
+
waitForNetwork: false,
|
|
281
|
+
};
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
/**
|
|
285
|
+
* Set localStorage item
|
|
286
|
+
*/
|
|
287
|
+
const setLocalStorage = defineTool({
|
|
288
|
+
capability: 'core',
|
|
289
|
+
schema: {
|
|
290
|
+
name: 'browser_set_local_storage',
|
|
291
|
+
title: 'Autonomous localStorage setting',
|
|
292
|
+
description: 'Autonomously set a localStorage item for the current page.',
|
|
293
|
+
inputSchema: z.object({
|
|
294
|
+
key: z.string().describe('Storage key'),
|
|
295
|
+
value: z.string().describe('Storage value'),
|
|
296
|
+
}),
|
|
297
|
+
type: 'destructive',
|
|
298
|
+
},
|
|
299
|
+
handle: async (context, params) => {
|
|
300
|
+
const tab = context.currentTabOrDie();
|
|
301
|
+
const code = [
|
|
302
|
+
`// Set localStorage item: ${params.key}`,
|
|
303
|
+
`await page.evaluate(([key, value]) => localStorage.setItem(key, value), [${JSON.stringify(params.key)}, ${JSON.stringify(params.value)}]);`,
|
|
304
|
+
];
|
|
305
|
+
const action = async () => {
|
|
306
|
+
await tab.page.evaluate(([key, value]) => {
|
|
307
|
+
localStorage.setItem(key, value);
|
|
308
|
+
}, [params.key, params.value]);
|
|
309
|
+
return {
|
|
310
|
+
content: [{ type: 'text', text: `localStorage['${params.key}'] has been set.` }]
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
return {
|
|
314
|
+
code,
|
|
315
|
+
action,
|
|
316
|
+
captureSnapshot: false,
|
|
317
|
+
waitForNetwork: false,
|
|
318
|
+
};
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
export default [
|
|
322
|
+
saveStorageState,
|
|
323
|
+
getCookies,
|
|
324
|
+
setCookie,
|
|
325
|
+
clearCookies,
|
|
326
|
+
getLocalStorage,
|
|
327
|
+
setLocalStorage,
|
|
328
|
+
];
|
package/lib/tools/tab.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) DarbotLabs.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export { Tab } from '../tab.js';
|
package/lib/tools/tabs.js
CHANGED
package/lib/tools/testing.js
CHANGED
package/lib/tools/tool.js
CHANGED
package/lib/tools/utils.js
CHANGED
package/lib/tools/vision.js
CHANGED
package/lib/tools/wait.js
CHANGED
package/lib/tools.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) DarbotLabs.
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -29,6 +29,13 @@ import screenshot from './tools/screenshot.js';
|
|
|
29
29
|
import testing from './tools/testing.js';
|
|
30
30
|
import vision from './tools/vision.js';
|
|
31
31
|
import wait from './tools/wait.js';
|
|
32
|
+
import aiNative from './tools/ai-native.js';
|
|
33
|
+
import autonomous from './tools/autonomous.js';
|
|
34
|
+
import scroll from './tools/scroll.js';
|
|
35
|
+
import clock from './tools/clock.js';
|
|
36
|
+
import emulation from './tools/emulation.js';
|
|
37
|
+
import diagnostics from './tools/diagnostics.js';
|
|
38
|
+
import storage from './tools/storage.js';
|
|
32
39
|
export const snapshotTools = [
|
|
33
40
|
...common(true),
|
|
34
41
|
...console,
|
|
@@ -48,6 +55,13 @@ export const snapshotTools = [
|
|
|
48
55
|
...tabs(true),
|
|
49
56
|
...testing,
|
|
50
57
|
...wait(true),
|
|
58
|
+
...aiNative,
|
|
59
|
+
...autonomous,
|
|
60
|
+
...scroll(true),
|
|
61
|
+
...clock(true),
|
|
62
|
+
...emulation(true),
|
|
63
|
+
...diagnostics,
|
|
64
|
+
...storage,
|
|
51
65
|
];
|
|
52
66
|
export const visionTools = [
|
|
53
67
|
...common(false),
|
|
@@ -67,4 +81,11 @@ export const visionTools = [
|
|
|
67
81
|
...testing,
|
|
68
82
|
...vision,
|
|
69
83
|
...wait(false),
|
|
84
|
+
...aiNative,
|
|
85
|
+
...autonomous,
|
|
86
|
+
...scroll(false),
|
|
87
|
+
...clock(false),
|
|
88
|
+
...emulation(false),
|
|
89
|
+
...diagnostics,
|
|
90
|
+
...storage,
|
|
70
91
|
];
|