@playwright/mcp 0.0.36-alpha-2025-09-03 → 0.0.36-alpha-2025-09-04
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +1 -1
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/lib/{browserContextFactory.js → browser/browserContextFactory.js} +76 -36
- package/lib/{browserServerBackend.js → browser/browserServerBackend.js} +24 -22
- package/lib/{utils → browser}/codegen.js +8 -3
- package/lib/{config.js → browser/config.js} +43 -26
- package/lib/{context.js → browser/context.js} +27 -30
- package/lib/{response.js → browser/response.js} +14 -14
- package/lib/{sessionLog.js → browser/sessionLog.js} +23 -18
- package/lib/{tab.js → browser/tab.js} +29 -27
- package/lib/{tools → browser/tools}/common.js +11 -9
- package/lib/{tools → browser/tools}/console.js +7 -5
- package/lib/{tools → browser/tools}/dialogs.js +9 -7
- package/lib/browser/tools/evaluate.js +88 -0
- package/lib/{tools → browser/tools}/files.js +8 -6
- package/lib/browser/tools/form.js +92 -0
- package/lib/{tools → browser/tools}/install.js +18 -14
- package/lib/browser/tools/keyboard.js +113 -0
- package/lib/{tools → browser/tools}/mouse.js +18 -16
- package/lib/{tools → browser/tools}/navigate.js +10 -8
- package/lib/{tools → browser/tools}/network.js +7 -5
- package/lib/browser/tools/pdf.js +76 -0
- package/lib/browser/tools/screenshot.js +115 -0
- package/lib/browser/tools/snapshot.js +175 -0
- package/lib/{tools → browser/tools}/tabs.js +9 -7
- package/lib/{tools → browser/tools}/tool.js +6 -2
- package/lib/{tools → browser/tools}/utils.js +10 -5
- package/lib/{tools → browser/tools}/verify.js +59 -24
- package/lib/{tools → browser/tools}/wait.js +10 -8
- package/lib/browser/tools.js +61 -0
- package/lib/extension/cdpRelay.js +85 -48
- package/lib/extension/extensionContextFactory.js +48 -11
- package/lib/extension/protocol.js +4 -1
- package/lib/index.js +47 -12
- package/lib/{utils/log.js → log.js} +11 -4
- package/lib/{utils/package.js → package.js} +9 -5
- package/lib/program.js +68 -39
- package/lib/sdk/bundle.js +79 -0
- package/lib/{mcp → sdk}/http.js +57 -17
- package/lib/{mcp → sdk}/inProcessTransport.js +15 -20
- package/lib/{mcp → sdk}/manualPromise.js +11 -9
- package/lib/{mcp → sdk}/mdb.js +77 -38
- package/lib/{mcp → sdk}/proxyBackend.js +53 -16
- package/lib/sdk/server.js +164 -0
- package/lib/{mcp → sdk}/tool.js +8 -4
- package/lib/vscode/host.js +64 -35
- package/lib/vscode/main.js +48 -13
- package/package.json +6 -7
- package/lib/loop/loop.js +0 -69
- package/lib/loop/loopClaude.js +0 -152
- package/lib/loop/loopOpenAI.js +0 -141
- package/lib/loop/main.js +0 -60
- package/lib/loopTools/context.js +0 -67
- package/lib/loopTools/main.js +0 -54
- package/lib/loopTools/perform.js +0 -32
- package/lib/loopTools/snapshot.js +0 -29
- package/lib/loopTools/tool.js +0 -18
- package/lib/mcp/server.js +0 -123
- package/lib/tools/evaluate.js +0 -53
- package/lib/tools/form.js +0 -57
- package/lib/tools/keyboard.js +0 -78
- package/lib/tools/pdf.js +0 -40
- package/lib/tools/screenshot.js +0 -79
- package/lib/tools/snapshot.js +0 -139
- package/lib/tools.js +0 -54
- package/lib/utils/fileUtils.js +0 -36
- package/lib/utils/guid.js +0 -22
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,19 +14,16 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
_images = [];
|
|
21
|
-
_context;
|
|
22
|
-
_includeSnapshot = false;
|
|
23
|
-
_includeTabs = false;
|
|
24
|
-
_tabSnapshot;
|
|
25
|
-
toolName;
|
|
26
|
-
toolArgs;
|
|
27
|
-
_isError;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.Response = void 0;
|
|
19
|
+
const tab_1 = require("./tab");
|
|
20
|
+
class Response {
|
|
28
21
|
constructor(context, toolName, toolArgs) {
|
|
22
|
+
this._result = [];
|
|
23
|
+
this._code = [];
|
|
24
|
+
this._images = [];
|
|
25
|
+
this._includeSnapshot = false;
|
|
26
|
+
this._includeTabs = false;
|
|
29
27
|
this._context = context;
|
|
30
28
|
this.toolName = toolName;
|
|
31
29
|
this.toolArgs = toolArgs;
|
|
@@ -73,6 +71,7 @@ export class Response {
|
|
|
73
71
|
return this._tabSnapshot;
|
|
74
72
|
}
|
|
75
73
|
serialize() {
|
|
74
|
+
var _a;
|
|
76
75
|
const response = [];
|
|
77
76
|
// Start with command result.
|
|
78
77
|
if (this._result.length) {
|
|
@@ -92,8 +91,8 @@ ${this._code.join('\n')}
|
|
|
92
91
|
if (this._includeSnapshot || this._includeTabs)
|
|
93
92
|
response.push(...renderTabsMarkdown(this._context.tabs(), this._includeTabs));
|
|
94
93
|
// Add snapshot if provided.
|
|
95
|
-
if (this._tabSnapshot
|
|
96
|
-
response.push(...renderModalStates(this._context, this._tabSnapshot.modalStates));
|
|
94
|
+
if ((_a = this._tabSnapshot) === null || _a === void 0 ? void 0 : _a.modalStates.length) {
|
|
95
|
+
response.push(...(0, tab_1.renderModalStates)(this._context, this._tabSnapshot.modalStates));
|
|
97
96
|
response.push('');
|
|
98
97
|
}
|
|
99
98
|
else if (this._tabSnapshot) {
|
|
@@ -112,6 +111,7 @@ ${this._code.join('\n')}
|
|
|
112
111
|
return { content, isError: this._isError };
|
|
113
112
|
}
|
|
114
113
|
}
|
|
114
|
+
exports.Response = Response;
|
|
115
115
|
function renderTabSnapshot(tabSnapshot) {
|
|
116
116
|
const lines = [];
|
|
117
117
|
if (tabSnapshot.consoleMessages.length) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,24 +14,26 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
_flushEntriesTimeout;
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.SessionLog = void 0;
|
|
22
|
+
const fs_1 = __importDefault(require("fs"));
|
|
23
|
+
const path_1 = __importDefault(require("path"));
|
|
24
|
+
const log_1 = require("../log");
|
|
25
|
+
const config_1 = require("./config");
|
|
26
|
+
class SessionLog {
|
|
27
27
|
constructor(sessionFolder) {
|
|
28
|
+
this._ordinal = 0;
|
|
29
|
+
this._pendingEntries = [];
|
|
30
|
+
this._sessionFileQueue = Promise.resolve();
|
|
28
31
|
this._folder = sessionFolder;
|
|
29
|
-
this._file =
|
|
32
|
+
this._file = path_1.default.join(this._folder, 'session.md');
|
|
30
33
|
}
|
|
31
34
|
static async create(config, rootPath) {
|
|
32
|
-
const sessionFolder = await outputFile(config, rootPath, `session-${Date.now()}`);
|
|
33
|
-
await
|
|
35
|
+
const sessionFolder = await (0, config_1.outputFile)(config, rootPath, `session-${Date.now()}`);
|
|
36
|
+
await fs_1.default.promises.mkdir(sessionFolder, { recursive: true });
|
|
34
37
|
// eslint-disable-next-line no-console
|
|
35
38
|
console.error(`Session: ${sessionFolder}`);
|
|
36
39
|
return new SessionLog(sessionFolder);
|
|
@@ -50,10 +53,11 @@ export class SessionLog {
|
|
|
50
53
|
this._appendEntry(entry);
|
|
51
54
|
}
|
|
52
55
|
logUserAction(action, tab, code, isUpdate) {
|
|
56
|
+
var _a, _b;
|
|
53
57
|
code = code.trim();
|
|
54
58
|
if (isUpdate) {
|
|
55
59
|
const lastEntry = this._pendingEntries[this._pendingEntries.length - 1];
|
|
56
|
-
if (lastEntry.userAction
|
|
60
|
+
if (((_a = lastEntry.userAction) === null || _a === void 0 ? void 0 : _a.name) === action.name) {
|
|
57
61
|
lastEntry.userAction = action;
|
|
58
62
|
lastEntry.code = code;
|
|
59
63
|
return;
|
|
@@ -62,7 +66,7 @@ export class SessionLog {
|
|
|
62
66
|
if (action.name === 'navigate') {
|
|
63
67
|
// Already logged at this location.
|
|
64
68
|
const lastEntry = this._pendingEntries[this._pendingEntries.length - 1];
|
|
65
|
-
if (lastEntry
|
|
69
|
+
if (((_b = lastEntry === null || lastEntry === void 0 ? void 0 : lastEntry.tabSnapshot) === null || _b === void 0 ? void 0 : _b.url) === action.url)
|
|
66
70
|
return;
|
|
67
71
|
}
|
|
68
72
|
const entry = {
|
|
@@ -111,11 +115,12 @@ export class SessionLog {
|
|
|
111
115
|
}
|
|
112
116
|
if (entry.tabSnapshot) {
|
|
113
117
|
const fileName = `${ordinal}.snapshot.yml`;
|
|
114
|
-
|
|
118
|
+
fs_1.default.promises.writeFile(path_1.default.join(this._folder, fileName), entry.tabSnapshot.ariaSnapshot).catch(log_1.logUnhandledError);
|
|
115
119
|
lines.push(`- Snapshot: ${fileName}`);
|
|
116
120
|
}
|
|
117
121
|
lines.push('', '');
|
|
118
122
|
}
|
|
119
|
-
this._sessionFileQueue = this._sessionFileQueue.then(() =>
|
|
123
|
+
this._sessionFileQueue = this._sessionFileQueue.then(() => fs_1.default.promises.appendFile(this._file, lines.join('\n')));
|
|
120
124
|
}
|
|
121
125
|
}
|
|
126
|
+
exports.SessionLog = SessionLog;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,25 +14,25 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.Tab = exports.TabEvents = void 0;
|
|
19
|
+
exports.renderModalStates = renderModalStates;
|
|
20
|
+
const events_1 = require("events");
|
|
21
|
+
const utils_1 = require("./tools/utils");
|
|
22
|
+
const log_1 = require("../log");
|
|
23
|
+
const manualPromise_1 = require("../sdk/manualPromise");
|
|
24
|
+
exports.TabEvents = {
|
|
21
25
|
modalState: 'modalState'
|
|
22
26
|
};
|
|
23
|
-
|
|
24
|
-
context;
|
|
25
|
-
page;
|
|
26
|
-
_lastTitle = 'about:blank';
|
|
27
|
-
_consoleMessages = [];
|
|
28
|
-
_recentConsoleMessages = [];
|
|
29
|
-
_requests = new Map();
|
|
30
|
-
_onPageClose;
|
|
31
|
-
_modalStates = [];
|
|
32
|
-
_downloads = [];
|
|
27
|
+
class Tab extends events_1.EventEmitter {
|
|
33
28
|
constructor(context, page, onPageClose) {
|
|
34
29
|
super();
|
|
30
|
+
this._lastTitle = 'about:blank';
|
|
31
|
+
this._consoleMessages = [];
|
|
32
|
+
this._recentConsoleMessages = [];
|
|
33
|
+
this._requests = new Map();
|
|
34
|
+
this._modalStates = [];
|
|
35
|
+
this._downloads = [];
|
|
35
36
|
this.context = context;
|
|
36
37
|
this.page = page;
|
|
37
38
|
this._onPageClose = onPageClose;
|
|
@@ -63,7 +64,7 @@ export class Tab extends EventEmitter {
|
|
|
63
64
|
}
|
|
64
65
|
setModalState(modalState) {
|
|
65
66
|
this._modalStates.push(modalState);
|
|
66
|
-
this.emit(TabEvents.modalState, modalState);
|
|
67
|
+
this.emit(exports.TabEvents.modalState, modalState);
|
|
67
68
|
}
|
|
68
69
|
clearModalState(modalState) {
|
|
69
70
|
this._modalStates = this._modalStates.filter(state => state !== modalState);
|
|
@@ -103,7 +104,7 @@ export class Tab extends EventEmitter {
|
|
|
103
104
|
}
|
|
104
105
|
async updateTitle() {
|
|
105
106
|
await this._raceAgainstModalStates(async () => {
|
|
106
|
-
this._lastTitle = await callOnPageNoTrace(this.page, page => page.title());
|
|
107
|
+
this._lastTitle = await (0, utils_1.callOnPageNoTrace)(this.page, page => page.title());
|
|
107
108
|
});
|
|
108
109
|
}
|
|
109
110
|
lastTitle() {
|
|
@@ -113,11 +114,11 @@ export class Tab extends EventEmitter {
|
|
|
113
114
|
return this === this.context.currentTab();
|
|
114
115
|
}
|
|
115
116
|
async waitForLoadState(state, options) {
|
|
116
|
-
await callOnPageNoTrace(this.page, page => page.waitForLoadState(state, options).catch(logUnhandledError));
|
|
117
|
+
await (0, utils_1.callOnPageNoTrace)(this.page, page => page.waitForLoadState(state, options).catch(log_1.logUnhandledError));
|
|
117
118
|
}
|
|
118
119
|
async navigate(url) {
|
|
119
120
|
this._clearCollectedArtifacts();
|
|
120
|
-
const downloadEvent = callOnPageNoTrace(this.page, page => page.waitForEvent('download').catch(logUnhandledError));
|
|
121
|
+
const downloadEvent = (0, utils_1.callOnPageNoTrace)(this.page, page => page.waitForEvent('download').catch(log_1.logUnhandledError));
|
|
121
122
|
try {
|
|
122
123
|
await this.page.goto(url, { waitUntil: 'domcontentloaded' });
|
|
123
124
|
}
|
|
@@ -165,7 +166,7 @@ export class Tab extends EventEmitter {
|
|
|
165
166
|
tabSnapshot.consoleMessages = this._recentConsoleMessages;
|
|
166
167
|
this._recentConsoleMessages = [];
|
|
167
168
|
}
|
|
168
|
-
return tabSnapshot
|
|
169
|
+
return tabSnapshot !== null && tabSnapshot !== void 0 ? tabSnapshot : {
|
|
169
170
|
url: this.page.url(),
|
|
170
171
|
title: '',
|
|
171
172
|
ariaSnapshot: '',
|
|
@@ -180,19 +181,19 @@ export class Tab extends EventEmitter {
|
|
|
180
181
|
async _raceAgainstModalStates(action) {
|
|
181
182
|
if (this.modalStates().length)
|
|
182
183
|
return this.modalStates();
|
|
183
|
-
const promise = new ManualPromise();
|
|
184
|
+
const promise = new manualPromise_1.ManualPromise();
|
|
184
185
|
const listener = (modalState) => promise.resolve([modalState]);
|
|
185
|
-
this.once(TabEvents.modalState, listener);
|
|
186
|
+
this.once(exports.TabEvents.modalState, listener);
|
|
186
187
|
return await Promise.race([
|
|
187
188
|
action().then(() => {
|
|
188
|
-
this.off(TabEvents.modalState, listener);
|
|
189
|
+
this.off(exports.TabEvents.modalState, listener);
|
|
189
190
|
return [];
|
|
190
191
|
}),
|
|
191
192
|
promise,
|
|
192
193
|
]);
|
|
193
194
|
}
|
|
194
195
|
async waitForCompletion(callback) {
|
|
195
|
-
await this._raceAgainstModalStates(() => waitForCompletion(this, callback));
|
|
196
|
+
await this._raceAgainstModalStates(() => (0, utils_1.waitForCompletion)(this, callback));
|
|
196
197
|
}
|
|
197
198
|
async refLocator(params) {
|
|
198
199
|
return (await this.refLocators([params]))[0];
|
|
@@ -210,11 +211,12 @@ export class Tab extends EventEmitter {
|
|
|
210
211
|
await new Promise(f => setTimeout(f, time));
|
|
211
212
|
return;
|
|
212
213
|
}
|
|
213
|
-
await callOnPageNoTrace(this.page, page => {
|
|
214
|
+
await (0, utils_1.callOnPageNoTrace)(this.page, page => {
|
|
214
215
|
return page.evaluate(() => new Promise(f => setTimeout(f, 1000)));
|
|
215
216
|
});
|
|
216
217
|
}
|
|
217
218
|
}
|
|
219
|
+
exports.Tab = Tab;
|
|
218
220
|
function messageToConsoleMessage(message) {
|
|
219
221
|
return {
|
|
220
222
|
type: message.type(),
|
|
@@ -236,13 +238,13 @@ function pageErrorToConsoleMessage(errorOrValue) {
|
|
|
236
238
|
toString: () => String(errorOrValue),
|
|
237
239
|
};
|
|
238
240
|
}
|
|
239
|
-
|
|
241
|
+
function renderModalStates(context, modalStates) {
|
|
240
242
|
const result = ['### Modal state'];
|
|
241
243
|
if (modalStates.length === 0)
|
|
242
244
|
result.push('- There is no modal state present');
|
|
243
245
|
for (const state of modalStates) {
|
|
244
246
|
const tool = context.tools.filter(tool => 'clearsModalState' in tool).find(tool => tool.clearsModalState === state.type);
|
|
245
|
-
result.push(`- [${state.description}]: can be handled by the "${tool
|
|
247
|
+
result.push(`- [${state.description}]: can be handled by the "${tool === null || tool === void 0 ? void 0 : tool.schema.name}" tool`);
|
|
246
248
|
}
|
|
247
249
|
return result;
|
|
248
250
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,15 +14,16 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const bundle_1 = require("../../sdk/bundle");
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const close = (0, tool_1.defineTool)({
|
|
19
21
|
capability: 'core',
|
|
20
22
|
schema: {
|
|
21
23
|
name: 'browser_close',
|
|
22
24
|
title: 'Close browser',
|
|
23
25
|
description: 'Close the page',
|
|
24
|
-
inputSchema: z.object({}),
|
|
26
|
+
inputSchema: bundle_1.z.object({}),
|
|
25
27
|
type: 'readOnly',
|
|
26
28
|
},
|
|
27
29
|
handle: async (context, params, response) => {
|
|
@@ -30,15 +32,15 @@ const close = defineTool({
|
|
|
30
32
|
response.addCode(`await page.close()`);
|
|
31
33
|
},
|
|
32
34
|
});
|
|
33
|
-
const resize = defineTabTool({
|
|
35
|
+
const resize = (0, tool_1.defineTabTool)({
|
|
34
36
|
capability: 'core',
|
|
35
37
|
schema: {
|
|
36
38
|
name: 'browser_resize',
|
|
37
39
|
title: 'Resize browser window',
|
|
38
40
|
description: 'Resize the browser window',
|
|
39
|
-
inputSchema: z.object({
|
|
40
|
-
width: z.number().describe('Width of the browser window'),
|
|
41
|
-
height: z.number().describe('Height of the browser window'),
|
|
41
|
+
inputSchema: bundle_1.z.object({
|
|
42
|
+
width: bundle_1.z.number().describe('Width of the browser window'),
|
|
43
|
+
height: bundle_1.z.number().describe('Height of the browser window'),
|
|
42
44
|
}),
|
|
43
45
|
type: 'readOnly',
|
|
44
46
|
},
|
|
@@ -49,7 +51,7 @@ const resize = defineTabTool({
|
|
|
49
51
|
});
|
|
50
52
|
},
|
|
51
53
|
});
|
|
52
|
-
|
|
54
|
+
exports.default = [
|
|
53
55
|
close,
|
|
54
56
|
resize
|
|
55
57
|
];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,21 +14,22 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const bundle_1 = require("../../sdk/bundle");
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const console = (0, tool_1.defineTabTool)({
|
|
19
21
|
capability: 'core',
|
|
20
22
|
schema: {
|
|
21
23
|
name: 'browser_console_messages',
|
|
22
24
|
title: 'Get console messages',
|
|
23
25
|
description: 'Returns all console messages',
|
|
24
|
-
inputSchema: z.object({}),
|
|
26
|
+
inputSchema: bundle_1.z.object({}),
|
|
25
27
|
type: 'readOnly',
|
|
26
28
|
},
|
|
27
29
|
handle: async (tab, params, response) => {
|
|
28
30
|
tab.consoleMessages().map(message => response.addResult(message.toString()));
|
|
29
31
|
},
|
|
30
32
|
});
|
|
31
|
-
|
|
33
|
+
exports.default = [
|
|
32
34
|
console,
|
|
33
35
|
];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,17 +14,18 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const bundle_1 = require("../../sdk/bundle");
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const handleDialog = (0, tool_1.defineTabTool)({
|
|
19
21
|
capability: 'core',
|
|
20
22
|
schema: {
|
|
21
23
|
name: 'browser_handle_dialog',
|
|
22
24
|
title: 'Handle a dialog',
|
|
23
25
|
description: 'Handle a dialog',
|
|
24
|
-
inputSchema: z.object({
|
|
25
|
-
accept: z.boolean().describe('Whether to accept the dialog.'),
|
|
26
|
-
promptText: z.string().optional().describe('The text of the prompt in case of a prompt dialog.'),
|
|
26
|
+
inputSchema: bundle_1.z.object({
|
|
27
|
+
accept: bundle_1.z.boolean().describe('Whether to accept the dialog.'),
|
|
28
|
+
promptText: bundle_1.z.string().optional().describe('The text of the prompt in case of a prompt dialog.'),
|
|
27
29
|
}),
|
|
28
30
|
type: 'destructive',
|
|
29
31
|
},
|
|
@@ -42,6 +44,6 @@ const handleDialog = defineTabTool({
|
|
|
42
44
|
},
|
|
43
45
|
clearsModalState: 'dialog',
|
|
44
46
|
});
|
|
45
|
-
|
|
47
|
+
exports.default = [
|
|
46
48
|
handleDialog,
|
|
47
49
|
];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
const bundle_1 = require("../../sdk/bundle");
|
|
52
|
+
const tool_1 = require("./tool");
|
|
53
|
+
const javascript = __importStar(require("../codegen"));
|
|
54
|
+
const utils_1 = require("./utils");
|
|
55
|
+
const evaluateSchema = bundle_1.z.object({
|
|
56
|
+
function: bundle_1.z.string().describe('() => { /* code */ } or (element) => { /* code */ } when element is provided'),
|
|
57
|
+
element: bundle_1.z.string().optional().describe('Human-readable element description used to obtain permission to interact with the element'),
|
|
58
|
+
ref: bundle_1.z.string().optional().describe('Exact target element reference from the page snapshot'),
|
|
59
|
+
});
|
|
60
|
+
const evaluate = (0, tool_1.defineTabTool)({
|
|
61
|
+
capability: 'core',
|
|
62
|
+
schema: {
|
|
63
|
+
name: 'browser_evaluate',
|
|
64
|
+
title: 'Evaluate JavaScript',
|
|
65
|
+
description: 'Evaluate JavaScript expression on page or element',
|
|
66
|
+
inputSchema: evaluateSchema,
|
|
67
|
+
type: 'destructive',
|
|
68
|
+
},
|
|
69
|
+
handle: async (tab, params, response) => {
|
|
70
|
+
response.setIncludeSnapshot();
|
|
71
|
+
let locator;
|
|
72
|
+
if (params.ref && params.element) {
|
|
73
|
+
locator = await tab.refLocator({ ref: params.ref, element: params.element });
|
|
74
|
+
response.addCode(`await page.${await (0, utils_1.generateLocator)(locator)}.evaluate(${javascript.quote(params.function)});`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
response.addCode(`await page.evaluate(${javascript.quote(params.function)});`);
|
|
78
|
+
}
|
|
79
|
+
await tab.waitForCompletion(async () => {
|
|
80
|
+
const receiver = locator !== null && locator !== void 0 ? locator : tab.page;
|
|
81
|
+
const result = await receiver._evaluateFunction(params.function);
|
|
82
|
+
response.addResult(JSON.stringify(result, null, 2) || 'undefined');
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
exports.default = [
|
|
87
|
+
evaluate,
|
|
88
|
+
];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,16 +14,17 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const bundle_1 = require("../../sdk/bundle");
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const uploadFile = (0, tool_1.defineTabTool)({
|
|
19
21
|
capability: 'core',
|
|
20
22
|
schema: {
|
|
21
23
|
name: 'browser_file_upload',
|
|
22
24
|
title: 'Upload files',
|
|
23
25
|
description: 'Upload one or multiple files',
|
|
24
|
-
inputSchema: z.object({
|
|
25
|
-
paths: z.array(z.string()).describe('The absolute paths to the files to upload. Can be a single file or multiple files.'),
|
|
26
|
+
inputSchema: bundle_1.z.object({
|
|
27
|
+
paths: bundle_1.z.array(bundle_1.z.string()).describe('The absolute paths to the files to upload. Can be a single file or multiple files.'),
|
|
26
28
|
}),
|
|
27
29
|
type: 'destructive',
|
|
28
30
|
},
|
|
@@ -39,6 +41,6 @@ const uploadFile = defineTabTool({
|
|
|
39
41
|
},
|
|
40
42
|
clearsModalState: 'fileChooser',
|
|
41
43
|
});
|
|
42
|
-
|
|
44
|
+
exports.default = [
|
|
43
45
|
uploadFile,
|
|
44
46
|
];
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
const bundle_1 = require("../../sdk/bundle");
|
|
52
|
+
const tool_1 = require("./tool");
|
|
53
|
+
const utils_1 = require("./utils");
|
|
54
|
+
const javascript = __importStar(require("../codegen"));
|
|
55
|
+
const fillForm = (0, tool_1.defineTabTool)({
|
|
56
|
+
capability: 'core',
|
|
57
|
+
schema: {
|
|
58
|
+
name: 'browser_fill_form',
|
|
59
|
+
title: 'Fill form',
|
|
60
|
+
description: 'Fill multiple form fields',
|
|
61
|
+
inputSchema: bundle_1.z.object({
|
|
62
|
+
fields: bundle_1.z.array(bundle_1.z.object({
|
|
63
|
+
name: bundle_1.z.string().describe('Human-readable field name'),
|
|
64
|
+
type: bundle_1.z.enum(['textbox', 'checkbox', 'radio', 'combobox', 'slider']).describe('Type of the field'),
|
|
65
|
+
ref: bundle_1.z.string().describe('Exact target field reference from the page snapshot'),
|
|
66
|
+
value: bundle_1.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.'),
|
|
67
|
+
})).describe('Fields to fill in'),
|
|
68
|
+
}),
|
|
69
|
+
type: 'destructive',
|
|
70
|
+
},
|
|
71
|
+
handle: async (tab, params, response) => {
|
|
72
|
+
for (const field of params.fields) {
|
|
73
|
+
const locator = await tab.refLocator({ element: field.name, ref: field.ref });
|
|
74
|
+
const locatorSource = `await page.${await (0, utils_1.generateLocator)(locator)}`;
|
|
75
|
+
if (field.type === 'textbox' || field.type === 'slider') {
|
|
76
|
+
await locator.fill(field.value);
|
|
77
|
+
response.addCode(`${locatorSource}.fill(${javascript.quote(field.value)});`);
|
|
78
|
+
}
|
|
79
|
+
else if (field.type === 'checkbox' || field.type === 'radio') {
|
|
80
|
+
await locator.setChecked(field.value === 'true');
|
|
81
|
+
response.addCode(`${locatorSource}.setChecked(${javascript.quote(field.value)});`);
|
|
82
|
+
}
|
|
83
|
+
else if (field.type === 'combobox') {
|
|
84
|
+
await locator.selectOption({ label: field.value });
|
|
85
|
+
response.addCode(`${locatorSource}.selectOption(${javascript.quote(field.value)});`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
exports.default = [
|
|
91
|
+
fillForm,
|
|
92
|
+
];
|