@wordbricks/playwright-mcp 0.1.20 → 0.1.23
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/cli-wrapper.js +15 -14
- package/cli.js +1 -1
- package/config.d.ts +11 -6
- package/index.d.ts +7 -5
- package/index.js +1 -1
- package/package.json +34 -57
- package/LICENSE +0 -202
- package/lib/browserContextFactory.js +0 -326
- package/lib/browserServerBackend.js +0 -84
- package/lib/config.js +0 -286
- package/lib/context.js +0 -309
- package/lib/extension/cdpRelay.js +0 -346
- package/lib/extension/extensionContextFactory.js +0 -56
- package/lib/frameworkPatterns.js +0 -35
- package/lib/hooks/antiBotDetectionHook.js +0 -171
- package/lib/hooks/core.js +0 -144
- package/lib/hooks/eventConsumer.js +0 -52
- package/lib/hooks/events.js +0 -42
- package/lib/hooks/formatToolCallEvent.js +0 -16
- package/lib/hooks/frameworkStateHook.js +0 -182
- package/lib/hooks/grouping.js +0 -72
- package/lib/hooks/jsonLdDetectionHook.js +0 -175
- package/lib/hooks/networkFilters.js +0 -82
- package/lib/hooks/networkSetup.js +0 -59
- package/lib/hooks/networkTrackingHook.js +0 -67
- package/lib/hooks/pageHeightHook.js +0 -75
- package/lib/hooks/registry.js +0 -42
- package/lib/hooks/requireTabHook.js +0 -26
- package/lib/hooks/schema.js +0 -89
- package/lib/hooks/waitHook.js +0 -33
- package/lib/index.js +0 -39
- package/lib/mcp/inProcessTransport.js +0 -72
- package/lib/mcp/proxyBackend.js +0 -115
- package/lib/mcp/server.js +0 -86
- package/lib/mcp/tool.js +0 -38
- package/lib/mcp/transport.js +0 -181
- package/lib/playwrightTransformer.js +0 -497
- package/lib/program.js +0 -110
- package/lib/response.js +0 -186
- package/lib/sessionLog.js +0 -121
- package/lib/tab.js +0 -249
- package/lib/tools/common.js +0 -55
- package/lib/tools/console.js +0 -33
- package/lib/tools/dialogs.js +0 -47
- package/lib/tools/evaluate.js +0 -53
- package/lib/tools/extractFrameworkState.js +0 -214
- package/lib/tools/files.js +0 -45
- package/lib/tools/form.js +0 -57
- package/lib/tools/getSnapshot.js +0 -37
- package/lib/tools/getVisibleHtml.js +0 -52
- package/lib/tools/install.js +0 -51
- package/lib/tools/keyboard.js +0 -78
- package/lib/tools/mouse.js +0 -99
- package/lib/tools/navigate.js +0 -70
- package/lib/tools/network.js +0 -123
- package/lib/tools/networkDetail.js +0 -229
- package/lib/tools/networkSearch/bodySearch.js +0 -147
- package/lib/tools/networkSearch/grouping.js +0 -28
- package/lib/tools/networkSearch/helpers.js +0 -32
- package/lib/tools/networkSearch/searchHtml.js +0 -67
- package/lib/tools/networkSearch/types.js +0 -1
- package/lib/tools/networkSearch/urlSearch.js +0 -82
- package/lib/tools/networkSearch.js +0 -268
- package/lib/tools/pdf.js +0 -40
- package/lib/tools/repl.js +0 -402
- package/lib/tools/screenshot.js +0 -79
- package/lib/tools/scroll.js +0 -126
- package/lib/tools/snapshot.js +0 -144
- package/lib/tools/tabs.js +0 -59
- package/lib/tools/tool.js +0 -33
- package/lib/tools/utils.js +0 -74
- package/lib/tools/wait.js +0 -55
- package/lib/tools.js +0 -67
- package/lib/utils/adBlockFilter.js +0 -87
- package/lib/utils/codegen.js +0 -51
- package/lib/utils/extensionPath.js +0 -10
- package/lib/utils/fileUtils.js +0 -36
- package/lib/utils/graphql.js +0 -258
- package/lib/utils/guid.js +0 -22
- package/lib/utils/httpServer.js +0 -39
- package/lib/utils/log.js +0 -21
- package/lib/utils/manualPromise.js +0 -111
- package/lib/utils/networkFormat.js +0 -12
- package/lib/utils/package.js +0 -20
- package/lib/utils/result.js +0 -2
- package/lib/utils/sanitizeHtml.js +0 -98
- package/lib/utils/truncate.js +0 -103
- package/lib/utils/withTimeout.js +0 -7
- package/src/index.ts +0 -50
package/lib/tools/snapshot.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
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 { defineTabTool, defineTool } from './tool.js';
|
|
18
|
-
import * as javascript from '../utils/codegen.js';
|
|
19
|
-
import { generateLocator } from './utils.js';
|
|
20
|
-
const snapshot = defineTool({
|
|
21
|
-
capability: 'core',
|
|
22
|
-
schema: {
|
|
23
|
-
name: 'browser_snapshot',
|
|
24
|
-
title: 'Page snapshot',
|
|
25
|
-
description: 'Capture accessibility snapshot of the current page, this is better than screenshot',
|
|
26
|
-
inputSchema: z.object({}),
|
|
27
|
-
type: 'readOnly',
|
|
28
|
-
},
|
|
29
|
-
handle: async (context, params, response) => {
|
|
30
|
-
await context.ensureTab();
|
|
31
|
-
response.setIncludeSnapshot('full');
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
export const elementSchema = z.object({
|
|
35
|
-
element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
|
|
36
|
-
ref: z.string().describe('Exact target element reference from the page snapshot'),
|
|
37
|
-
});
|
|
38
|
-
const clickSchema = elementSchema.extend({
|
|
39
|
-
doubleClick: z.boolean().optional().describe('Whether to perform a double click instead of a single click'),
|
|
40
|
-
button: z.enum(['left', 'right', 'middle']).optional().describe('Button to click, defaults to left'),
|
|
41
|
-
modifiers: z.array(z.enum(['Alt', 'Control', 'ControlOrMeta', 'Meta', 'Shift'])).optional().describe('Modifier keys to press'),
|
|
42
|
-
});
|
|
43
|
-
const click = defineTabTool({
|
|
44
|
-
capability: 'core',
|
|
45
|
-
schema: {
|
|
46
|
-
name: 'browser_click',
|
|
47
|
-
title: 'Click',
|
|
48
|
-
description: 'Perform click on a web page',
|
|
49
|
-
inputSchema: clickSchema,
|
|
50
|
-
type: 'input',
|
|
51
|
-
},
|
|
52
|
-
handle: async (tab, params, response) => {
|
|
53
|
-
response.setIncludeSnapshot();
|
|
54
|
-
const locator = await tab.refLocator(params);
|
|
55
|
-
const options = {
|
|
56
|
-
button: params.button,
|
|
57
|
-
modifiers: params.modifiers,
|
|
58
|
-
};
|
|
59
|
-
const formatted = javascript.formatObject(options, ' ', 'oneline');
|
|
60
|
-
const optionsAttr = formatted !== '{}' ? formatted : '';
|
|
61
|
-
if (params.doubleClick)
|
|
62
|
-
response.addCode(`await page.${await generateLocator(locator)}.dblclick(${optionsAttr});`);
|
|
63
|
-
else
|
|
64
|
-
response.addCode(`await page.${await generateLocator(locator)}.click(${optionsAttr});`);
|
|
65
|
-
await tab.waitForCompletion(async () => {
|
|
66
|
-
if (params.doubleClick)
|
|
67
|
-
await locator.dblclick(options);
|
|
68
|
-
else
|
|
69
|
-
await locator.click(options);
|
|
70
|
-
});
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
const drag = defineTabTool({
|
|
74
|
-
capability: 'core',
|
|
75
|
-
schema: {
|
|
76
|
-
name: 'browser_drag',
|
|
77
|
-
title: 'Drag mouse',
|
|
78
|
-
description: 'Perform drag and drop between two elements',
|
|
79
|
-
inputSchema: z.object({
|
|
80
|
-
startElement: z.string().describe('Human-readable source element description used to obtain the permission to interact with the element'),
|
|
81
|
-
startRef: z.string().describe('Exact source element reference from the page snapshot'),
|
|
82
|
-
endElement: z.string().describe('Human-readable target element description used to obtain the permission to interact with the element'),
|
|
83
|
-
endRef: z.string().describe('Exact target element reference from the page snapshot'),
|
|
84
|
-
}),
|
|
85
|
-
type: 'input',
|
|
86
|
-
},
|
|
87
|
-
handle: async (tab, params, response) => {
|
|
88
|
-
response.setIncludeSnapshot();
|
|
89
|
-
const [startLocator, endLocator] = await tab.refLocators([
|
|
90
|
-
{ ref: params.startRef, element: params.startElement },
|
|
91
|
-
{ ref: params.endRef, element: params.endElement },
|
|
92
|
-
]);
|
|
93
|
-
await tab.waitForCompletion(async () => {
|
|
94
|
-
await startLocator.dragTo(endLocator);
|
|
95
|
-
});
|
|
96
|
-
response.addCode(`await page.${await generateLocator(startLocator)}.dragTo(page.${await generateLocator(endLocator)});`);
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
const hover = defineTabTool({
|
|
100
|
-
capability: 'core',
|
|
101
|
-
schema: {
|
|
102
|
-
name: 'browser_hover',
|
|
103
|
-
title: 'Hover mouse',
|
|
104
|
-
description: 'Hover over element on page',
|
|
105
|
-
inputSchema: elementSchema,
|
|
106
|
-
type: 'readOnly',
|
|
107
|
-
},
|
|
108
|
-
handle: async (tab, params, response) => {
|
|
109
|
-
response.setIncludeSnapshot();
|
|
110
|
-
const locator = await tab.refLocator(params);
|
|
111
|
-
response.addCode(`await page.${await generateLocator(locator)}.hover();`);
|
|
112
|
-
await tab.waitForCompletion(async () => {
|
|
113
|
-
await locator.hover();
|
|
114
|
-
});
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
const selectOptionSchema = elementSchema.extend({
|
|
118
|
-
values: z.array(z.string()).describe('Array of values to select in the dropdown. This can be a single value or multiple values.'),
|
|
119
|
-
});
|
|
120
|
-
const selectOption = defineTabTool({
|
|
121
|
-
capability: 'core',
|
|
122
|
-
schema: {
|
|
123
|
-
name: 'browser_select_option',
|
|
124
|
-
title: 'Select option',
|
|
125
|
-
description: 'Select an option in a dropdown',
|
|
126
|
-
inputSchema: selectOptionSchema,
|
|
127
|
-
type: 'input',
|
|
128
|
-
},
|
|
129
|
-
handle: async (tab, params, response) => {
|
|
130
|
-
response.setIncludeSnapshot();
|
|
131
|
-
const locator = await tab.refLocator(params);
|
|
132
|
-
response.addCode(`await page.${await generateLocator(locator)}.selectOption(${javascript.formatObject(params.values)});`);
|
|
133
|
-
await tab.waitForCompletion(async () => {
|
|
134
|
-
await locator.selectOption(params.values);
|
|
135
|
-
});
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
export default [
|
|
139
|
-
snapshot,
|
|
140
|
-
click,
|
|
141
|
-
drag,
|
|
142
|
-
hover,
|
|
143
|
-
selectOption,
|
|
144
|
-
];
|
package/lib/tools/tabs.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
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 browserTabs = defineTool({
|
|
19
|
-
capability: 'core-tabs',
|
|
20
|
-
schema: {
|
|
21
|
-
name: 'browser_tabs',
|
|
22
|
-
title: 'Manage tabs',
|
|
23
|
-
description: 'List, create, close, or select a browser tab.',
|
|
24
|
-
inputSchema: z.object({
|
|
25
|
-
action: z.enum(['list', 'new', 'close', 'select']).describe('Operation to perform'),
|
|
26
|
-
index: z.number().optional().describe('Tab index, used for close/select. If omitted for close, current tab is closed.'),
|
|
27
|
-
}),
|
|
28
|
-
type: 'action',
|
|
29
|
-
},
|
|
30
|
-
handle: async (context, params, response) => {
|
|
31
|
-
switch (params.action) {
|
|
32
|
-
case 'list': {
|
|
33
|
-
await context.ensureTab();
|
|
34
|
-
response.setIncludeTabs();
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
case 'new': {
|
|
38
|
-
await context.newTab();
|
|
39
|
-
response.setIncludeTabs();
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
case 'close': {
|
|
43
|
-
await context.closeTab(params.index);
|
|
44
|
-
response.setIncludeSnapshot('full');
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
case 'select': {
|
|
48
|
-
if (params.index === undefined)
|
|
49
|
-
throw new Error('Tab index is required');
|
|
50
|
-
await context.selectTab(params.index);
|
|
51
|
-
response.setIncludeSnapshot('full');
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
export default [
|
|
58
|
-
browserTabs,
|
|
59
|
-
];
|
package/lib/tools/tool.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
export function defineTool(tool) {
|
|
17
|
-
return tool;
|
|
18
|
-
}
|
|
19
|
-
export function defineTabTool(tool) {
|
|
20
|
-
return {
|
|
21
|
-
...tool,
|
|
22
|
-
handle: async (context, params, response) => {
|
|
23
|
-
const tab = await context.ensureTab();
|
|
24
|
-
const modalStates = tab.modalStates().map(state => state.type);
|
|
25
|
-
if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState))
|
|
26
|
-
response.addError(`Error: The tool "${tool.schema.name}" can only be used when there is related modal state present.\n` + tab.modalStatesMarkdown().join('\n'));
|
|
27
|
-
else if (!tool.clearsModalState && modalStates.length)
|
|
28
|
-
response.addError(`Error: Tool "${tool.schema.name}" does not handle the modal state.\n` + tab.modalStatesMarkdown().join('\n'));
|
|
29
|
-
else
|
|
30
|
-
return tool.handle(tab, params, response);
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|
package/lib/tools/utils.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
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_get_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
|
-
}
|
package/lib/tools/wait.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
if (params.time) {
|
|
35
|
-
response.addCode(`await new Promise(f => setTimeout(f, ${params.time} * 1000));`);
|
|
36
|
-
await new Promise(f => setTimeout(f, Math.min(30000, params.time * 1000)));
|
|
37
|
-
}
|
|
38
|
-
const tab = context.currentTabOrDie();
|
|
39
|
-
const locator = params.text ? tab.page.getByText(params.text).first() : undefined;
|
|
40
|
-
const goneLocator = params.textGone ? tab.page.getByText(params.textGone).first() : undefined;
|
|
41
|
-
if (goneLocator) {
|
|
42
|
-
response.addCode(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`);
|
|
43
|
-
await goneLocator.waitFor({ state: 'hidden' });
|
|
44
|
-
}
|
|
45
|
-
if (locator) {
|
|
46
|
-
response.addCode(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
|
|
47
|
-
await locator.waitFor({ state: 'visible' });
|
|
48
|
-
}
|
|
49
|
-
response.addResult(`Waited for ${params.text || params.textGone || params.time}`);
|
|
50
|
-
response.setIncludeSnapshot();
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
export default [
|
|
54
|
-
wait,
|
|
55
|
-
];
|
package/lib/tools.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
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 files from './tools/files.js';
|
|
20
|
-
// import install from './tools/install.js';
|
|
21
|
-
import keyboard from './tools/keyboard.js';
|
|
22
|
-
import navigate from './tools/navigate.js';
|
|
23
|
-
import network from './tools/network.js';
|
|
24
|
-
import networkSearch from './tools/networkSearch.js';
|
|
25
|
-
import networkDetail from './tools/networkDetail.js';
|
|
26
|
-
// import pdf from './tools/pdf.js';
|
|
27
|
-
import snapshot from './tools/snapshot.js';
|
|
28
|
-
// import tabs from './tools/tabs.js';
|
|
29
|
-
// import screenshot from './tools/screenshot.js';
|
|
30
|
-
// import wait from './tools/wait.js';
|
|
31
|
-
// import javascript from './tools/javascript.js';
|
|
32
|
-
import evaluate from './tools/evaluate.js';
|
|
33
|
-
import getVisibleHtml from './tools/getVisibleHtml.js';
|
|
34
|
-
import getSnapshot from './tools/getSnapshot.js';
|
|
35
|
-
import repl from './tools/repl.js';
|
|
36
|
-
import extractFrameworkState from './tools/extractFrameworkState.js';
|
|
37
|
-
import scroll from './tools/scroll.js';
|
|
38
|
-
import { toolNameSchema } from './hooks/schema.js';
|
|
39
|
-
export const allTools = [
|
|
40
|
-
...common,
|
|
41
|
-
...console,
|
|
42
|
-
// ...dialogs(true),
|
|
43
|
-
// ...files(true),
|
|
44
|
-
// ...install,
|
|
45
|
-
...keyboard,
|
|
46
|
-
...navigate,
|
|
47
|
-
...network,
|
|
48
|
-
...networkSearch,
|
|
49
|
-
...networkDetail,
|
|
50
|
-
// ...pdf,
|
|
51
|
-
// ...screenshot,
|
|
52
|
-
...snapshot,
|
|
53
|
-
// ...javascript,
|
|
54
|
-
...evaluate,
|
|
55
|
-
// ...tabs(true),
|
|
56
|
-
// ...testing,
|
|
57
|
-
// ...wait,
|
|
58
|
-
...getVisibleHtml,
|
|
59
|
-
...getSnapshot,
|
|
60
|
-
...repl,
|
|
61
|
-
...extractFrameworkState,
|
|
62
|
-
...scroll,
|
|
63
|
-
];
|
|
64
|
-
export function filteredTools(config) {
|
|
65
|
-
return allTools.filter(tool => (tool.capability.startsWith('core') || config.capabilities?.includes(tool.capability)) &&
|
|
66
|
-
toolNameSchema.safeParse(tool.schema.name).success);
|
|
67
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import { dirname } from 'path';
|
|
5
|
-
import { FiltersEngine, Request } from '@ghostery/adblocker';
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = dirname(__filename);
|
|
8
|
-
class AdBlockFilter {
|
|
9
|
-
_engine;
|
|
10
|
-
_initialized = false;
|
|
11
|
-
_loadFilters() {
|
|
12
|
-
const packageRoot = path.resolve(__dirname, '../..');
|
|
13
|
-
const libFiltersDir = path.join(packageRoot, 'lib/filters');
|
|
14
|
-
const srcFiltersDir = path.join(packageRoot, 'src/filters');
|
|
15
|
-
const filtersDir = fs.existsSync(libFiltersDir) ? libFiltersDir : srcFiltersDir;
|
|
16
|
-
if (!fs.existsSync(filtersDir))
|
|
17
|
-
return FiltersEngine.empty();
|
|
18
|
-
const filterFiles = fs.readdirSync(filtersDir).filter(f => f.endsWith('.txt'));
|
|
19
|
-
const allFilters = [];
|
|
20
|
-
for (const file of filterFiles) {
|
|
21
|
-
const filePath = path.join(filtersDir, file);
|
|
22
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
23
|
-
allFilters.push(content);
|
|
24
|
-
}
|
|
25
|
-
const combinedFilters = allFilters.join('\n');
|
|
26
|
-
return FiltersEngine.parse(combinedFilters);
|
|
27
|
-
}
|
|
28
|
-
initialize() {
|
|
29
|
-
if (this._initialized)
|
|
30
|
-
return;
|
|
31
|
-
this._engine = this._loadFilters();
|
|
32
|
-
this._initialized = true;
|
|
33
|
-
}
|
|
34
|
-
shouldBlockRequest(url, domain, resourceType) {
|
|
35
|
-
if (!this._initialized)
|
|
36
|
-
this.initialize();
|
|
37
|
-
if (!this._engine)
|
|
38
|
-
return false;
|
|
39
|
-
try {
|
|
40
|
-
const urlObj = new URL(url);
|
|
41
|
-
const hostname = urlObj.hostname;
|
|
42
|
-
const request = Request.fromRawDetails({
|
|
43
|
-
url,
|
|
44
|
-
hostname,
|
|
45
|
-
domain,
|
|
46
|
-
sourceUrl: url,
|
|
47
|
-
sourceHostname: hostname,
|
|
48
|
-
sourceDomain: domain,
|
|
49
|
-
type: this._mapResourceType(resourceType),
|
|
50
|
-
requestId: '',
|
|
51
|
-
tabId: 0,
|
|
52
|
-
});
|
|
53
|
-
const result = this._engine.match(request);
|
|
54
|
-
return result.match;
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
_mapResourceType(resourceType) {
|
|
61
|
-
const mapping = {
|
|
62
|
-
'document': 'main_frame',
|
|
63
|
-
'stylesheet': 'stylesheet',
|
|
64
|
-
'image': 'image',
|
|
65
|
-
'media': 'media',
|
|
66
|
-
'font': 'font',
|
|
67
|
-
'script': 'script',
|
|
68
|
-
'texttrack': 'other',
|
|
69
|
-
'xhr': 'xmlhttprequest',
|
|
70
|
-
'fetch': 'xmlhttprequest',
|
|
71
|
-
'websocket': 'websocket',
|
|
72
|
-
'manifest': 'other',
|
|
73
|
-
'other': 'other',
|
|
74
|
-
};
|
|
75
|
-
return mapping[resourceType] || 'other';
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
let filterInstance;
|
|
79
|
-
export const getAdBlockFilter = () => {
|
|
80
|
-
if (!filterInstance)
|
|
81
|
-
filterInstance = new AdBlockFilter();
|
|
82
|
-
return filterInstance;
|
|
83
|
-
};
|
|
84
|
-
export const shouldBlockRequest = (url, domain, resourceType) => {
|
|
85
|
-
const filter = getAdBlockFilter();
|
|
86
|
-
return filter.shouldBlockRequest(url, domain, resourceType);
|
|
87
|
-
};
|
package/lib/utils/codegen.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
// adapted from:
|
|
17
|
-
// - https://github.com/microsoft/playwright/blob/76ee48dc9d4034536e3ec5b2c7ce8be3b79418a8/packages/playwright-core/src/utils/isomorphic/stringUtils.ts
|
|
18
|
-
// - https://github.com/microsoft/playwright/blob/76ee48dc9d4034536e3ec5b2c7ce8be3b79418a8/packages/playwright-core/src/server/codegen/javascript.ts
|
|
19
|
-
// NOTE: this function should not be used to escape any selectors.
|
|
20
|
-
export function escapeWithQuotes(text, char = '\'') {
|
|
21
|
-
const stringified = JSON.stringify(text);
|
|
22
|
-
const escapedText = stringified.substring(1, stringified.length - 1).replace(/\\"/g, '"');
|
|
23
|
-
if (char === '\'')
|
|
24
|
-
return char + escapedText.replace(/[']/g, '\\\'') + char;
|
|
25
|
-
if (char === '"')
|
|
26
|
-
return char + escapedText.replace(/["]/g, '\\"') + char;
|
|
27
|
-
if (char === '`')
|
|
28
|
-
return char + escapedText.replace(/[`]/g, '\\`') + char;
|
|
29
|
-
throw new Error('Invalid escape char');
|
|
30
|
-
}
|
|
31
|
-
export function quote(text) {
|
|
32
|
-
return escapeWithQuotes(text, '\'');
|
|
33
|
-
}
|
|
34
|
-
export function formatObject(value, indent = ' ', mode = 'multiline') {
|
|
35
|
-
if (typeof value === 'string')
|
|
36
|
-
return quote(value);
|
|
37
|
-
if (Array.isArray(value))
|
|
38
|
-
return `[${value.map(o => formatObject(o)).join(', ')}]`;
|
|
39
|
-
if (typeof value === 'object') {
|
|
40
|
-
const keys = Object.keys(value).filter(key => value[key] !== undefined).sort();
|
|
41
|
-
if (!keys.length)
|
|
42
|
-
return '{}';
|
|
43
|
-
const tokens = [];
|
|
44
|
-
for (const key of keys)
|
|
45
|
-
tokens.push(`${key}: ${formatObject(value[key])}`);
|
|
46
|
-
if (mode === 'multiline')
|
|
47
|
-
return `{\n${tokens.join(`,\n${indent}`)}\n}`;
|
|
48
|
-
return `{ ${tokens.join(', ')} }`;
|
|
49
|
-
}
|
|
50
|
-
return String(value);
|
|
51
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { dirname, resolve } from 'node:path';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
-
// Resolve package root from this module's location
|
|
4
|
-
// In published package: node_modules/@wordbricks/playwright-mcp/lib/utils/extensionPath.js
|
|
5
|
-
// In development: src/utils/extensionPath.ts
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = dirname(__filename);
|
|
8
|
-
// Go up from lib/utils/ or src/utils/ to package root
|
|
9
|
-
const packageRoot = resolve(__dirname, '../..');
|
|
10
|
-
export const extensionPath = resolve(packageRoot, 'src/extensions/uBlockOriginLite');
|
package/lib/utils/fileUtils.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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 os from 'node:os';
|
|
17
|
-
import path from 'node:path';
|
|
18
|
-
export function cacheDir() {
|
|
19
|
-
let cacheDirectory;
|
|
20
|
-
if (process.platform === 'linux')
|
|
21
|
-
cacheDirectory = process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache');
|
|
22
|
-
else if (process.platform === 'darwin')
|
|
23
|
-
cacheDirectory = path.join(os.homedir(), 'Library', 'Caches');
|
|
24
|
-
else if (process.platform === 'win32')
|
|
25
|
-
cacheDirectory = process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local');
|
|
26
|
-
else
|
|
27
|
-
throw new Error('Unsupported platform: ' + process.platform);
|
|
28
|
-
return path.join(cacheDirectory, 'ms-playwright');
|
|
29
|
-
}
|
|
30
|
-
export function sanitizeForFilePath(s) {
|
|
31
|
-
const sanitize = (s) => s.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, '-');
|
|
32
|
-
const separator = s.lastIndexOf('.');
|
|
33
|
-
if (separator === -1)
|
|
34
|
-
return sanitize(s);
|
|
35
|
-
return sanitize(s.substring(0, separator)) + '.' + sanitize(s.substring(separator + 1));
|
|
36
|
-
}
|