playwright 1.56.0-alpha-2025-09-03 → 1.56.0-alpha-1756945786000

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.
Files changed (59) hide show
  1. package/README.md +2 -2
  2. package/ThirdPartyNotices.txt +3 -3
  3. package/lib/index.js +2 -2
  4. package/lib/matchers/toBeTruthy.js +3 -3
  5. package/lib/matchers/toEqual.js +3 -3
  6. package/lib/matchers/toMatchText.js +3 -3
  7. package/lib/mcp/browser/actions.d.js +16 -0
  8. package/lib/mcp/browser/browserContextFactory.js +227 -0
  9. package/lib/mcp/browser/browserServerBackend.js +82 -0
  10. package/lib/mcp/browser/codegen.js +64 -0
  11. package/lib/mcp/browser/config.js +279 -0
  12. package/lib/mcp/browser/context.js +229 -0
  13. package/lib/mcp/browser/response.js +163 -0
  14. package/lib/mcp/browser/sessionLog.js +160 -0
  15. package/lib/mcp/browser/tab.js +256 -0
  16. package/lib/mcp/browser/tools/common.js +63 -0
  17. package/lib/mcp/browser/tools/console.js +41 -0
  18. package/lib/mcp/browser/tools/dialogs.js +55 -0
  19. package/lib/mcp/browser/tools/evaluate.js +70 -0
  20. package/lib/mcp/browser/tools/files.js +52 -0
  21. package/lib/mcp/browser/tools/form.js +73 -0
  22. package/lib/mcp/browser/tools/install.js +69 -0
  23. package/lib/mcp/browser/tools/keyboard.js +95 -0
  24. package/lib/mcp/browser/tools/mouse.js +107 -0
  25. package/lib/mcp/browser/tools/navigate.js +62 -0
  26. package/lib/mcp/browser/tools/network.js +49 -0
  27. package/lib/mcp/{sdk/call.js → browser/tools/pdf.js} +27 -18
  28. package/lib/mcp/browser/tools/screenshot.js +94 -0
  29. package/lib/mcp/browser/tools/snapshot.js +162 -0
  30. package/lib/mcp/browser/tools/tabs.js +67 -0
  31. package/lib/mcp/browser/tools/tool.js +49 -0
  32. package/lib/mcp/browser/tools/utils.js +90 -0
  33. package/lib/mcp/browser/tools/verify.js +154 -0
  34. package/lib/mcp/browser/tools/wait.js +63 -0
  35. package/lib/mcp/browser/tools.js +42 -83
  36. package/lib/mcp/config.d.js +16 -0
  37. package/lib/mcp/extension/cdpRelay.js +348 -0
  38. package/lib/mcp/extension/extensionContextFactory.js +75 -0
  39. package/lib/mcp/{browser/tool.js → extension/protocol.js} +6 -8
  40. package/lib/mcp/index.js +61 -0
  41. package/lib/mcp/log.js +35 -0
  42. package/lib/mcp/program.js +96 -0
  43. package/lib/mcp/sdk/bundle.js +11 -1
  44. package/lib/mcp/sdk/exports.js +2 -2
  45. package/lib/mcp/sdk/http.js +21 -6
  46. package/lib/mcp/sdk/mdb.js +16 -15
  47. package/lib/mcp/sdk/proxyBackend.js +7 -6
  48. package/lib/mcp/sdk/server.js +6 -6
  49. package/lib/mcp/sdk/tool.js +1 -1
  50. package/lib/mcp/{browser/backend.js → test/browserBackend.js} +7 -9
  51. package/lib/mcp/test/browserTool.js +30 -0
  52. package/lib/mcp/test/browserTools.js +120 -0
  53. package/lib/mcp/test/{backend.js → testBackend.js} +12 -12
  54. package/lib/mcp/test/{context.js → testContext.js} +6 -6
  55. package/lib/mcp/test/{tool.js → testTool.js} +6 -6
  56. package/lib/mcp/test/{tools.js → testTools.js} +7 -7
  57. package/lib/mcpBundleImpl.js +11 -11
  58. package/lib/program.js +4 -4
  59. package/package.json +6 -3
