patchright-core 1.56.1 → 1.58.2
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/ThirdPartyNotices.txt +3134 -560
- package/bin/install_webkit_wsl.ps1 +1 -3
- package/browsers.json +21 -22
- package/lib/cli/program.js +16 -60
- package/lib/client/api.js +3 -3
- package/lib/client/browser.js +3 -5
- package/lib/client/browserContext.js +62 -8
- package/lib/client/browserType.js +4 -3
- package/lib/client/connection.js +4 -0
- package/lib/client/consoleMessage.js +5 -1
- package/lib/client/electron.js +1 -1
- package/lib/client/elementHandle.js +3 -0
- package/lib/client/events.js +5 -1
- package/lib/client/fetch.js +3 -4
- package/lib/client/frame.js +10 -1
- package/lib/client/locator.js +12 -1
- package/lib/client/network.js +5 -1
- package/lib/client/page.js +31 -6
- package/lib/client/pageAgent.js +64 -0
- package/lib/client/platform.js +3 -0
- package/lib/client/playwright.js +1 -5
- package/lib/client/tracing.js +7 -5
- package/lib/client/worker.js +22 -0
- package/lib/generated/clockSource.js +1 -1
- package/lib/generated/injectedScriptSource.js +1 -1
- package/lib/generated/pollingRecorderSource.js +1 -1
- package/lib/inProcessFactory.js +0 -2
- package/lib/mcpBundle.js +84 -0
- package/lib/mcpBundleImpl/index.js +147 -0
- package/lib/protocol/serializers.js +5 -0
- package/lib/protocol/validator.js +112 -50
- package/lib/remote/playwrightServer.js +1 -2
- package/lib/server/agent/actionRunner.js +335 -0
- package/lib/server/agent/actions.js +128 -0
- package/lib/server/agent/codegen.js +111 -0
- package/lib/server/agent/context.js +150 -0
- package/lib/server/agent/expectTools.js +156 -0
- package/lib/server/agent/pageAgent.js +204 -0
- package/lib/server/agent/performTools.js +262 -0
- package/lib/server/agent/tool.js +109 -0
- package/lib/server/android/android.js +1 -1
- package/lib/server/artifact.js +1 -1
- package/lib/server/bidi/bidiBrowser.js +81 -22
- package/lib/server/bidi/bidiChromium.js +9 -13
- package/lib/server/bidi/bidiConnection.js +1 -0
- package/lib/server/bidi/bidiDeserializer.js +116 -0
- package/lib/server/bidi/bidiExecutionContext.js +75 -29
- package/lib/server/bidi/bidiFirefox.js +7 -9
- package/lib/server/bidi/bidiNetworkManager.js +1 -1
- package/lib/server/bidi/bidiPage.js +61 -30
- package/lib/server/bidi/third_party/bidiProtocolCore.js +1 -0
- package/lib/server/browserContext.js +43 -36
- package/lib/server/browserType.js +12 -4
- package/lib/server/chromium/chromium.js +26 -21
- package/lib/server/chromium/chromiumSwitches.js +12 -3
- package/lib/server/chromium/crBrowser.js +30 -12
- package/lib/server/chromium/crConnection.js +0 -5
- package/lib/server/chromium/crCoverage.js +13 -1
- package/lib/server/chromium/crDevTools.js +0 -2
- package/lib/server/chromium/crNetworkManager.js +107 -18
- package/lib/server/chromium/crPage.js +68 -124
- package/lib/server/chromium/crServiceWorker.js +14 -1
- package/lib/server/codegen/javascript.js +6 -29
- package/lib/server/console.js +5 -1
- package/lib/server/deviceDescriptorsSource.json +56 -56
- package/lib/server/dispatchers/browserContextDispatcher.js +26 -8
- package/lib/server/dispatchers/dispatcher.js +6 -13
- package/lib/server/dispatchers/frameDispatcher.js +1 -1
- package/lib/server/dispatchers/jsHandleDispatcher.js +2 -2
- package/lib/server/dispatchers/pageAgentDispatcher.js +96 -0
- package/lib/server/dispatchers/pageDispatcher.js +14 -22
- package/lib/server/dispatchers/playwrightDispatcher.js +0 -4
- package/lib/server/dom.js +12 -3
- package/lib/server/electron/electron.js +6 -3
- package/lib/server/firefox/ffBrowser.js +10 -20
- package/lib/server/firefox/ffConnection.js +0 -5
- package/lib/server/firefox/ffNetworkManager.js +2 -2
- package/lib/server/firefox/ffPage.js +18 -24
- package/lib/server/firefox/firefox.js +18 -9
- package/lib/server/frameSelectors.js +18 -8
- package/lib/server/frames.js +257 -87
- package/lib/server/input.js +7 -3
- package/lib/server/instrumentation.js +3 -0
- package/lib/server/javascript.js +8 -4
- package/lib/server/launchApp.js +2 -1
- package/lib/server/localUtils.js +4 -8
- package/lib/server/network.js +50 -12
- package/lib/server/page.js +112 -126
- package/lib/server/playwright.js +2 -4
- package/lib/server/progress.js +26 -6
- package/lib/server/recorder/recorderApp.js +80 -101
- package/lib/server/recorder.js +3 -2
- package/lib/server/registry/browserFetcher.js +6 -4
- package/lib/server/registry/index.js +278 -189
- package/lib/server/registry/oopDownloadBrowserMain.js +9 -2
- package/lib/server/screencast.js +190 -0
- package/lib/server/screenshotter.js +6 -0
- package/lib/server/socksClientCertificatesInterceptor.js +1 -1
- package/lib/server/trace/recorder/snapshotter.js +17 -8
- package/lib/server/trace/recorder/snapshotterInjected.js +30 -72
- package/lib/server/trace/recorder/tracing.js +31 -21
- package/lib/server/trace/viewer/traceParser.js +72 -0
- package/lib/server/trace/viewer/traceViewer.js +45 -40
- package/lib/server/utils/comparators.js +3 -25
- package/lib/server/utils/expectUtils.js +87 -2
- package/lib/server/utils/hostPlatform.js +30 -3
- package/lib/server/utils/httpServer.js +5 -20
- package/lib/server/utils/imageUtils.js +141 -0
- package/lib/server/utils/network.js +55 -40
- package/lib/server/utils/nodePlatform.js +6 -0
- package/lib/server/{chromium/videoRecorder.js → videoRecorder.js} +35 -24
- package/lib/server/webkit/webkit.js +5 -16
- package/lib/server/webkit/wkBrowser.js +2 -6
- package/lib/server/webkit/wkConnection.js +1 -6
- package/lib/server/webkit/wkInterceptableRequest.js +29 -1
- package/lib/server/webkit/wkPage.js +76 -51
- package/lib/server/webkit/wkWorkers.js +2 -1
- package/lib/utils/isomorphic/ariaSnapshot.js +63 -0
- package/lib/utils/isomorphic/locatorGenerators.js +24 -8
- package/lib/utils/isomorphic/lruCache.js +51 -0
- package/lib/utils/isomorphic/mimeType.js +1 -1
- package/lib/utils/isomorphic/protocolFormatter.js +3 -0
- package/lib/utils/isomorphic/protocolMetainfo.js +11 -2
- package/lib/utils/isomorphic/stringUtils.js +49 -0
- package/lib/utils/isomorphic/trace/entries.js +16 -0
- package/lib/utils/isomorphic/trace/snapshotRenderer.js +499 -0
- package/lib/utils/isomorphic/trace/snapshotServer.js +120 -0
- package/lib/utils/isomorphic/trace/snapshotStorage.js +89 -0
- package/lib/utils/isomorphic/trace/traceLoader.js +131 -0
- package/lib/utils/isomorphic/trace/traceModel.js +365 -0
- package/lib/utils/isomorphic/trace/traceModernizer.js +400 -0
- package/lib/utils/isomorphic/trace/versions/traceV3.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV4.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV5.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV6.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV7.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV8.js +16 -0
- package/lib/utils/isomorphic/urlMatch.js +19 -5
- package/lib/utils/isomorphic/yaml.js +84 -0
- package/lib/utils.js +4 -0
- package/lib/utilsBundle.js +1 -1
- package/lib/utilsBundleImpl/index.js +124 -124
- package/lib/vite/htmlReport/index.html +21 -21
- package/lib/vite/recorder/assets/codeMirrorModule-CFUTFUO7.js +32 -0
- package/lib/vite/recorder/assets/{codeMirrorModule-C3UTv-Ge.css → codeMirrorModule-DYBRYzYX.css} +1 -1
- package/lib/vite/recorder/assets/{index-Ri0uHF7I.css → index-BSjZa4pk.css} +1 -1
- package/lib/vite/recorder/assets/index-CVkBxsGf.js +193 -0
- package/lib/vite/recorder/index.html +2 -2
- package/lib/vite/traceViewer/assets/codeMirrorModule-BVA4h_ZY.js +32 -0
- package/lib/vite/traceViewer/assets/defaultSettingsView-CjfmcdOz.js +266 -0
- package/lib/vite/traceViewer/{codeMirrorModule.C3UTv-Ge.css → codeMirrorModule.DYBRYzYX.css} +1 -1
- package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +1 -0
- package/lib/vite/traceViewer/index.BVu7tZDe.css +1 -0
- package/lib/vite/traceViewer/index.BtyWtaE-.js +2 -0
- package/lib/vite/traceViewer/index.html +6 -6
- package/lib/vite/traceViewer/manifest.webmanifest +16 -0
- package/lib/vite/traceViewer/snapshot.html +3 -3
- package/lib/vite/traceViewer/sw.bundle.js +5 -3
- package/lib/vite/traceViewer/uiMode.fyrXARf2.js +5 -0
- package/lib/vite/traceViewer/uiMode.html +3 -3
- package/package.json +2 -1
- package/types/protocol.d.ts +939 -245
- package/types/types.d.ts +143 -153
- package/lib/client/accessibility.js +0 -49
- package/lib/server/accessibility.js +0 -69
- package/lib/server/bidi/third_party/bidiDeserializer.js +0 -98
- package/lib/server/chromium/crAccessibility.js +0 -263
- package/lib/server/firefox/ffAccessibility.js +0 -238
- package/lib/server/trace/test/inMemorySnapshotter.js +0 -87
- package/lib/server/webkit/wkAccessibility.js +0 -237
- package/lib/server/webkit/wsl/webkit-wsl-transport-client.js +0 -74
- package/lib/server/webkit/wsl/webkit-wsl-transport-server.js +0 -113
- package/lib/vite/recorder/assets/codeMirrorModule-RJCXzfmE.js +0 -24
- package/lib/vite/recorder/assets/index-Y-X2TGJv.js +0 -193
- package/lib/vite/traceViewer/assets/codeMirrorModule-rbQPefq7.js +0 -24
- package/lib/vite/traceViewer/assets/defaultSettingsView-CLbol9XR.js +0 -265
- package/lib/vite/traceViewer/defaultSettingsView.TQ8_7ybu.css +0 -1
- package/lib/vite/traceViewer/index.I8N9v4jT.css +0 -1
- package/lib/vite/traceViewer/index.zIVi6mN9.js +0 -2
- package/lib/vite/traceViewer/uiMode.B_CpmIpF.js +0 -5
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var performTools_exports = {};
|
|
20
|
+
__export(performTools_exports, {
|
|
21
|
+
default: () => performTools_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(performTools_exports);
|
|
24
|
+
var import_mcpBundle = require("../../mcpBundle");
|
|
25
|
+
var import_tool = require("./tool");
|
|
26
|
+
const navigateSchema = import_mcpBundle.z.object({
|
|
27
|
+
url: import_mcpBundle.z.string().describe("URL to navigate to")
|
|
28
|
+
});
|
|
29
|
+
const navigate = (0, import_tool.defineTool)({
|
|
30
|
+
schema: {
|
|
31
|
+
name: "browser_navigate",
|
|
32
|
+
title: "Navigate to URL",
|
|
33
|
+
description: "Navigate to a URL",
|
|
34
|
+
inputSchema: navigateSchema
|
|
35
|
+
},
|
|
36
|
+
handle: async (progress, context, params) => {
|
|
37
|
+
return await context.runActionNoWait(progress, {
|
|
38
|
+
method: "navigate",
|
|
39
|
+
url: params.url
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const snapshot = (0, import_tool.defineTool)({
|
|
44
|
+
schema: {
|
|
45
|
+
name: "browser_snapshot",
|
|
46
|
+
title: "Page snapshot",
|
|
47
|
+
description: "Capture accessibility snapshot of the current page, this is better than screenshot",
|
|
48
|
+
inputSchema: import_mcpBundle.z.object({})
|
|
49
|
+
},
|
|
50
|
+
handle: async (progress, context, params) => {
|
|
51
|
+
return await context.snapshotResult(progress);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const elementSchema = import_mcpBundle.z.object({
|
|
55
|
+
element: import_mcpBundle.z.string().describe("Human-readable element description used to obtain permission to interact with the element"),
|
|
56
|
+
ref: import_mcpBundle.z.string().describe("Exact target element reference from the page snapshot")
|
|
57
|
+
});
|
|
58
|
+
const clickSchema = elementSchema.extend({
|
|
59
|
+
doubleClick: import_mcpBundle.z.boolean().optional().describe("Whether to perform a double click instead of a single click"),
|
|
60
|
+
button: import_mcpBundle.z.enum(["left", "right", "middle"]).optional().describe("Button to click, defaults to left"),
|
|
61
|
+
modifiers: import_mcpBundle.z.array(import_mcpBundle.z.enum(["Alt", "Control", "ControlOrMeta", "Meta", "Shift"])).optional().describe("Modifier keys to press")
|
|
62
|
+
});
|
|
63
|
+
const click = (0, import_tool.defineTool)({
|
|
64
|
+
schema: {
|
|
65
|
+
name: "browser_click",
|
|
66
|
+
title: "Click",
|
|
67
|
+
description: "Perform click on a web page",
|
|
68
|
+
inputSchema: clickSchema
|
|
69
|
+
},
|
|
70
|
+
handle: async (progress, context, params) => {
|
|
71
|
+
const [selector] = await context.refSelectors(progress, [params]);
|
|
72
|
+
return await context.runActionAndWait(progress, {
|
|
73
|
+
method: "click",
|
|
74
|
+
selector,
|
|
75
|
+
button: params.button,
|
|
76
|
+
modifiers: params.modifiers,
|
|
77
|
+
clickCount: params.doubleClick ? 2 : void 0
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const drag = (0, import_tool.defineTool)({
|
|
82
|
+
schema: {
|
|
83
|
+
name: "browser_drag",
|
|
84
|
+
title: "Drag mouse",
|
|
85
|
+
description: "Perform drag and drop between two elements",
|
|
86
|
+
inputSchema: import_mcpBundle.z.object({
|
|
87
|
+
startElement: import_mcpBundle.z.string().describe("Human-readable source element description used to obtain the permission to interact with the element"),
|
|
88
|
+
startRef: import_mcpBundle.z.string().describe("Exact source element reference from the page snapshot"),
|
|
89
|
+
endElement: import_mcpBundle.z.string().describe("Human-readable target element description used to obtain the permission to interact with the element"),
|
|
90
|
+
endRef: import_mcpBundle.z.string().describe("Exact target element reference from the page snapshot")
|
|
91
|
+
})
|
|
92
|
+
},
|
|
93
|
+
handle: async (progress, context, params) => {
|
|
94
|
+
const [sourceSelector, targetSelector] = await context.refSelectors(progress, [
|
|
95
|
+
{ ref: params.startRef, element: params.startElement },
|
|
96
|
+
{ ref: params.endRef, element: params.endElement }
|
|
97
|
+
]);
|
|
98
|
+
return await context.runActionAndWait(progress, {
|
|
99
|
+
method: "drag",
|
|
100
|
+
sourceSelector,
|
|
101
|
+
targetSelector
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const hoverSchema = elementSchema.extend({
|
|
106
|
+
modifiers: import_mcpBundle.z.array(import_mcpBundle.z.enum(["Alt", "Control", "ControlOrMeta", "Meta", "Shift"])).optional().describe("Modifier keys to press")
|
|
107
|
+
});
|
|
108
|
+
const hover = (0, import_tool.defineTool)({
|
|
109
|
+
schema: {
|
|
110
|
+
name: "browser_hover",
|
|
111
|
+
title: "Hover mouse",
|
|
112
|
+
description: "Hover over element on page",
|
|
113
|
+
inputSchema: hoverSchema
|
|
114
|
+
},
|
|
115
|
+
handle: async (progress, context, params) => {
|
|
116
|
+
const [selector] = await context.refSelectors(progress, [params]);
|
|
117
|
+
return await context.runActionAndWait(progress, {
|
|
118
|
+
method: "hover",
|
|
119
|
+
selector,
|
|
120
|
+
modifiers: params.modifiers
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
const selectOptionSchema = elementSchema.extend({
|
|
125
|
+
values: import_mcpBundle.z.array(import_mcpBundle.z.string()).describe("Array of values to select in the dropdown. This can be a single value or multiple values.")
|
|
126
|
+
});
|
|
127
|
+
const selectOption = (0, import_tool.defineTool)({
|
|
128
|
+
schema: {
|
|
129
|
+
name: "browser_select_option",
|
|
130
|
+
title: "Select option",
|
|
131
|
+
description: "Select an option in a dropdown",
|
|
132
|
+
inputSchema: selectOptionSchema
|
|
133
|
+
},
|
|
134
|
+
handle: async (progress, context, params) => {
|
|
135
|
+
const [selector] = await context.refSelectors(progress, [params]);
|
|
136
|
+
return await context.runActionAndWait(progress, {
|
|
137
|
+
method: "selectOption",
|
|
138
|
+
selector,
|
|
139
|
+
labels: params.values
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
const pressKey = (0, import_tool.defineTool)({
|
|
144
|
+
schema: {
|
|
145
|
+
name: "browser_press_key",
|
|
146
|
+
title: "Press a key",
|
|
147
|
+
description: "Press a key on the keyboard",
|
|
148
|
+
inputSchema: import_mcpBundle.z.object({
|
|
149
|
+
key: import_mcpBundle.z.string().describe("Name of the key to press or a character to generate, such as `ArrowLeft` or `a`"),
|
|
150
|
+
modifiers: import_mcpBundle.z.array(import_mcpBundle.z.enum(["Alt", "Control", "ControlOrMeta", "Meta", "Shift"])).optional().describe("Modifier keys to press")
|
|
151
|
+
})
|
|
152
|
+
},
|
|
153
|
+
handle: async (progress, context, params) => {
|
|
154
|
+
return await context.runActionAndWait(progress, {
|
|
155
|
+
method: "pressKey",
|
|
156
|
+
key: params.modifiers ? [...params.modifiers, params.key].join("+") : params.key
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
const typeSchema = elementSchema.extend({
|
|
161
|
+
text: import_mcpBundle.z.string().describe("Text to type into the element"),
|
|
162
|
+
submit: import_mcpBundle.z.boolean().optional().describe("Whether to submit entered text (press Enter after)"),
|
|
163
|
+
slowly: import_mcpBundle.z.boolean().optional().describe("Whether to type one character at a time. Useful for triggering key handlers in the page. By default entire text is filled in at once.")
|
|
164
|
+
});
|
|
165
|
+
const type = (0, import_tool.defineTool)({
|
|
166
|
+
schema: {
|
|
167
|
+
name: "browser_type",
|
|
168
|
+
title: "Type text",
|
|
169
|
+
description: "Type text into editable element",
|
|
170
|
+
inputSchema: typeSchema
|
|
171
|
+
},
|
|
172
|
+
handle: async (progress, context, params) => {
|
|
173
|
+
const [selector] = await context.refSelectors(progress, [params]);
|
|
174
|
+
if (params.slowly) {
|
|
175
|
+
return await context.runActionAndWait(progress, {
|
|
176
|
+
method: "pressSequentially",
|
|
177
|
+
selector,
|
|
178
|
+
text: params.text,
|
|
179
|
+
submit: params.submit
|
|
180
|
+
});
|
|
181
|
+
} else {
|
|
182
|
+
return await context.runActionAndWait(progress, {
|
|
183
|
+
method: "fill",
|
|
184
|
+
selector,
|
|
185
|
+
text: params.text,
|
|
186
|
+
submit: params.submit
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
const fillForm = (0, import_tool.defineTool)({
|
|
192
|
+
schema: {
|
|
193
|
+
name: "browser_fill_form",
|
|
194
|
+
title: "Fill form",
|
|
195
|
+
description: "Fill multiple form fields. Always use this tool when you can fill more than one field at a time.",
|
|
196
|
+
inputSchema: import_mcpBundle.z.object({
|
|
197
|
+
fields: import_mcpBundle.z.array(import_mcpBundle.z.object({
|
|
198
|
+
name: import_mcpBundle.z.string().describe("Human-readable field name"),
|
|
199
|
+
type: import_mcpBundle.z.enum(["textbox", "checkbox", "radio", "combobox", "slider"]).describe("Type of the field"),
|
|
200
|
+
ref: import_mcpBundle.z.string().describe("Exact target field reference from the page snapshot"),
|
|
201
|
+
value: import_mcpBundle.z.string().describe("Value to fill in the field. If the field is a checkbox, the value should be `true` or `false`. If the field is a combobox, the value should be the text of the option.")
|
|
202
|
+
})).describe("Fields to fill in")
|
|
203
|
+
})
|
|
204
|
+
},
|
|
205
|
+
handle: async (progress, context, params) => {
|
|
206
|
+
const actions = [];
|
|
207
|
+
for (const field of params.fields) {
|
|
208
|
+
const [selector] = await context.refSelectors(progress, [{ ref: field.ref, element: field.name }]);
|
|
209
|
+
if (field.type === "textbox" || field.type === "slider") {
|
|
210
|
+
actions.push({
|
|
211
|
+
method: "fill",
|
|
212
|
+
selector,
|
|
213
|
+
text: field.value
|
|
214
|
+
});
|
|
215
|
+
} else if (field.type === "checkbox" || field.type === "radio") {
|
|
216
|
+
actions.push({
|
|
217
|
+
method: "setChecked",
|
|
218
|
+
selector,
|
|
219
|
+
checked: field.value === "true"
|
|
220
|
+
});
|
|
221
|
+
} else if (field.type === "combobox") {
|
|
222
|
+
actions.push({
|
|
223
|
+
method: "selectOption",
|
|
224
|
+
selector,
|
|
225
|
+
labels: [field.value]
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return await context.runActionsAndWait(progress, actions);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
const setCheckedSchema = elementSchema.extend({
|
|
233
|
+
checked: import_mcpBundle.z.boolean().describe("Whether to check the checkbox")
|
|
234
|
+
});
|
|
235
|
+
const setChecked = (0, import_tool.defineTool)({
|
|
236
|
+
schema: {
|
|
237
|
+
name: "browser_set_checked",
|
|
238
|
+
title: "Set checked",
|
|
239
|
+
description: "Set the checked state of a checkbox",
|
|
240
|
+
inputSchema: setCheckedSchema
|
|
241
|
+
},
|
|
242
|
+
handle: async (progress, context, params) => {
|
|
243
|
+
const [selector] = await context.refSelectors(progress, [params]);
|
|
244
|
+
return await context.runActionAndWait(progress, {
|
|
245
|
+
method: "setChecked",
|
|
246
|
+
selector,
|
|
247
|
+
checked: params.checked
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
var performTools_default = [
|
|
252
|
+
navigate,
|
|
253
|
+
snapshot,
|
|
254
|
+
click,
|
|
255
|
+
drag,
|
|
256
|
+
hover,
|
|
257
|
+
selectOption,
|
|
258
|
+
pressKey,
|
|
259
|
+
type,
|
|
260
|
+
fillForm,
|
|
261
|
+
setChecked
|
|
262
|
+
];
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var tool_exports = {};
|
|
20
|
+
__export(tool_exports, {
|
|
21
|
+
defineTool: () => defineTool,
|
|
22
|
+
toolsForLoop: () => toolsForLoop
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(tool_exports);
|
|
25
|
+
var import_mcpBundle = require("../../mcpBundle");
|
|
26
|
+
var import_stringUtils = require("../../utils/isomorphic/stringUtils");
|
|
27
|
+
function defineTool(tool) {
|
|
28
|
+
return tool;
|
|
29
|
+
}
|
|
30
|
+
function toolsForLoop(progress, context, toolDefinitions, options = {}) {
|
|
31
|
+
const tools = toolDefinitions.map((tool) => {
|
|
32
|
+
const result = {
|
|
33
|
+
name: tool.schema.name,
|
|
34
|
+
description: tool.schema.description,
|
|
35
|
+
inputSchema: import_mcpBundle.z.toJSONSchema(tool.schema.inputSchema)
|
|
36
|
+
};
|
|
37
|
+
return result;
|
|
38
|
+
});
|
|
39
|
+
if (options.resultSchema) {
|
|
40
|
+
tools.push({
|
|
41
|
+
name: "report_result",
|
|
42
|
+
description: "Report the result of the task.",
|
|
43
|
+
inputSchema: options.resultSchema
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (options.refuseToPerform === "allow") {
|
|
47
|
+
tools.push({
|
|
48
|
+
name: "refuse_to_perform",
|
|
49
|
+
description: "Refuse to perform action.",
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: "object",
|
|
52
|
+
properties: {
|
|
53
|
+
reason: {
|
|
54
|
+
type: "string",
|
|
55
|
+
description: `Call this when you believe that you can't perform the action because something is wrong with the page. The reason will be reported to the user.`
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
required: ["reason"]
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
let reportedResult;
|
|
63
|
+
let refusedToPerformReason;
|
|
64
|
+
const callTool = async (params) => {
|
|
65
|
+
if (params.name === "report_result") {
|
|
66
|
+
reportedResult = params.arguments;
|
|
67
|
+
return {
|
|
68
|
+
content: [{ type: "text", text: "Done" }],
|
|
69
|
+
isError: false
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (params.name === "refuse_to_perform") {
|
|
73
|
+
refusedToPerformReason = params.arguments.reason;
|
|
74
|
+
return {
|
|
75
|
+
content: [{ type: "text", text: "Done" }],
|
|
76
|
+
isError: false
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const tool = toolDefinitions.find((t) => t.schema.name === params.name);
|
|
80
|
+
if (!tool) {
|
|
81
|
+
return {
|
|
82
|
+
content: [{
|
|
83
|
+
type: "text",
|
|
84
|
+
text: `Tool ${params.name} not found. Available tools: ${toolDefinitions.map((t) => t.schema.name)}`
|
|
85
|
+
}],
|
|
86
|
+
isError: true
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
return await tool.handle(progress, context, params.arguments);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
return {
|
|
93
|
+
content: [{ type: "text", text: (0, import_stringUtils.stripAnsiEscapes)(error.message) }],
|
|
94
|
+
isError: true
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
tools,
|
|
100
|
+
callTool,
|
|
101
|
+
reportedResult: options.resultSchema ? () => reportedResult : void 0,
|
|
102
|
+
refusedToPerformReason: () => refusedToPerformReason
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
defineTool,
|
|
108
|
+
toolsForLoop
|
|
109
|
+
});
|
|
@@ -248,7 +248,7 @@ class AndroidDevice extends import_instrumentation.SdkObject {
|
|
|
248
248
|
"--disable-fre",
|
|
249
249
|
"--no-default-browser-check",
|
|
250
250
|
`--remote-debugging-socket-name=${socketName}`,
|
|
251
|
-
...(0, import_chromiumSwitches.chromiumSwitches)(),
|
|
251
|
+
...(0, import_chromiumSwitches.chromiumSwitches)(void 0, void 0, true),
|
|
252
252
|
...this._innerDefaultArgs(options)
|
|
253
253
|
];
|
|
254
254
|
return chromeArguments;
|
package/lib/server/artifact.js
CHANGED
|
@@ -103,7 +103,7 @@ class Artifact extends import_instrumentation.SdkObject {
|
|
|
103
103
|
if (!this._unaccessibleErrorMessage)
|
|
104
104
|
await import_fs.default.promises.unlink(this._localPath).catch((e) => {
|
|
105
105
|
});
|
|
106
|
-
await this.reportFinished(new import_errors.TargetClosedError());
|
|
106
|
+
await this.reportFinished(new import_errors.TargetClosedError(this.closeReason()));
|
|
107
107
|
}
|
|
108
108
|
async reportFinished(error) {
|
|
109
109
|
if (this._finished)
|
|
@@ -62,12 +62,16 @@ class BidiBrowser extends import_browser.Browser {
|
|
|
62
62
|
browser._bidiSessionInfo = await browser._browserSession.send("session.new", {
|
|
63
63
|
capabilities: {
|
|
64
64
|
alwaysMatch: {
|
|
65
|
-
acceptInsecureCerts: options.persistent?.internalIgnoreHTTPSErrors || options.persistent?.ignoreHTTPSErrors,
|
|
66
|
-
proxy: getProxyConfiguration(options.originalLaunchOptions.proxyOverride ?? options.proxy),
|
|
67
|
-
unhandledPromptBehavior: {
|
|
65
|
+
"acceptInsecureCerts": options.persistent?.internalIgnoreHTTPSErrors || options.persistent?.ignoreHTTPSErrors,
|
|
66
|
+
"proxy": getProxyConfiguration(options.originalLaunchOptions.proxyOverride ?? options.proxy),
|
|
67
|
+
"unhandledPromptBehavior": {
|
|
68
68
|
default: bidi.Session.UserPromptHandlerType.Ignore
|
|
69
69
|
},
|
|
70
|
-
webSocketUrl: true
|
|
70
|
+
"webSocketUrl": true,
|
|
71
|
+
// Chrome with WebDriver BiDi does not support prerendering
|
|
72
|
+
// yet because WebDriver BiDi behavior is not specified. See
|
|
73
|
+
// https://github.com/w3c/webdriver-bidi/issues/321.
|
|
74
|
+
"goog:prerenderingDisabled": true
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
77
|
});
|
|
@@ -76,7 +80,8 @@ class BidiBrowser extends import_browser.Browser {
|
|
|
76
80
|
"browsingContext",
|
|
77
81
|
"network",
|
|
78
82
|
"log",
|
|
79
|
-
"script"
|
|
83
|
+
"script",
|
|
84
|
+
"input"
|
|
80
85
|
]
|
|
81
86
|
});
|
|
82
87
|
await browser._browserSession.send("network.addDataCollector", {
|
|
@@ -122,15 +127,15 @@ class BidiBrowser extends import_browser.Browser {
|
|
|
122
127
|
_onBrowsingContextCreated(event) {
|
|
123
128
|
if (event.parent) {
|
|
124
129
|
const parentFrameId = event.parent;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (!parentFrame)
|
|
128
|
-
continue;
|
|
130
|
+
const page2 = this._findPageForFrame(parentFrameId);
|
|
131
|
+
if (page2) {
|
|
129
132
|
page2._session.addFrameBrowsingContext(event.context);
|
|
130
|
-
page2._page.frameManager.frameAttached(event.context, parentFrameId);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
const frame = page2._page.frameManager.frameAttached(event.context, parentFrameId);
|
|
134
|
+
frame._url = event.url;
|
|
135
|
+
page2._getFrameNode(frame).then((node) => {
|
|
136
|
+
const attributes = node?.value?.attributes;
|
|
137
|
+
frame._name = attributes?.name ?? attributes?.id ?? "";
|
|
138
|
+
});
|
|
134
139
|
return;
|
|
135
140
|
}
|
|
136
141
|
return;
|
|
@@ -140,8 +145,9 @@ class BidiBrowser extends import_browser.Browser {
|
|
|
140
145
|
context = this._defaultContext;
|
|
141
146
|
if (!context)
|
|
142
147
|
return;
|
|
148
|
+
context.doGrantGlobalPermissionsForURL(event.url);
|
|
143
149
|
const session = this._connection.createMainFrameBrowsingContextSession(event.context);
|
|
144
|
-
const opener = event.originalOpener && this.
|
|
150
|
+
const opener = event.originalOpener && this._findPageForFrame(event.originalOpener);
|
|
145
151
|
const page = new import_bidiPage.BidiPage(context, session, opener || null);
|
|
146
152
|
page._page.mainFrame()._url = event.url;
|
|
147
153
|
this._bidiPages.set(event.context, page);
|
|
@@ -171,6 +177,12 @@ class BidiBrowser extends import_browser.Browser {
|
|
|
171
177
|
return;
|
|
172
178
|
}
|
|
173
179
|
}
|
|
180
|
+
_findPageForFrame(frameId) {
|
|
181
|
+
for (const page of this._bidiPages.values()) {
|
|
182
|
+
if (page._page.frameManager.frame(frameId))
|
|
183
|
+
return page;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
174
186
|
}
|
|
175
187
|
class BidiBrowserContext extends import_browserContext.BrowserContext {
|
|
176
188
|
constructor(browser, browserContextId, options) {
|
|
@@ -207,6 +219,10 @@ class BidiBrowserContext extends import_browserContext.BrowserContext {
|
|
|
207
219
|
userContexts: [this._userContextId()]
|
|
208
220
|
}));
|
|
209
221
|
}
|
|
222
|
+
if (this._options.extraHTTPHeaders)
|
|
223
|
+
promises.push(this.doUpdateExtraHTTPHeaders());
|
|
224
|
+
if (this._options.permissions)
|
|
225
|
+
promises.push(this.doGrantPermissions("*", this._options.permissions));
|
|
210
226
|
await Promise.all(promises);
|
|
211
227
|
}
|
|
212
228
|
possiblyUninitializedPages() {
|
|
@@ -265,17 +281,34 @@ class BidiBrowserContext extends import_browserContext.BrowserContext {
|
|
|
265
281
|
);
|
|
266
282
|
}
|
|
267
283
|
async doGrantPermissions(origin, permissions) {
|
|
284
|
+
if (origin === "null")
|
|
285
|
+
return;
|
|
268
286
|
const currentPermissions = this._originToPermissions.get(origin) || [];
|
|
269
287
|
const toGrant = permissions.filter((permission) => !currentPermissions.includes(permission));
|
|
270
288
|
this._originToPermissions.set(origin, [...currentPermissions, ...toGrant]);
|
|
271
|
-
|
|
289
|
+
if (origin === "*") {
|
|
290
|
+
await Promise.all(this._bidiPages().flatMap(
|
|
291
|
+
(page) => page._page.frames().map(
|
|
292
|
+
(frame) => this.doGrantPermissions(new URL(frame._url).origin, permissions)
|
|
293
|
+
)
|
|
294
|
+
));
|
|
295
|
+
} else {
|
|
296
|
+
await Promise.all(toGrant.map((permission) => this._setPermission(origin, permission, bidi.Permissions.PermissionState.Granted)));
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
async doGrantGlobalPermissionsForURL(url) {
|
|
300
|
+
const permissions = this._originToPermissions.get("*");
|
|
301
|
+
if (!permissions)
|
|
302
|
+
return;
|
|
303
|
+
await this.doGrantPermissions(new URL(url).origin, permissions);
|
|
272
304
|
}
|
|
273
305
|
async doClearPermissions() {
|
|
274
306
|
const currentPermissions = [...this._originToPermissions.entries()];
|
|
275
307
|
this._originToPermissions = /* @__PURE__ */ new Map();
|
|
276
|
-
await Promise.all(currentPermissions.
|
|
277
|
-
|
|
278
|
-
|
|
308
|
+
await Promise.all(currentPermissions.flatMap(([origin, permissions]) => {
|
|
309
|
+
if (origin !== "*")
|
|
310
|
+
return permissions.map((p) => this._setPermission(origin, p, bidi.Permissions.PermissionState.Prompt));
|
|
311
|
+
}));
|
|
279
312
|
}
|
|
280
313
|
async _setPermission(origin, permission, state) {
|
|
281
314
|
await this._browser._browserSession.send("permissions.setPermission", {
|
|
@@ -300,6 +333,11 @@ class BidiBrowserContext extends import_browserContext.BrowserContext {
|
|
|
300
333
|
});
|
|
301
334
|
}
|
|
302
335
|
async doUpdateExtraHTTPHeaders() {
|
|
336
|
+
const allHeaders = this._options.extraHTTPHeaders || [];
|
|
337
|
+
await this._browser._browserSession.send("network.setExtraHeaders", {
|
|
338
|
+
headers: allHeaders.map(({ name, value }) => ({ name, value: { type: "string", value } })),
|
|
339
|
+
userContexts: [this._userContextId()]
|
|
340
|
+
});
|
|
303
341
|
}
|
|
304
342
|
async setUserAgent(userAgent) {
|
|
305
343
|
this._options.userAgent = userAgent;
|
|
@@ -334,21 +372,42 @@ class BidiBrowserContext extends import_browserContext.BrowserContext {
|
|
|
334
372
|
await Promise.all(ids.map((script) => this._browser._browserSession.send("script.removePreloadScript", { script })));
|
|
335
373
|
}
|
|
336
374
|
async doUpdateRequestInterception() {
|
|
375
|
+
if (this.requestInterceptors.length > 0 && !this._interceptId) {
|
|
376
|
+
const { intercept } = await this._browser._browserSession.send("network.addIntercept", {
|
|
377
|
+
phases: [bidi.Network.InterceptPhase.BeforeRequestSent],
|
|
378
|
+
urlPatterns: [{ type: "pattern" }]
|
|
379
|
+
});
|
|
380
|
+
this._interceptId = intercept;
|
|
381
|
+
}
|
|
382
|
+
if (this.requestInterceptors.length === 0 && this._interceptId) {
|
|
383
|
+
const intercept = this._interceptId;
|
|
384
|
+
this._interceptId = void 0;
|
|
385
|
+
await this._browser._browserSession.send("network.removeIntercept", { intercept });
|
|
386
|
+
}
|
|
337
387
|
}
|
|
338
388
|
async doUpdateDefaultViewport() {
|
|
339
|
-
if (!this._options.viewport)
|
|
389
|
+
if (!this._options.viewport && !this._options.screen)
|
|
340
390
|
return;
|
|
391
|
+
const screenSize = this._options.screen || this._options.viewport;
|
|
392
|
+
const viewportSize = this._options.viewport || this._options.screen;
|
|
341
393
|
await Promise.all([
|
|
342
394
|
this._browser._browserSession.send("browsingContext.setViewport", {
|
|
343
395
|
viewport: {
|
|
344
|
-
width:
|
|
345
|
-
height:
|
|
396
|
+
width: viewportSize.width,
|
|
397
|
+
height: viewportSize.height
|
|
346
398
|
},
|
|
347
399
|
devicePixelRatio: this._options.deviceScaleFactor || 1,
|
|
348
400
|
userContexts: [this._userContextId()]
|
|
349
401
|
}),
|
|
350
402
|
this._browser._browserSession.send("emulation.setScreenOrientationOverride", {
|
|
351
|
-
screenOrientation: getScreenOrientation(!!this._options.isMobile,
|
|
403
|
+
screenOrientation: getScreenOrientation(!!this._options.isMobile, screenSize),
|
|
404
|
+
userContexts: [this._userContextId()]
|
|
405
|
+
}),
|
|
406
|
+
this._browser._browserSession.send("emulation.setScreenSettingsOverride", {
|
|
407
|
+
screenArea: {
|
|
408
|
+
width: screenSize.width,
|
|
409
|
+
height: screenSize.height
|
|
410
|
+
},
|
|
352
411
|
userContexts: [this._userContextId()]
|
|
353
412
|
})
|
|
354
413
|
]);
|
|
@@ -38,9 +38,10 @@ var import_bidiBrowser = require("./bidiBrowser");
|
|
|
38
38
|
var import_bidiConnection = require("./bidiConnection");
|
|
39
39
|
var import_chromiumSwitches = require("../chromium/chromiumSwitches");
|
|
40
40
|
var import_chromium = require("../chromium/chromium");
|
|
41
|
+
var import_hostPlatform = require("../utils/hostPlatform");
|
|
41
42
|
class BidiChromium extends import_browserType.BrowserType {
|
|
42
43
|
constructor(parent) {
|
|
43
|
-
super(parent, "
|
|
44
|
+
super(parent, "chromium");
|
|
44
45
|
}
|
|
45
46
|
async connectToTransport(transport, options, browserLogsCollector) {
|
|
46
47
|
const bidiTransport = await require("./bidiOverCdp").connectBidiOverCdp(transport);
|
|
@@ -56,14 +57,12 @@ class BidiChromium extends import_browserType.BrowserType {
|
|
|
56
57
|
throw e;
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
|
-
doRewriteStartupLog(
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return error;
|
|
66
|
-
error.logs = [
|
|
60
|
+
doRewriteStartupLog(logs) {
|
|
61
|
+
if (logs.includes("Missing X server"))
|
|
62
|
+
logs = "\n" + (0, import_ascii.wrapInASCIIBox)(import_browserType.kNoXServerRunningError, 1);
|
|
63
|
+
if (!logs.includes("crbug.com/357670") && !logs.includes("No usable sandbox!") && !logs.includes("crbug.com/638180"))
|
|
64
|
+
return logs;
|
|
65
|
+
return [
|
|
67
66
|
`Chromium sandboxing failed!`,
|
|
68
67
|
`================================`,
|
|
69
68
|
`To avoid the sandboxing issue, do either of the following:`,
|
|
@@ -72,7 +71,6 @@ class BidiChromium extends import_browserType.BrowserType {
|
|
|
72
71
|
`================================`,
|
|
73
72
|
``
|
|
74
73
|
].join("\n");
|
|
75
|
-
return error;
|
|
76
74
|
}
|
|
77
75
|
amendEnvironment(env) {
|
|
78
76
|
return env;
|
|
@@ -109,11 +107,9 @@ class BidiChromium extends import_browserType.BrowserType {
|
|
|
109
107
|
if (args.find((arg) => !arg.startsWith("-")))
|
|
110
108
|
throw new Error("Arguments can not specify page to be opened");
|
|
111
109
|
const chromeArguments = [...(0, import_chromiumSwitches.chromiumSwitches)(options.assistantMode)];
|
|
112
|
-
if (import_os.default.platform()
|
|
110
|
+
if (import_os.default.platform() !== "darwin" || !(0, import_hostPlatform.hasGpuMac)()) {
|
|
113
111
|
chromeArguments.push("--enable-unsafe-swiftshader");
|
|
114
112
|
}
|
|
115
|
-
if (options.devtools)
|
|
116
|
-
chromeArguments.push("--auto-open-devtools-for-tabs");
|
|
117
113
|
if (options.headless) {
|
|
118
114
|
chromeArguments.push("--headless");
|
|
119
115
|
chromeArguments.push(
|
|
@@ -173,6 +173,7 @@ class BidiSession extends import_events.EventEmitter {
|
|
|
173
173
|
this._browsingContexts.clear();
|
|
174
174
|
for (const callback of this._callbacks.values()) {
|
|
175
175
|
callback.error.type = this._crashed ? "crashed" : "closed";
|
|
176
|
+
callback.error.setMessage(`Internal server error, session ${callback.error.type}.`);
|
|
176
177
|
callback.error.logs = this.connection._browserDisconnectedLogs;
|
|
177
178
|
callback.reject(callback.error);
|
|
178
179
|
}
|