@cotestdev/mcp_playwright 0.0.2 → 0.0.3
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/lib/cli.d.ts +8 -0
- package/lib/cli.d.ts.map +1 -0
- package/lib/cli.js +11 -0
- package/lib/cli.js.map +1 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +27 -4
- package/lib/index.js.map +1 -1
- package/lib/mcp/browser/actions.d.js +16 -0
- package/lib/mcp/browser/browserContextFactory.js +285 -0
- package/lib/mcp/browser/browserServerBackend.js +74 -0
- package/lib/mcp/browser/codegen.js +66 -0
- package/lib/mcp/browser/config.js +346 -0
- package/lib/mcp/browser/context.js +260 -0
- package/lib/mcp/browser/processUtils.js +102 -0
- package/lib/mcp/browser/response.js +169 -0
- package/lib/mcp/browser/sessionLog.js +160 -0
- package/lib/mcp/browser/tab.js +301 -0
- package/lib/mcp/browser/tools/common.js +71 -0
- package/lib/mcp/browser/tools/console.js +41 -0
- package/lib/mcp/browser/tools/dialogs.js +61 -0
- package/lib/mcp/browser/tools/evaluate.js +71 -0
- package/lib/mcp/browser/tools/files.js +54 -0
- package/lib/mcp/browser/tools/form.js +75 -0
- package/lib/mcp/browser/tools/install.js +69 -0
- package/lib/mcp/browser/tools/keyboard.js +85 -0
- package/lib/mcp/browser/tools/mouse.js +107 -0
- package/lib/mcp/browser/tools/navigate.js +63 -0
- package/lib/mcp/browser/tools/network.js +49 -0
- package/lib/mcp/browser/tools/pdf.js +59 -0
- package/lib/mcp/browser/tools/screenshot.js +95 -0
- package/lib/mcp/browser/tools/script.js +60 -0
- package/lib/mcp/browser/tools/snapshot.js +183 -0
- package/lib/mcp/browser/tools/tabs.js +71 -0
- package/lib/mcp/browser/tools/tool.js +49 -0
- package/lib/mcp/browser/tools/tracing.js +74 -0
- package/lib/mcp/browser/tools/utils.js +96 -0
- package/lib/mcp/browser/tools/verify.js +155 -0
- package/lib/mcp/browser/tools/wait.js +64 -0
- package/lib/mcp/browser/tools.js +79 -0
- package/lib/mcp/browser/watchdog.js +44 -0
- package/lib/mcp/sdk/bundle.js +75 -0
- package/lib/mcp/sdk/exports.js +32 -0
- package/lib/mcp/sdk/http.js +165 -0
- package/lib/mcp/sdk/inProcessTransport.js +71 -0
- package/lib/mcp/sdk/mdb.js +208 -0
- package/lib/mcp/sdk/proxyBackend.js +128 -0
- package/lib/mcp/sdk/server.js +155 -0
- package/lib/mcp/sdk/tool.js +46 -0
- package/lib/server.d.ts +8 -0
- package/lib/server.d.ts.map +1 -0
- package/lib/server.js +27 -0
- package/lib/server.js.map +1 -0
- package/package.json +10 -4
|
@@ -0,0 +1,301 @@
|
|
|
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 tab_exports = {};
|
|
20
|
+
__export(tab_exports, {
|
|
21
|
+
Tab: () => Tab,
|
|
22
|
+
TabEvents: () => TabEvents,
|
|
23
|
+
renderModalStates: () => renderModalStates
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(tab_exports);
|
|
26
|
+
var import_events = require("events");
|
|
27
|
+
var import_utils = require("playwright-core/lib/utils");
|
|
28
|
+
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
29
|
+
var import_utils2 = require("./tools/utils");
|
|
30
|
+
var import_log = require("../log");
|
|
31
|
+
const TabEvents = {
|
|
32
|
+
modalState: "modalState"
|
|
33
|
+
};
|
|
34
|
+
class Tab extends import_events.EventEmitter {
|
|
35
|
+
constructor(context, page, onPageClose) {
|
|
36
|
+
super();
|
|
37
|
+
this._lastTitle = "about:blank";
|
|
38
|
+
this._consoleMessages = [];
|
|
39
|
+
this._recentConsoleMessages = [];
|
|
40
|
+
this._requests = /* @__PURE__ */ new Map();
|
|
41
|
+
this._modalStates = [];
|
|
42
|
+
this._downloads = [];
|
|
43
|
+
this.context = context;
|
|
44
|
+
this.page = page;
|
|
45
|
+
this._onPageClose = onPageClose;
|
|
46
|
+
page.on("console", (event) => this._handleConsoleMessage(messageToConsoleMessage(event)));
|
|
47
|
+
page.on("pageerror", (error) => this._handleConsoleMessage(pageErrorToConsoleMessage(error)));
|
|
48
|
+
page.on("request", (request) => {
|
|
49
|
+
this._requests.set(request, null);
|
|
50
|
+
if (request.frame() === page.mainFrame() && request.isNavigationRequest())
|
|
51
|
+
this._willNavigateMainFrameToNewDocument();
|
|
52
|
+
});
|
|
53
|
+
page.on("response", (response) => this._requests.set(response.request(), response));
|
|
54
|
+
page.on("close", () => this._onClose());
|
|
55
|
+
page.on("filechooser", (chooser) => {
|
|
56
|
+
this.setModalState({
|
|
57
|
+
type: "fileChooser",
|
|
58
|
+
description: "File chooser",
|
|
59
|
+
fileChooser: chooser,
|
|
60
|
+
clearedBy: "browser_file_upload"
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
page.on("dialog", (dialog) => this._dialogShown(dialog));
|
|
64
|
+
page.on("download", (download) => {
|
|
65
|
+
void this._downloadStarted(download);
|
|
66
|
+
});
|
|
67
|
+
page.setDefaultNavigationTimeout(this.context.config.timeouts.navigation);
|
|
68
|
+
page.setDefaultTimeout(this.context.config.timeouts.action);
|
|
69
|
+
page[tabSymbol] = this;
|
|
70
|
+
void this._initialize();
|
|
71
|
+
}
|
|
72
|
+
static forPage(page) {
|
|
73
|
+
return page[tabSymbol];
|
|
74
|
+
}
|
|
75
|
+
async _initialize() {
|
|
76
|
+
const messages = await this.page.consoleMessages().catch(() => []);
|
|
77
|
+
for (const message of messages)
|
|
78
|
+
this._handleConsoleMessage(messageToConsoleMessage(message));
|
|
79
|
+
const errors = await this.page.pageErrors().catch(() => []);
|
|
80
|
+
for (const error of errors)
|
|
81
|
+
this._handleConsoleMessage(pageErrorToConsoleMessage(error));
|
|
82
|
+
const requests = await this.page.requests().catch(() => []);
|
|
83
|
+
for (const request of requests) {
|
|
84
|
+
this._requests.set(request, null);
|
|
85
|
+
void request.response().catch(() => null).then((response) => {
|
|
86
|
+
if (response)
|
|
87
|
+
this._requests.set(request, response);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
modalStates() {
|
|
92
|
+
return this._modalStates;
|
|
93
|
+
}
|
|
94
|
+
setModalState(modalState) {
|
|
95
|
+
this._modalStates.push(modalState);
|
|
96
|
+
this.emit(TabEvents.modalState, modalState);
|
|
97
|
+
}
|
|
98
|
+
clearModalState(modalState) {
|
|
99
|
+
this._modalStates = this._modalStates.filter((state) => state !== modalState);
|
|
100
|
+
}
|
|
101
|
+
modalStatesMarkdown() {
|
|
102
|
+
return renderModalStates(this.context, this.modalStates());
|
|
103
|
+
}
|
|
104
|
+
_dialogShown(dialog) {
|
|
105
|
+
this.setModalState({
|
|
106
|
+
type: "dialog",
|
|
107
|
+
description: `"${dialog.type()}" dialog with message "${dialog.message()}"`,
|
|
108
|
+
dialog,
|
|
109
|
+
clearedBy: "browser_handle_dialog"
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
async _downloadStarted(download) {
|
|
113
|
+
const entry = {
|
|
114
|
+
download,
|
|
115
|
+
finished: false,
|
|
116
|
+
outputFile: await this.context.outputFile(download.suggestedFilename(), { origin: "web" })
|
|
117
|
+
};
|
|
118
|
+
this._downloads.push(entry);
|
|
119
|
+
await download.saveAs(entry.outputFile);
|
|
120
|
+
entry.finished = true;
|
|
121
|
+
}
|
|
122
|
+
_clearCollectedArtifacts() {
|
|
123
|
+
this._consoleMessages.length = 0;
|
|
124
|
+
this._recentConsoleMessages.length = 0;
|
|
125
|
+
this._requests.clear();
|
|
126
|
+
}
|
|
127
|
+
_handleConsoleMessage(message) {
|
|
128
|
+
this._consoleMessages.push(message);
|
|
129
|
+
this._recentConsoleMessages.push(message);
|
|
130
|
+
}
|
|
131
|
+
_onClose() {
|
|
132
|
+
this._clearCollectedArtifacts();
|
|
133
|
+
this._onPageClose(this);
|
|
134
|
+
}
|
|
135
|
+
_willNavigateMainFrameToNewDocument() {
|
|
136
|
+
this._lastAriaSnapshot = void 0;
|
|
137
|
+
}
|
|
138
|
+
async updateTitle() {
|
|
139
|
+
await this._raceAgainstModalStates(async () => {
|
|
140
|
+
this._lastTitle = await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.title());
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
lastTitle() {
|
|
144
|
+
return this._lastTitle;
|
|
145
|
+
}
|
|
146
|
+
isCurrentTab() {
|
|
147
|
+
return this === this.context.currentTab();
|
|
148
|
+
}
|
|
149
|
+
async waitForLoadState(state, options) {
|
|
150
|
+
await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForLoadState(state, options).catch(import_log.logUnhandledError));
|
|
151
|
+
}
|
|
152
|
+
async navigate(url) {
|
|
153
|
+
this._clearCollectedArtifacts();
|
|
154
|
+
this._willNavigateMainFrameToNewDocument();
|
|
155
|
+
const downloadEvent = (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForEvent("download").catch(import_log.logUnhandledError));
|
|
156
|
+
try {
|
|
157
|
+
await this.page.goto(url, { waitUntil: "domcontentloaded" });
|
|
158
|
+
} catch (_e) {
|
|
159
|
+
const e = _e;
|
|
160
|
+
const mightBeDownload = e.message.includes("net::ERR_ABORTED") || e.message.includes("Download is starting");
|
|
161
|
+
if (!mightBeDownload)
|
|
162
|
+
throw e;
|
|
163
|
+
const download = await Promise.race([
|
|
164
|
+
downloadEvent,
|
|
165
|
+
new Promise((resolve) => setTimeout(resolve, 3e3))
|
|
166
|
+
]);
|
|
167
|
+
if (!download)
|
|
168
|
+
throw e;
|
|
169
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
await this.waitForLoadState("load", { timeout: 5e3 });
|
|
173
|
+
}
|
|
174
|
+
consoleMessages() {
|
|
175
|
+
return this._consoleMessages;
|
|
176
|
+
}
|
|
177
|
+
requests() {
|
|
178
|
+
return this._requests;
|
|
179
|
+
}
|
|
180
|
+
async captureSnapshot() {
|
|
181
|
+
let tabSnapshot;
|
|
182
|
+
const modalStates = await this._raceAgainstModalStates(async () => {
|
|
183
|
+
const snapshot = await this.page._snapshotForAI();
|
|
184
|
+
tabSnapshot = {
|
|
185
|
+
url: this.page.url(),
|
|
186
|
+
title: await this.page.title(),
|
|
187
|
+
ariaSnapshot: snapshot,
|
|
188
|
+
formattedAriaSnapshotDiff: this._lastAriaSnapshot ? generateAriaSnapshotDiff(this._lastAriaSnapshot, snapshot) : void 0,
|
|
189
|
+
modalStates: [],
|
|
190
|
+
consoleMessages: [],
|
|
191
|
+
downloads: this._downloads
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
if (tabSnapshot) {
|
|
195
|
+
tabSnapshot.consoleMessages = this._recentConsoleMessages;
|
|
196
|
+
this._recentConsoleMessages = [];
|
|
197
|
+
this._lastAriaSnapshot = tabSnapshot.ariaSnapshot;
|
|
198
|
+
}
|
|
199
|
+
return tabSnapshot ?? {
|
|
200
|
+
url: this.page.url(),
|
|
201
|
+
title: "",
|
|
202
|
+
ariaSnapshot: "",
|
|
203
|
+
modalStates,
|
|
204
|
+
consoleMessages: [],
|
|
205
|
+
downloads: []
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
_javaScriptBlocked() {
|
|
209
|
+
return this._modalStates.some((state) => state.type === "dialog");
|
|
210
|
+
}
|
|
211
|
+
async _raceAgainstModalStates(action) {
|
|
212
|
+
if (this.modalStates().length)
|
|
213
|
+
return this.modalStates();
|
|
214
|
+
const promise = new import_utils.ManualPromise();
|
|
215
|
+
const listener = (modalState) => promise.resolve([modalState]);
|
|
216
|
+
this.once(TabEvents.modalState, listener);
|
|
217
|
+
return await Promise.race([
|
|
218
|
+
action().then(() => {
|
|
219
|
+
this.off(TabEvents.modalState, listener);
|
|
220
|
+
return [];
|
|
221
|
+
}),
|
|
222
|
+
promise
|
|
223
|
+
]);
|
|
224
|
+
}
|
|
225
|
+
async waitForCompletion(callback) {
|
|
226
|
+
await this._raceAgainstModalStates(() => (0, import_utils2.waitForCompletion)(this, callback));
|
|
227
|
+
}
|
|
228
|
+
async refLocator(params) {
|
|
229
|
+
return (await this.refLocators([params]))[0];
|
|
230
|
+
}
|
|
231
|
+
async refLocators(params) {
|
|
232
|
+
const snapshot = await this.page._snapshotForAI();
|
|
233
|
+
return params.map((param) => {
|
|
234
|
+
if (!snapshot.includes(`[ref=${param.ref}]`))
|
|
235
|
+
throw new Error(`Ref ${param.ref} not found in the current page snapshot. Try capturing new snapshot.`);
|
|
236
|
+
return this.page.locator(`aria-ref=${param.ref}`).describe(param.element);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
async waitForTimeout(time) {
|
|
240
|
+
if (this._javaScriptBlocked()) {
|
|
241
|
+
await new Promise((f) => setTimeout(f, time));
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => {
|
|
245
|
+
return page.evaluate(() => new Promise((f) => setTimeout(f, 1e3)));
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function messageToConsoleMessage(message) {
|
|
250
|
+
return {
|
|
251
|
+
type: message.type(),
|
|
252
|
+
text: message.text(),
|
|
253
|
+
toString: () => `[${message.type().toUpperCase()}] ${message.text()} @ ${message.location().url}:${message.location().lineNumber}`
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function pageErrorToConsoleMessage(errorOrValue) {
|
|
257
|
+
if (errorOrValue instanceof Error) {
|
|
258
|
+
return {
|
|
259
|
+
type: void 0,
|
|
260
|
+
text: errorOrValue.message,
|
|
261
|
+
toString: () => errorOrValue.stack || errorOrValue.message
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
type: void 0,
|
|
266
|
+
text: String(errorOrValue),
|
|
267
|
+
toString: () => String(errorOrValue)
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
function renderModalStates(context, modalStates) {
|
|
271
|
+
const result = ["### Modal state"];
|
|
272
|
+
if (modalStates.length === 0)
|
|
273
|
+
result.push("- There is no modal state present");
|
|
274
|
+
for (const state of modalStates)
|
|
275
|
+
result.push(`- [${state.description}]: can be handled by the "${state.clearedBy}" tool`);
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
278
|
+
const tabSymbol = Symbol("tabSymbol");
|
|
279
|
+
function generateAriaSnapshotDiff(oldSnapshot, newSnapshot) {
|
|
280
|
+
const diffs = (0, import_utils.diffAriaSnapshots)(import_utilsBundle.yaml, oldSnapshot, newSnapshot);
|
|
281
|
+
if (diffs === "equal")
|
|
282
|
+
return "<no changes>";
|
|
283
|
+
if (diffs === "different")
|
|
284
|
+
return;
|
|
285
|
+
if (diffs.length > 3 || diffs.some((diff) => diff.newSource.split("\n").length > 100)) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const lines = [`The following refs have changed`];
|
|
289
|
+
for (const diff of diffs)
|
|
290
|
+
lines.push("", "```yaml", diff.newSource.trimEnd(), "```");
|
|
291
|
+
const combined = lines.join("\n");
|
|
292
|
+
if (combined.length >= newSnapshot.length)
|
|
293
|
+
return;
|
|
294
|
+
return combined;
|
|
295
|
+
}
|
|
296
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
297
|
+
0 && (module.exports = {
|
|
298
|
+
Tab,
|
|
299
|
+
TabEvents,
|
|
300
|
+
renderModalStates
|
|
301
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
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 common_exports = {};
|
|
20
|
+
__export(common_exports, {
|
|
21
|
+
baseSchema: () => baseSchema,
|
|
22
|
+
default: () => common_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(common_exports);
|
|
25
|
+
var import_bundle = require("../../sdk/bundle");
|
|
26
|
+
var import_tool = require("./tool");
|
|
27
|
+
const baseSchema = import_bundle.z.object({
|
|
28
|
+
toolText: import_bundle.z.string().describe("A human-readable description of the action to perform by the tool.")
|
|
29
|
+
});
|
|
30
|
+
const close = (0, import_tool.defineTool)({
|
|
31
|
+
capability: "core",
|
|
32
|
+
schema: {
|
|
33
|
+
name: "browser_close",
|
|
34
|
+
title: "Close browser",
|
|
35
|
+
description: "Close the page",
|
|
36
|
+
inputSchema: baseSchema.extend({}),
|
|
37
|
+
type: "readOnly"
|
|
38
|
+
},
|
|
39
|
+
handle: async (context, params, response) => {
|
|
40
|
+
await context.closeBrowserContext();
|
|
41
|
+
response.setIncludeTabs();
|
|
42
|
+
response.addCode(`await page.close()`);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const resize = (0, import_tool.defineTabTool)({
|
|
46
|
+
capability: "core",
|
|
47
|
+
schema: {
|
|
48
|
+
name: "browser_resize",
|
|
49
|
+
title: "Resize browser window",
|
|
50
|
+
description: "Resize the browser window",
|
|
51
|
+
inputSchema: baseSchema.extend({
|
|
52
|
+
width: import_bundle.z.number().describe("Width of the browser window"),
|
|
53
|
+
height: import_bundle.z.number().describe("Height of the browser window")
|
|
54
|
+
}),
|
|
55
|
+
type: "readOnly"
|
|
56
|
+
},
|
|
57
|
+
handle: async (tab, params, response) => {
|
|
58
|
+
response.addCode(`await page.setViewportSize({ width: ${params.width}, height: ${params.height} });`);
|
|
59
|
+
await tab.waitForCompletion(async () => {
|
|
60
|
+
await tab.page.setViewportSize({ width: params.width, height: params.height });
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
var common_default = [
|
|
65
|
+
close,
|
|
66
|
+
resize
|
|
67
|
+
];
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
baseSchema
|
|
71
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
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 console_exports = {};
|
|
20
|
+
__export(console_exports, {
|
|
21
|
+
default: () => console_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(console_exports);
|
|
24
|
+
var import_bundle = require("../../sdk/bundle");
|
|
25
|
+
var import_tool = require("./tool");
|
|
26
|
+
const console = (0, import_tool.defineTabTool)({
|
|
27
|
+
capability: "core",
|
|
28
|
+
schema: {
|
|
29
|
+
name: "browser_console_messages",
|
|
30
|
+
title: "Get console messages",
|
|
31
|
+
description: "Returns all console messages",
|
|
32
|
+
inputSchema: import_bundle.z.object({}),
|
|
33
|
+
type: "readOnly"
|
|
34
|
+
},
|
|
35
|
+
handle: async (tab, params, response) => {
|
|
36
|
+
tab.consoleMessages().map((message) => response.addResult(message.toString()));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
var console_default = [
|
|
40
|
+
console
|
|
41
|
+
];
|
|
@@ -0,0 +1,61 @@
|
|
|
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 dialogs_exports = {};
|
|
20
|
+
__export(dialogs_exports, {
|
|
21
|
+
default: () => dialogs_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(dialogs_exports);
|
|
24
|
+
var import_bundle = require("../../sdk/bundle");
|
|
25
|
+
var import_common = require("./common");
|
|
26
|
+
var import_tool = require("./tool");
|
|
27
|
+
const handleDialog = (0, import_tool.defineTabTool)({
|
|
28
|
+
capability: "core",
|
|
29
|
+
schema: {
|
|
30
|
+
name: "browser_handle_dialog",
|
|
31
|
+
title: "Handle a dialog",
|
|
32
|
+
description: "Handle a dialog",
|
|
33
|
+
inputSchema: import_common.baseSchema.extend({
|
|
34
|
+
accept: import_bundle.z.boolean().describe("Whether to accept the dialog."),
|
|
35
|
+
promptText: import_bundle.z.string().optional().describe("The text of the prompt in case of a prompt dialog.")
|
|
36
|
+
}),
|
|
37
|
+
type: "destructive"
|
|
38
|
+
},
|
|
39
|
+
handle: async (tab, params, response) => {
|
|
40
|
+
response.setIncludeSnapshot();
|
|
41
|
+
const dialogState = tab.modalStates().find((state) => state.type === "dialog");
|
|
42
|
+
if (!dialogState)
|
|
43
|
+
throw new Error("No dialog visible");
|
|
44
|
+
tab.clearModalState(dialogState);
|
|
45
|
+
await tab.waitForCompletion(async () => {
|
|
46
|
+
if (params.accept) {
|
|
47
|
+
if (params.promptText)
|
|
48
|
+
response.addCode(`await page.on('dialog', dialog => dialog.accept(${JSON.stringify(params.promptText)}));`);
|
|
49
|
+
else
|
|
50
|
+
response.addCode(`await page.on('dialog', dialog => dialog.accept());`);
|
|
51
|
+
await dialogState.dialog.accept(params.promptText);
|
|
52
|
+
} else {
|
|
53
|
+
await dialogState.dialog.dismiss();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
clearsModalState: "dialog"
|
|
58
|
+
});
|
|
59
|
+
var dialogs_default = [
|
|
60
|
+
handleDialog
|
|
61
|
+
];
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var evaluate_exports = {};
|
|
30
|
+
__export(evaluate_exports, {
|
|
31
|
+
default: () => evaluate_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(evaluate_exports);
|
|
34
|
+
var import_bundle = require("../../sdk/bundle");
|
|
35
|
+
var import_tool = require("./tool");
|
|
36
|
+
var javascript = __toESM(require("../codegen"));
|
|
37
|
+
var import_utils = require("./utils");
|
|
38
|
+
var import_common = require("./common");
|
|
39
|
+
const evaluateSchema = import_common.baseSchema.extend({
|
|
40
|
+
function: import_bundle.z.string().describe("() => { /* code */ } or (element) => { /* code */ } when element is provided"),
|
|
41
|
+
element: import_bundle.z.string().optional().describe("Human-readable element description used to obtain permission to interact with the element"),
|
|
42
|
+
ref: import_bundle.z.string().optional().describe("Exact target element reference from the page snapshot")
|
|
43
|
+
});
|
|
44
|
+
const evaluate = (0, import_tool.defineTabTool)({
|
|
45
|
+
capability: "core",
|
|
46
|
+
schema: {
|
|
47
|
+
name: "browser_evaluate",
|
|
48
|
+
title: "Evaluate JavaScript",
|
|
49
|
+
description: "Evaluate JavaScript expression on page or element",
|
|
50
|
+
inputSchema: evaluateSchema,
|
|
51
|
+
type: "destructive"
|
|
52
|
+
},
|
|
53
|
+
handle: async (tab, params, response) => {
|
|
54
|
+
response.setIncludeSnapshot();
|
|
55
|
+
let locator;
|
|
56
|
+
if (params.ref && params.element) {
|
|
57
|
+
locator = await tab.refLocator({ ref: params.ref, element: params.element });
|
|
58
|
+
response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.evaluate(${javascript.quote(params.function)});`);
|
|
59
|
+
} else {
|
|
60
|
+
response.addCode(`await page.evaluate(${javascript.quote(params.function)});`);
|
|
61
|
+
}
|
|
62
|
+
await tab.waitForCompletion(async () => {
|
|
63
|
+
const receiver = locator ?? tab.page;
|
|
64
|
+
const result = await receiver._evaluateFunction(params.function);
|
|
65
|
+
response.addResult(JSON.stringify(result, null, 2) || "undefined");
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
var evaluate_default = [
|
|
70
|
+
evaluate
|
|
71
|
+
];
|
|
@@ -0,0 +1,54 @@
|
|
|
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 files_exports = {};
|
|
20
|
+
__export(files_exports, {
|
|
21
|
+
default: () => files_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(files_exports);
|
|
24
|
+
var import_bundle = require("../../sdk/bundle");
|
|
25
|
+
var import_common = require("./common");
|
|
26
|
+
var import_tool = require("./tool");
|
|
27
|
+
const uploadFile = (0, import_tool.defineTabTool)({
|
|
28
|
+
capability: "core",
|
|
29
|
+
schema: {
|
|
30
|
+
name: "browser_file_upload",
|
|
31
|
+
title: "Upload files",
|
|
32
|
+
description: "Upload one or multiple files",
|
|
33
|
+
inputSchema: import_common.baseSchema.extend({
|
|
34
|
+
paths: import_bundle.z.array(import_bundle.z.string()).optional().describe("The absolute paths to the files to upload. Can be single file or multiple files. If omitted, file chooser is cancelled.")
|
|
35
|
+
}),
|
|
36
|
+
type: "destructive"
|
|
37
|
+
},
|
|
38
|
+
handle: async (tab, params, response) => {
|
|
39
|
+
response.setIncludeSnapshot();
|
|
40
|
+
const modalState = tab.modalStates().find((state) => state.type === "fileChooser");
|
|
41
|
+
if (!modalState)
|
|
42
|
+
throw new Error("No file chooser visible");
|
|
43
|
+
response.addCode(`await fileChooser.setFiles(${JSON.stringify(params.paths)})`);
|
|
44
|
+
tab.clearModalState(modalState);
|
|
45
|
+
await tab.waitForCompletion(async () => {
|
|
46
|
+
if (params.paths)
|
|
47
|
+
await modalState.fileChooser.setFiles(params.paths);
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
clearsModalState: "fileChooser"
|
|
51
|
+
});
|
|
52
|
+
var files_default = [
|
|
53
|
+
uploadFile
|
|
54
|
+
];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var form_exports = {};
|
|
30
|
+
__export(form_exports, {
|
|
31
|
+
default: () => form_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(form_exports);
|
|
34
|
+
var import_bundle = require("../../sdk/bundle");
|
|
35
|
+
var import_tool = require("./tool");
|
|
36
|
+
var import_utils = require("./utils");
|
|
37
|
+
var codegen = __toESM(require("../codegen"));
|
|
38
|
+
var import_common = require("./common");
|
|
39
|
+
const fillForm = (0, import_tool.defineTabTool)({
|
|
40
|
+
capability: "core",
|
|
41
|
+
schema: {
|
|
42
|
+
name: "browser_fill_form",
|
|
43
|
+
title: "Fill form",
|
|
44
|
+
description: "Fill multiple form fields",
|
|
45
|
+
inputSchema: import_common.baseSchema.extend({
|
|
46
|
+
fields: import_bundle.z.array(import_bundle.z.object({
|
|
47
|
+
name: import_bundle.z.string().describe("Human-readable field name"),
|
|
48
|
+
type: import_bundle.z.enum(["textbox", "checkbox", "radio", "combobox", "slider"]).describe("Type of the field"),
|
|
49
|
+
ref: import_bundle.z.string().describe("Exact target field reference from the page snapshot"),
|
|
50
|
+
value: import_bundle.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.")
|
|
51
|
+
})).describe("Fields to fill in")
|
|
52
|
+
}),
|
|
53
|
+
type: "destructive"
|
|
54
|
+
},
|
|
55
|
+
handle: async (tab, params, response) => {
|
|
56
|
+
for (const field of params.fields) {
|
|
57
|
+
const locator = await tab.refLocator({ element: field.name, ref: field.ref });
|
|
58
|
+
const locatorSource = `await page.${await (0, import_utils.generateLocator)(locator)}`;
|
|
59
|
+
if (field.type === "textbox" || field.type === "slider") {
|
|
60
|
+
const secret = tab.context.lookupSecret(field.value);
|
|
61
|
+
await locator.fill(secret.value);
|
|
62
|
+
response.addCode(`${locatorSource}.fill(${secret.code});`);
|
|
63
|
+
} else if (field.type === "checkbox" || field.type === "radio") {
|
|
64
|
+
await locator.setChecked(field.value === "true");
|
|
65
|
+
response.addCode(`${locatorSource}.setChecked(${field.value});`);
|
|
66
|
+
} else if (field.type === "combobox") {
|
|
67
|
+
await locator.selectOption({ label: field.value });
|
|
68
|
+
response.addCode(`${locatorSource}.selectOption(${codegen.quote(field.value)});`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
var form_default = [
|
|
74
|
+
fillForm
|
|
75
|
+
];
|