@@ -0,0 +1,160 @@
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 sessionLog_exports = {};
30
+ __export(sessionLog_exports, {
31
+ SessionLog: () => SessionLog
32
+ });
33
+ module.exports = __toCommonJS(sessionLog_exports);
34
+ var import_fs = __toESM(require("fs"));
35
+ var import_path = __toESM(require("path"));
36
+ var import_log = require("../log");
37
+ var import_config = require("./config");
38
+ class SessionLog {
39
+ constructor(sessionFolder) {
40
+ this._ordinal = 0;
41
+ this._pendingEntries = [];
42
+ this._sessionFileQueue = Promise.resolve();
43
+ this._folder = sessionFolder;
44
+ this._file = import_path.default.join(this._folder, "session.md");
45
+ }
46
+ static async create(config, rootPath) {
47
+ const sessionFolder = await (0, import_config.outputFile)(config, rootPath, `session-${Date.now()}`);
48
+ await import_fs.default.promises.mkdir(sessionFolder, { recursive: true });
49
+ console.error(`Session: ${sessionFolder}`);
50
+ return new SessionLog(sessionFolder);
51
+ }
52
+ logResponse(response) {
53
+ const entry = {
54
+ timestamp: performance.now(),
55
+ toolCall: {
56
+ toolName: response.toolName,
57
+ toolArgs: response.toolArgs,
58
+ result: response.result(),
59
+ isError: response.isError()
60
+ },
61
+ code: response.code(),
62
+ tabSnapshot: response.tabSnapshot()
63
+ };
64
+ this._appendEntry(entry);
65
+ }
66
+ logUserAction(action, tab, code, isUpdate) {
67
+ code = code.trim();
68
+ if (isUpdate) {
69
+ const lastEntry = this._pendingEntries[this._pendingEntries.length - 1];
70
+ if (lastEntry.userAction?.name === action.name) {
71
+ lastEntry.userAction = action;
72
+ lastEntry.code = code;
73
+ return;
74
+ }
75
+ }
76
+ if (action.name === "navigate") {
77
+ const lastEntry = this._pendingEntries[this._pendingEntries.length - 1];
78
+ if (lastEntry?.tabSnapshot?.url === action.url)
79
+ return;
80
+ }
81
+ const entry = {
82
+ timestamp: performance.now(),
83
+ userAction: action,
84
+ code,
85
+ tabSnapshot: {
86
+ url: tab.page.url(),
87
+ title: "",
88
+ ariaSnapshot: action.ariaSnapshot || "",
89
+ modalStates: [],
90
+ consoleMessages: [],
91
+ downloads: []
92
+ }
93
+ };
94
+ this._appendEntry(entry);
95
+ }
96
+ _appendEntry(entry) {
97
+ this._pendingEntries.push(entry);
98
+ if (this._flushEntriesTimeout)
99
+ clearTimeout(this._flushEntriesTimeout);
100
+ this._flushEntriesTimeout = setTimeout(() => this._flushEntries(), 1e3);
101
+ }
102
+ async _flushEntries() {
103
+ clearTimeout(this._flushEntriesTimeout);
104
+ const entries = this._pendingEntries;
105
+ this._pendingEntries = [];
106
+ const lines = [""];
107
+ for (const entry of entries) {
108
+ const ordinal = (++this._ordinal).toString().padStart(3, "0");
109
+ if (entry.toolCall) {
110
+ lines.push(
111
+ `### Tool call: ${entry.toolCall.toolName}`,
112
+ `- Args`,
113
+ "```json",
114
+ JSON.stringify(entry.toolCall.toolArgs, null, 2),
115
+ "```"
116
+ );
117
+ if (entry.toolCall.result) {
118
+ lines.push(
119
+ entry.toolCall.isError ? `- Error` : `- Result`,
120
+ "```",
121
+ entry.toolCall.result,
122
+ "```"
123
+ );
124
+ }
125
+ }
126
+ if (entry.userAction) {
127
+ const actionData = { ...entry.userAction };
128
+ delete actionData.ariaSnapshot;
129
+ delete actionData.selector;
130
+ delete actionData.signals;
131
+ lines.push(
132
+ `### User action: ${entry.userAction.name}`,
133
+ `- Args`,
134
+ "```json",
135
+ JSON.stringify(actionData, null, 2),
136
+ "```"
137
+ );
138
+ }
139
+ if (entry.code) {
140
+ lines.push(
141
+ `- Code`,
142
+ "```js",
143
+ entry.code,
144
+ "```"
145
+ );
146
+ }
147
+ if (entry.tabSnapshot) {
148
+ const fileName = `${ordinal}.snapshot.yml`;
149
+ import_fs.default.promises.writeFile(import_path.default.join(this._folder, fileName), entry.tabSnapshot.ariaSnapshot).catch(import_log.logUnhandledError);
150
+ lines.push(`- Snapshot: ${fileName}`);
151
+ }
152
+ lines.push("", "");
153
+ }
154
+ this._sessionFileQueue = this._sessionFileQueue.then(() => import_fs.default.promises.appendFile(this._file, lines.join("\n")));
155
+ }
156
+ }
157
+ // Annotate the CommonJS export names for ESM import in node:
158
+ 0 && (module.exports = {
159
+ SessionLog
160
+ });
@@ -0,0 +1,256 @@
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_utils2 = require("./tools/utils");
29
+ var import_log = require("../log");
30
+ const TabEvents = {
31
+ modalState: "modalState"
32
+ };
33
+ class Tab extends import_events.EventEmitter {
34
+ constructor(context, page, onPageClose) {
35
+ super();
36
+ this._lastTitle = "about:blank";
37
+ this._consoleMessages = [];
38
+ this._recentConsoleMessages = [];
39
+ this._requests = /* @__PURE__ */ new Map();
40
+ this._modalStates = [];
41
+ this._downloads = [];
42
+ this.context = context;
43
+ this.page = page;
44
+ this._onPageClose = onPageClose;
45
+ page.on("console", (event) => this._handleConsoleMessage(messageToConsoleMessage(event)));
46
+ page.on("pageerror", (error) => this._handleConsoleMessage(pageErrorToConsoleMessage(error)));
47
+ page.on("request", (request) => this._requests.set(request, null));
48
+ page.on("response", (response) => this._requests.set(response.request(), response));
49
+ page.on("close", () => this._onClose());
50
+ page.on("filechooser", (chooser) => {
51
+ this.setModalState({
52
+ type: "fileChooser",
53
+ description: "File chooser",
54
+ fileChooser: chooser
55
+ });
56
+ });
57
+ page.on("dialog", (dialog) => this._dialogShown(dialog));
58
+ page.on("download", (download) => {
59
+ void this._downloadStarted(download);
60
+ });
61
+ page.setDefaultNavigationTimeout(6e4);
62
+ page.setDefaultTimeout(5e3);
63
+ page[tabSymbol] = this;
64
+ }
65
+ static forPage(page) {
66
+ return page[tabSymbol];
67
+ }
68
+ modalStates() {
69
+ return this._modalStates;
70
+ }
71
+ setModalState(modalState) {
72
+ this._modalStates.push(modalState);
73
+ this.emit(TabEvents.modalState, modalState);
74
+ }
75
+ clearModalState(modalState) {
76
+ this._modalStates = this._modalStates.filter((state) => state !== modalState);
77
+ }
78
+ modalStatesMarkdown() {
79
+ return renderModalStates(this.context, this.modalStates());
80
+ }
81
+ _dialogShown(dialog) {
82
+ this.setModalState({
83
+ type: "dialog",
84
+ description: `"${dialog.type()}" dialog with message "${dialog.message()}"`,
85
+ dialog
86
+ });
87
+ }
88
+ async _downloadStarted(download) {
89
+ const entry = {
90
+ download,
91
+ finished: false,
92
+ outputFile: await this.context.outputFile(download.suggestedFilename())
93
+ };
94
+ this._downloads.push(entry);
95
+ await download.saveAs(entry.outputFile);
96
+ entry.finished = true;
97
+ }
98
+ _clearCollectedArtifacts() {
99
+ this._consoleMessages.length = 0;
100
+ this._recentConsoleMessages.length = 0;
101
+ this._requests.clear();
102
+ }
103
+ _handleConsoleMessage(message) {
104
+ this._consoleMessages.push(message);
105
+ this._recentConsoleMessages.push(message);
106
+ }
107
+ _onClose() {
108
+ this._clearCollectedArtifacts();
109
+ this._onPageClose(this);
110
+ }
111
+ async updateTitle() {
112
+ await this._raceAgainstModalStates(async () => {
113
+ this._lastTitle = await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.title());
114
+ });
115
+ }
116
+ lastTitle() {
117
+ return this._lastTitle;
118
+ }
119
+ isCurrentTab() {
120
+ return this === this.context.currentTab();
121
+ }
122
+ async waitForLoadState(state, options) {
123
+ await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForLoadState(state, options).catch(import_log.logUnhandledError));
124
+ }
125
+ async navigate(url) {
126
+ this._clearCollectedArtifacts();
127
+ const downloadEvent = (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForEvent("download").catch(import_log.logUnhandledError));
128
+ try {
129
+ await this.page.goto(url, { waitUntil: "domcontentloaded" });
130
+ } catch (_e) {
131
+ const e = _e;
132
+ const mightBeDownload = e.message.includes("net::ERR_ABORTED") || e.message.includes("Download is starting");
133
+ if (!mightBeDownload)
134
+ throw e;
135
+ const download = await Promise.race([
136
+ downloadEvent,
137
+ new Promise((resolve) => setTimeout(resolve, 3e3))
138
+ ]);
139
+ if (!download)
140
+ throw e;
141
+ await new Promise((resolve) => setTimeout(resolve, 500));
142
+ return;
143
+ }
144
+ await this.waitForLoadState("load", { timeout: 5e3 });
145
+ }
146
+ consoleMessages() {
147
+ return this._consoleMessages;
148
+ }
149
+ requests() {
150
+ return this._requests;
151
+ }
152
+ async captureSnapshot() {
153
+ let tabSnapshot;
154
+ const modalStates = await this._raceAgainstModalStates(async () => {
155
+ const snapshot = await this.page._snapshotForAI();
156
+ tabSnapshot = {
157
+ url: this.page.url(),
158
+ title: await this.page.title(),
159
+ ariaSnapshot: snapshot,
160
+ modalStates: [],
161
+ consoleMessages: [],
162
+ downloads: this._downloads
163
+ };
164
+ });
165
+ if (tabSnapshot) {
166
+ tabSnapshot.consoleMessages = this._recentConsoleMessages;
167
+ this._recentConsoleMessages = [];
168
+ }
169
+ return tabSnapshot ?? {
170
+ url: this.page.url(),
171
+ title: "",
172
+ ariaSnapshot: "",
173
+ modalStates,
174
+ consoleMessages: [],
175
+ downloads: []
176
+ };
177
+ }
178
+ _javaScriptBlocked() {
179
+ return this._modalStates.some((state) => state.type === "dialog");
180
+ }
181
+ async _raceAgainstModalStates(action) {
182
+ if (this.modalStates().length)
183
+ return this.modalStates();
184
+ const promise = new import_utils.ManualPromise();
185
+ const listener = (modalState) => promise.resolve([modalState]);
186
+ this.once(TabEvents.modalState, listener);
187
+ return await Promise.race([
188
+ action().then(() => {
189
+ this.off(TabEvents.modalState, listener);
190
+ return [];
191
+ }),
192
+ promise
193
+ ]);
194
+ }
195
+ async waitForCompletion(callback) {
196
+ await this._raceAgainstModalStates(() => (0, import_utils2.waitForCompletion)(this, callback));
197
+ }
198
+ async refLocator(params) {
199
+ return (await this.refLocators([params]))[0];
200
+ }
201
+ async refLocators(params) {
202
+ const snapshot = await this.page._snapshotForAI();
203
+ return params.map((param) => {
204
+ if (!snapshot.includes(`[ref=${param.ref}]`))
205
+ throw new Error(`Ref ${param.ref} not found in the current page snapshot. Try capturing new snapshot.`);
206
+ return this.page.locator(`aria-ref=${param.ref}`).describe(param.element);
207
+ });
208
+ }
209
+ async waitForTimeout(time) {
210
+ if (this._javaScriptBlocked()) {
211
+ await new Promise((f) => setTimeout(f, time));
212
+ return;
213
+ }
214
+ await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => {
215
+ return page.evaluate(() => new Promise((f) => setTimeout(f, 1e3)));
216
+ });
217
+ }
218
+ }
219
+ function messageToConsoleMessage(message) {
220
+ return {
221
+ type: message.type(),
222
+ text: message.text(),
223
+ toString: () => `[${message.type().toUpperCase()}] ${message.text()} @ ${message.location().url}:${message.location().lineNumber}`
224
+ };
225
+ }
226
+ function pageErrorToConsoleMessage(errorOrValue) {
227
+ if (errorOrValue instanceof Error) {
228
+ return {
229
+ type: void 0,
230
+ text: errorOrValue.message,
231
+ toString: () => errorOrValue.stack || errorOrValue.message
232
+ };
233
+ }
234
+ return {
235
+ type: void 0,
236
+ text: String(errorOrValue),
237
+ toString: () => String(errorOrValue)
238
+ };
239
+ }
240
+ function renderModalStates(context, modalStates) {
241
+ const result = ["### Modal state"];
242
+ if (modalStates.length === 0)
243
+ result.push("- There is no modal state present");
244
+ for (const state of modalStates) {
245
+ const tool = context.tools.filter((tool2) => "clearsModalState" in tool2).find((tool2) => tool2.clearsModalState === state.type);
246
+ result.push(`- [${state.description}]: can be handled by the "${tool?.schema.name}" tool`);
247
+ }
248
+ return result;
249
+ }
250
+ const tabSymbol = Symbol("tabSymbol");
251
+ // Annotate the CommonJS export names for ESM import in node:
252
+ 0 && (module.exports = {
253
+ Tab,
254
+ TabEvents,
255
+ renderModalStates
256
+ });
@@ -0,0 +1,63 @@
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
+ default: () => common_default
22
+ });
23
+ module.exports = __toCommonJS(common_exports);
24
+ var import_bundle = require("../../sdk/bundle");
25
+ var import_tool = require("./tool");
26
+ const close = (0, import_tool.defineTool)({
27
+ capability: "core",
28
+ schema: {
29
+ name: "browser_close",
30
+ title: "Close browser",
31
+ description: "Close the page",
32
+ inputSchema: import_bundle.z.object({}),
33
+ type: "readOnly"
34
+ },
35
+ handle: async (context, params, response) => {
36
+ await context.closeBrowserContext();
37
+ response.setIncludeTabs();
38
+ response.addCode(`await page.close()`);
39
+ }
40
+ });
41
+ const resize = (0, import_tool.defineTabTool)({
42
+ capability: "core",
43
+ schema: {
44
+ name: "browser_resize",
45
+ title: "Resize browser window",
46
+ description: "Resize the browser window",
47
+ inputSchema: import_bundle.z.object({
48
+ width: import_bundle.z.number().describe("Width of the browser window"),
49
+ height: import_bundle.z.number().describe("Height of the browser window")
50
+ }),
51
+ type: "readOnly"
52
+ },
53
+ handle: async (tab, params, response) => {
54
+ response.addCode(`await page.setViewportSize({ width: ${params.width}, height: ${params.height} });`);
55
+ await tab.waitForCompletion(async () => {
56
+ await tab.page.setViewportSize({ width: params.width, height: params.height });
57
+ });
58
+ }
59
+ });
60
+ var common_default = [
61
+ close,
62
+ resize
63
+ ];
@@ -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,55 @@
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_tool = require("./tool");
26
+ const handleDialog = (0, import_tool.defineTabTool)({
27
+ capability: "core",
28
+ schema: {
29
+ name: "browser_handle_dialog",
30
+ title: "Handle a dialog",
31
+ description: "Handle a dialog",
32
+ inputSchema: import_bundle.z.object({
33
+ accept: import_bundle.z.boolean().describe("Whether to accept the dialog."),
34
+ promptText: import_bundle.z.string().optional().describe("The text of the prompt in case of a prompt dialog.")
35
+ }),
36
+ type: "destructive"
37
+ },
38
+ handle: async (tab, params, response) => {
39
+ response.setIncludeSnapshot();
40
+ const dialogState = tab.modalStates().find((state) => state.type === "dialog");
41
+ if (!dialogState)
42
+ throw new Error("No dialog visible");
43
+ tab.clearModalState(dialogState);
44
+ await tab.waitForCompletion(async () => {
45
+ if (params.accept)
46
+ await dialogState.dialog.accept(params.promptText);
47
+ else
48
+ await dialogState.dialog.dismiss();
49
+ });
50
+ },
51
+ clearsModalState: "dialog"
52
+ });
53
+ var dialogs_default = [
54
+ handleDialog
55
+ ];
@@ -0,0 +1,70 @@
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
+ const evaluateSchema = import_bundle.z.object({
39
+ function: import_bundle.z.string().describe("() => { /* code */ } or (element) => { /* code */ } when element is provided"),
40
+ element: import_bundle.z.string().optional().describe("Human-readable element description used to obtain permission to interact with the element"),
41
+ ref: import_bundle.z.string().optional().describe("Exact target element reference from the page snapshot")
42
+ });
43
+ const evaluate = (0, import_tool.defineTabTool)({
44
+ capability: "core",
45
+ schema: {
46
+ name: "browser_evaluate",
47
+ title: "Evaluate JavaScript",
48
+ description: "Evaluate JavaScript expression on page or element",
49
+ inputSchema: evaluateSchema,
50
+ type: "destructive"
51
+ },
52
+ handle: async (tab, params, response) => {
53
+ response.setIncludeSnapshot();
54
+ let locator;
55
+ if (params.ref && params.element) {
56
+ locator = await tab.refLocator({ ref: params.ref, element: params.element });
57
+ response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.evaluate(${javascript.quote(params.function)});`);
58
+ } else {
59
+ response.addCode(`await page.evaluate(${javascript.quote(params.function)});`);
60
+ }
61
+ await tab.waitForCompletion(async () => {
62
+ const receiver = locator ?? tab.page;
63
+ const result = await receiver._evaluateFunction(params.function);
64
+ response.addResult(JSON.stringify(result, null, 2) || "undefined");
65
+ });
66
+ }
67
+ });
68
+ var evaluate_default = [
69
+ evaluate
70
+ ];