@ejazullah/browser-mcp 0.0.56
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 +202 -0
- package/README.md +860 -0
- package/cli.js +19 -0
- package/index.d.ts +23 -0
- package/index.js +1061 -0
- package/lib/auth.js +82 -0
- package/lib/browserContextFactory.js +205 -0
- package/lib/browserServerBackend.js +125 -0
- package/lib/config.js +266 -0
- package/lib/context.js +232 -0
- package/lib/databaseLogger.js +264 -0
- package/lib/extension/cdpRelay.js +346 -0
- package/lib/extension/extensionContextFactory.js +56 -0
- package/lib/extension/main.js +26 -0
- package/lib/fileUtils.js +32 -0
- package/lib/httpServer.js +39 -0
- package/lib/index.js +39 -0
- package/lib/javascript.js +49 -0
- package/lib/log.js +21 -0
- package/lib/loop/loop.js +69 -0
- package/lib/loop/loopClaude.js +152 -0
- package/lib/loop/loopOpenAI.js +143 -0
- package/lib/loop/main.js +60 -0
- package/lib/loopTools/context.js +66 -0
- package/lib/loopTools/main.js +49 -0
- package/lib/loopTools/perform.js +32 -0
- package/lib/loopTools/snapshot.js +29 -0
- package/lib/loopTools/tool.js +18 -0
- package/lib/manualPromise.js +111 -0
- package/lib/mcp/inProcessTransport.js +72 -0
- package/lib/mcp/server.js +93 -0
- package/lib/mcp/transport.js +217 -0
- package/lib/mongoDBLogger.js +252 -0
- package/lib/package.js +20 -0
- package/lib/program.js +113 -0
- package/lib/response.js +172 -0
- package/lib/sessionLog.js +156 -0
- package/lib/tab.js +266 -0
- package/lib/tools/cdp.js +169 -0
- package/lib/tools/common.js +55 -0
- package/lib/tools/console.js +33 -0
- package/lib/tools/dialogs.js +47 -0
- package/lib/tools/evaluate.js +53 -0
- package/lib/tools/extraction.js +217 -0
- package/lib/tools/files.js +44 -0
- package/lib/tools/forms.js +180 -0
- package/lib/tools/getext.js +99 -0
- package/lib/tools/install.js +53 -0
- package/lib/tools/interactions.js +191 -0
- package/lib/tools/keyboard.js +86 -0
- package/lib/tools/mouse.js +99 -0
- package/lib/tools/navigate.js +70 -0
- package/lib/tools/network.js +41 -0
- package/lib/tools/pdf.js +40 -0
- package/lib/tools/screenshot.js +75 -0
- package/lib/tools/selectors.js +233 -0
- package/lib/tools/snapshot.js +169 -0
- package/lib/tools/states.js +147 -0
- package/lib/tools/tabs.js +87 -0
- package/lib/tools/tool.js +33 -0
- package/lib/tools/utils.js +74 -0
- package/lib/tools/wait.js +56 -0
- package/lib/tools.js +64 -0
- package/lib/utils.js +26 -0
- package/openapi.json +683 -0
- package/package.json +92 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
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
|
+
// @ts-ignore
|
|
17
|
+
import { asLocator } from 'playwright-core/lib/utils';
|
|
18
|
+
export async function waitForCompletion(tab, callback) {
|
|
19
|
+
const requests = new Set();
|
|
20
|
+
let frameNavigated = false;
|
|
21
|
+
let waitCallback = () => { };
|
|
22
|
+
const waitBarrier = new Promise(f => { waitCallback = f; });
|
|
23
|
+
const requestListener = (request) => requests.add(request);
|
|
24
|
+
const requestFinishedListener = (request) => {
|
|
25
|
+
requests.delete(request);
|
|
26
|
+
if (!requests.size)
|
|
27
|
+
waitCallback();
|
|
28
|
+
};
|
|
29
|
+
const frameNavigateListener = (frame) => {
|
|
30
|
+
if (frame.parentFrame())
|
|
31
|
+
return;
|
|
32
|
+
frameNavigated = true;
|
|
33
|
+
dispose();
|
|
34
|
+
clearTimeout(timeout);
|
|
35
|
+
void tab.waitForLoadState('load').then(waitCallback);
|
|
36
|
+
};
|
|
37
|
+
const onTimeout = () => {
|
|
38
|
+
dispose();
|
|
39
|
+
waitCallback();
|
|
40
|
+
};
|
|
41
|
+
tab.page.on('request', requestListener);
|
|
42
|
+
tab.page.on('requestfinished', requestFinishedListener);
|
|
43
|
+
tab.page.on('framenavigated', frameNavigateListener);
|
|
44
|
+
const timeout = setTimeout(onTimeout, 10000);
|
|
45
|
+
const dispose = () => {
|
|
46
|
+
tab.page.off('request', requestListener);
|
|
47
|
+
tab.page.off('requestfinished', requestFinishedListener);
|
|
48
|
+
tab.page.off('framenavigated', frameNavigateListener);
|
|
49
|
+
clearTimeout(timeout);
|
|
50
|
+
};
|
|
51
|
+
try {
|
|
52
|
+
const result = await callback();
|
|
53
|
+
if (!requests.size && !frameNavigated)
|
|
54
|
+
waitCallback();
|
|
55
|
+
await waitBarrier;
|
|
56
|
+
await tab.waitForTimeout(1000);
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
dispose();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export async function generateLocator(locator) {
|
|
64
|
+
try {
|
|
65
|
+
const { resolvedSelector } = await locator._resolveSelector();
|
|
66
|
+
return asLocator('javascript', resolvedSelector);
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
throw new Error('Ref not found, likely because element was removed. Use browser_snapshot to see what elements are currently on the page.');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export async function callOnPageNoTrace(page, callback) {
|
|
73
|
+
return await page._wrapApiCall(() => callback(page), { internal: true });
|
|
74
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
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
|
+
const wait = defineTool({
|
|
19
|
+
capability: 'core',
|
|
20
|
+
schema: {
|
|
21
|
+
name: 'browser_wait_for',
|
|
22
|
+
title: 'Wait for',
|
|
23
|
+
description: 'Wait for text to appear or disappear or a specified time to pass',
|
|
24
|
+
inputSchema: z.object({
|
|
25
|
+
time: z.number().optional().describe('The time to wait in seconds'),
|
|
26
|
+
text: z.string().optional().describe('The text to wait for'),
|
|
27
|
+
textGone: z.string().optional().describe('The text to wait for to disappear'),
|
|
28
|
+
}),
|
|
29
|
+
type: 'readOnly',
|
|
30
|
+
},
|
|
31
|
+
handle: async (context, params, response) => {
|
|
32
|
+
if (!params.text && !params.textGone && !params.time)
|
|
33
|
+
throw new Error('Either time, text or textGone must be provided');
|
|
34
|
+
const code = [];
|
|
35
|
+
if (params.time) {
|
|
36
|
+
code.push(`await new Promise(f => setTimeout(f, ${params.time} * 1000));`);
|
|
37
|
+
await new Promise(f => setTimeout(f, Math.min(30000, params.time * 1000)));
|
|
38
|
+
}
|
|
39
|
+
const tab = context.currentTabOrDie();
|
|
40
|
+
const locator = params.text ? tab.page.getByText(params.text).first() : undefined;
|
|
41
|
+
const goneLocator = params.textGone ? tab.page.getByText(params.textGone).first() : undefined;
|
|
42
|
+
if (goneLocator) {
|
|
43
|
+
code.push(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`);
|
|
44
|
+
await goneLocator.waitFor({ state: 'hidden' });
|
|
45
|
+
}
|
|
46
|
+
if (locator) {
|
|
47
|
+
code.push(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
|
|
48
|
+
await locator.waitFor({ state: 'visible' });
|
|
49
|
+
}
|
|
50
|
+
response.addResult(`Waited for ${params.text || params.textGone || params.time}`);
|
|
51
|
+
response.setIncludeSnapshot();
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
export default [
|
|
55
|
+
wait,
|
|
56
|
+
];
|
package/lib/tools.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
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 common from './tools/common.js';
|
|
17
|
+
import console from './tools/console.js';
|
|
18
|
+
import dialogs from './tools/dialogs.js';
|
|
19
|
+
import evaluate from './tools/evaluate.js';
|
|
20
|
+
import extraction from './tools/extraction.js';
|
|
21
|
+
import files from './tools/files.js';
|
|
22
|
+
import forms from './tools/forms.js';
|
|
23
|
+
import getext from './tools/getext.js';
|
|
24
|
+
import install from './tools/install.js';
|
|
25
|
+
import interactions from './tools/interactions.js';
|
|
26
|
+
import keyboard from './tools/keyboard.js';
|
|
27
|
+
import navigate from './tools/navigate.js';
|
|
28
|
+
import network from './tools/network.js';
|
|
29
|
+
import pdf from './tools/pdf.js';
|
|
30
|
+
import selectors from './tools/selectors.js';
|
|
31
|
+
import snapshot from './tools/snapshot.js';
|
|
32
|
+
import states from './tools/states.js';
|
|
33
|
+
import tabs from './tools/tabs.js';
|
|
34
|
+
import screenshot from './tools/screenshot.js';
|
|
35
|
+
import wait from './tools/wait.js';
|
|
36
|
+
import mouse from './tools/mouse.js';
|
|
37
|
+
import { cdpTools } from './tools/cdp.js';
|
|
38
|
+
export const allTools = [
|
|
39
|
+
...cdpTools,
|
|
40
|
+
...common,
|
|
41
|
+
...console,
|
|
42
|
+
...dialogs,
|
|
43
|
+
...evaluate,
|
|
44
|
+
...extraction,
|
|
45
|
+
...files,
|
|
46
|
+
...forms,
|
|
47
|
+
...getext,
|
|
48
|
+
...install,
|
|
49
|
+
...interactions,
|
|
50
|
+
...keyboard,
|
|
51
|
+
...navigate,
|
|
52
|
+
...network,
|
|
53
|
+
...mouse,
|
|
54
|
+
...pdf,
|
|
55
|
+
...screenshot,
|
|
56
|
+
...selectors,
|
|
57
|
+
...snapshot,
|
|
58
|
+
...states,
|
|
59
|
+
...tabs,
|
|
60
|
+
...wait,
|
|
61
|
+
];
|
|
62
|
+
export function filteredTools(config) {
|
|
63
|
+
return allTools.filter(tool => tool.capability.startsWith('core') || config.capabilities?.includes(tool.capability));
|
|
64
|
+
}
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
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 crypto from 'crypto';
|
|
17
|
+
export function createHash(data) {
|
|
18
|
+
return crypto.createHash('sha256').update(data).digest('hex').slice(0, 7);
|
|
19
|
+
}
|
|
20
|
+
export function sanitizeForFilePath(s) {
|
|
21
|
+
const sanitize = (s) => s.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, '-');
|
|
22
|
+
const separator = s.lastIndexOf('.');
|
|
23
|
+
if (separator === -1)
|
|
24
|
+
return sanitize(s);
|
|
25
|
+
return sanitize(s.substring(0, separator)) + '.' + sanitize(s.substring(separator + 1));
|
|
26
|
+
}
|