@playwright/mcp 0.0.36-alpha-2025-09-04 → 0.0.37-alpha-2025-09-08

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 (50) hide show
  1. package/README.md +81 -46
  2. package/cli.js +7 -1
  3. package/config.d.ts +24 -0
  4. package/index.js +1 -1
  5. package/package.json +14 -39
  6. package/lib/browser/browserContextFactory.js +0 -251
  7. package/lib/browser/browserServerBackend.js +0 -79
  8. package/lib/browser/codegen.js +0 -54
  9. package/lib/browser/config.js +0 -263
  10. package/lib/browser/context.js +0 -223
  11. package/lib/browser/response.js +0 -165
  12. package/lib/browser/sessionLog.js +0 -126
  13. package/lib/browser/tab.js +0 -251
  14. package/lib/browser/tools/common.js +0 -57
  15. package/lib/browser/tools/console.js +0 -35
  16. package/lib/browser/tools/dialogs.js +0 -49
  17. package/lib/browser/tools/evaluate.js +0 -88
  18. package/lib/browser/tools/files.js +0 -46
  19. package/lib/browser/tools/form.js +0 -92
  20. package/lib/browser/tools/install.js +0 -57
  21. package/lib/browser/tools/keyboard.js +0 -113
  22. package/lib/browser/tools/mouse.js +0 -101
  23. package/lib/browser/tools/navigate.js +0 -56
  24. package/lib/browser/tools/network.js +0 -43
  25. package/lib/browser/tools/pdf.js +0 -76
  26. package/lib/browser/tools/screenshot.js +0 -115
  27. package/lib/browser/tools/snapshot.js +0 -175
  28. package/lib/browser/tools/tabs.js +0 -61
  29. package/lib/browser/tools/tool.js +0 -37
  30. package/lib/browser/tools/utils.js +0 -79
  31. package/lib/browser/tools/verify.js +0 -172
  32. package/lib/browser/tools/wait.js +0 -57
  33. package/lib/browser/tools.js +0 -61
  34. package/lib/extension/cdpRelay.js +0 -395
  35. package/lib/extension/extensionContextFactory.js +0 -93
  36. package/lib/extension/protocol.js +0 -21
  37. package/lib/index.js +0 -75
  38. package/lib/log.js +0 -28
  39. package/lib/package.js +0 -24
  40. package/lib/program.js +0 -161
  41. package/lib/sdk/bundle.js +0 -79
  42. package/lib/sdk/http.js +0 -175
  43. package/lib/sdk/inProcessTransport.js +0 -67
  44. package/lib/sdk/manualPromise.js +0 -113
  45. package/lib/sdk/mdb.js +0 -237
  46. package/lib/sdk/proxyBackend.js +0 -141
  47. package/lib/sdk/server.js +0 -164
  48. package/lib/sdk/tool.js +0 -36
  49. package/lib/vscode/host.js +0 -199
  50. package/lib/vscode/main.js +0 -97
@@ -1,88 +0,0 @@
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,46 +0,0 @@
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
- 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)({
21
- capability: 'core',
22
- schema: {
23
- name: 'browser_file_upload',
24
- title: 'Upload files',
25
- description: 'Upload one 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.'),
28
- }),
29
- type: 'destructive',
30
- },
31
- handle: async (tab, params, response) => {
32
- response.setIncludeSnapshot();
33
- const modalState = tab.modalStates().find(state => state.type === 'fileChooser');
34
- if (!modalState)
35
- throw new Error('No file chooser visible');
36
- response.addCode(`await fileChooser.setFiles(${JSON.stringify(params.paths)})`);
37
- tab.clearModalState(modalState);
38
- await tab.waitForCompletion(async () => {
39
- await modalState.fileChooser.setFiles(params.paths);
40
- });
41
- },
42
- clearsModalState: 'fileChooser',
43
- });
44
- exports.default = [
45
- uploadFile,
46
- ];
@@ -1,92 +0,0 @@
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
- ];
@@ -1,57 +0,0 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- const child_process_1 = require("child_process");
22
- const path_1 = __importDefault(require("path"));
23
- const bundle_1 = require("../../sdk/bundle");
24
- const tool_1 = require("./tool");
25
- const install = (0, tool_1.defineTool)({
26
- capability: 'core-install',
27
- schema: {
28
- name: 'browser_install',
29
- title: 'Install the browser specified in the config',
30
- description: 'Install the browser specified in the config. Call this if you get an error about the browser not being installed.',
31
- inputSchema: bundle_1.z.object({}),
32
- type: 'destructive',
33
- },
34
- handle: async (context, params, response) => {
35
- var _a, _b, _c, _d, _e, _f, _g;
36
- const channel = (_e = (_c = (_b = (_a = context.config.browser) === null || _a === void 0 ? void 0 : _a.launchOptions) === null || _b === void 0 ? void 0 : _b.channel) !== null && _c !== void 0 ? _c : (_d = context.config.browser) === null || _d === void 0 ? void 0 : _d.browserName) !== null && _e !== void 0 ? _e : 'chrome';
37
- const cliPath = path_1.default.join(require.resolve('playwright/package.json'), '../cli.js');
38
- const child = (0, child_process_1.fork)(cliPath, ['install', channel], {
39
- stdio: 'pipe',
40
- });
41
- const output = [];
42
- (_f = child.stdout) === null || _f === void 0 ? void 0 : _f.on('data', data => output.push(data.toString()));
43
- (_g = child.stderr) === null || _g === void 0 ? void 0 : _g.on('data', data => output.push(data.toString()));
44
- await new Promise((resolve, reject) => {
45
- child.on('close', code => {
46
- if (code === 0)
47
- resolve();
48
- else
49
- reject(new Error(`Failed to install browser: ${output.join('')}`));
50
- });
51
- });
52
- response.setIncludeTabs();
53
- },
54
- });
55
- exports.default = [
56
- install,
57
- ];
@@ -1,113 +0,0 @@
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 snapshot_1 = require("./snapshot");
54
- const utils_1 = require("./utils");
55
- const javascript = __importStar(require("../codegen"));
56
- const pressKey = (0, tool_1.defineTabTool)({
57
- capability: 'core',
58
- schema: {
59
- name: 'browser_press_key',
60
- title: 'Press a key',
61
- description: 'Press a key on the keyboard',
62
- inputSchema: bundle_1.z.object({
63
- key: bundle_1.z.string().describe('Name of the key to press or a character to generate, such as `ArrowLeft` or `a`'),
64
- }),
65
- type: 'destructive',
66
- },
67
- handle: async (tab, params, response) => {
68
- response.setIncludeSnapshot();
69
- response.addCode(`// Press ${params.key}`);
70
- response.addCode(`await page.keyboard.press('${params.key}');`);
71
- await tab.waitForCompletion(async () => {
72
- await tab.page.keyboard.press(params.key);
73
- });
74
- },
75
- });
76
- const typeSchema = snapshot_1.elementSchema.extend({
77
- text: bundle_1.z.string().describe('Text to type into the element'),
78
- submit: bundle_1.z.boolean().optional().describe('Whether to submit entered text (press Enter after)'),
79
- slowly: bundle_1.z.boolean().optional().describe('Whether to type one character at a time. Useful for triggering key handlers in the page. By default entire text is filled in at once.'),
80
- });
81
- const type = (0, tool_1.defineTabTool)({
82
- capability: 'core',
83
- schema: {
84
- name: 'browser_type',
85
- title: 'Type text',
86
- description: 'Type text into editable element',
87
- inputSchema: typeSchema,
88
- type: 'destructive',
89
- },
90
- handle: async (tab, params, response) => {
91
- const locator = await tab.refLocator(params);
92
- await tab.waitForCompletion(async () => {
93
- if (params.slowly) {
94
- response.setIncludeSnapshot();
95
- response.addCode(`await page.${await (0, utils_1.generateLocator)(locator)}.pressSequentially(${javascript.quote(params.text)});`);
96
- await locator.pressSequentially(params.text);
97
- }
98
- else {
99
- response.addCode(`await page.${await (0, utils_1.generateLocator)(locator)}.fill(${javascript.quote(params.text)});`);
100
- await locator.fill(params.text);
101
- }
102
- if (params.submit) {
103
- response.setIncludeSnapshot();
104
- response.addCode(`await page.${await (0, utils_1.generateLocator)(locator)}.press('Enter');`);
105
- await locator.press('Enter');
106
- }
107
- });
108
- },
109
- });
110
- exports.default = [
111
- pressKey,
112
- type,
113
- ];
@@ -1,101 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const bundle_1 = require("../../sdk/bundle");
19
- const tool_1 = require("./tool");
20
- const elementSchema = bundle_1.z.object({
21
- element: bundle_1.z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
22
- });
23
- const mouseMove = (0, tool_1.defineTabTool)({
24
- capability: 'vision',
25
- schema: {
26
- name: 'browser_mouse_move_xy',
27
- title: 'Move mouse',
28
- description: 'Move mouse to a given position',
29
- inputSchema: elementSchema.extend({
30
- x: bundle_1.z.number().describe('X coordinate'),
31
- y: bundle_1.z.number().describe('Y coordinate'),
32
- }),
33
- type: 'readOnly',
34
- },
35
- handle: async (tab, params, response) => {
36
- response.addCode(`// Move mouse to (${params.x}, ${params.y})`);
37
- response.addCode(`await page.mouse.move(${params.x}, ${params.y});`);
38
- await tab.waitForCompletion(async () => {
39
- await tab.page.mouse.move(params.x, params.y);
40
- });
41
- },
42
- });
43
- const mouseClick = (0, tool_1.defineTabTool)({
44
- capability: 'vision',
45
- schema: {
46
- name: 'browser_mouse_click_xy',
47
- title: 'Click',
48
- description: 'Click left mouse button at a given position',
49
- inputSchema: elementSchema.extend({
50
- x: bundle_1.z.number().describe('X coordinate'),
51
- y: bundle_1.z.number().describe('Y coordinate'),
52
- }),
53
- type: 'destructive',
54
- },
55
- handle: async (tab, params, response) => {
56
- response.setIncludeSnapshot();
57
- response.addCode(`// Click mouse at coordinates (${params.x}, ${params.y})`);
58
- response.addCode(`await page.mouse.move(${params.x}, ${params.y});`);
59
- response.addCode(`await page.mouse.down();`);
60
- response.addCode(`await page.mouse.up();`);
61
- await tab.waitForCompletion(async () => {
62
- await tab.page.mouse.move(params.x, params.y);
63
- await tab.page.mouse.down();
64
- await tab.page.mouse.up();
65
- });
66
- },
67
- });
68
- const mouseDrag = (0, tool_1.defineTabTool)({
69
- capability: 'vision',
70
- schema: {
71
- name: 'browser_mouse_drag_xy',
72
- title: 'Drag mouse',
73
- description: 'Drag left mouse button to a given position',
74
- inputSchema: elementSchema.extend({
75
- startX: bundle_1.z.number().describe('Start X coordinate'),
76
- startY: bundle_1.z.number().describe('Start Y coordinate'),
77
- endX: bundle_1.z.number().describe('End X coordinate'),
78
- endY: bundle_1.z.number().describe('End Y coordinate'),
79
- }),
80
- type: 'destructive',
81
- },
82
- handle: async (tab, params, response) => {
83
- response.setIncludeSnapshot();
84
- response.addCode(`// Drag mouse from (${params.startX}, ${params.startY}) to (${params.endX}, ${params.endY})`);
85
- response.addCode(`await page.mouse.move(${params.startX}, ${params.startY});`);
86
- response.addCode(`await page.mouse.down();`);
87
- response.addCode(`await page.mouse.move(${params.endX}, ${params.endY});`);
88
- response.addCode(`await page.mouse.up();`);
89
- await tab.waitForCompletion(async () => {
90
- await tab.page.mouse.move(params.startX, params.startY);
91
- await tab.page.mouse.down();
92
- await tab.page.mouse.move(params.endX, params.endY);
93
- await tab.page.mouse.up();
94
- });
95
- },
96
- });
97
- exports.default = [
98
- mouseMove,
99
- mouseClick,
100
- mouseDrag,
101
- ];
@@ -1,56 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const bundle_1 = require("../../sdk/bundle");
19
- const tool_1 = require("./tool");
20
- const navigate = (0, tool_1.defineTool)({
21
- capability: 'core',
22
- schema: {
23
- name: 'browser_navigate',
24
- title: 'Navigate to a URL',
25
- description: 'Navigate to a URL',
26
- inputSchema: bundle_1.z.object({
27
- url: bundle_1.z.string().describe('The URL to navigate to'),
28
- }),
29
- type: 'destructive',
30
- },
31
- handle: async (context, params, response) => {
32
- const tab = await context.ensureTab();
33
- await tab.navigate(params.url);
34
- response.setIncludeSnapshot();
35
- response.addCode(`await page.goto('${params.url}');`);
36
- },
37
- });
38
- const goBack = (0, tool_1.defineTabTool)({
39
- capability: 'core',
40
- schema: {
41
- name: 'browser_navigate_back',
42
- title: 'Go back',
43
- description: 'Go back to the previous page',
44
- inputSchema: bundle_1.z.object({}),
45
- type: 'readOnly',
46
- },
47
- handle: async (tab, params, response) => {
48
- await tab.page.goBack();
49
- response.setIncludeSnapshot();
50
- response.addCode(`await page.goBack();`);
51
- },
52
- });
53
- exports.default = [
54
- navigate,
55
- goBack,
56
- ];
@@ -1,43 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const bundle_1 = require("../../sdk/bundle");
19
- const tool_1 = require("./tool");
20
- const requests = (0, tool_1.defineTabTool)({
21
- capability: 'core',
22
- schema: {
23
- name: 'browser_network_requests',
24
- title: 'List network requests',
25
- description: 'Returns all network requests since loading the page',
26
- inputSchema: bundle_1.z.object({}),
27
- type: 'readOnly',
28
- },
29
- handle: async (tab, params, response) => {
30
- const requests = tab.requests();
31
- [...requests.entries()].forEach(([req, res]) => response.addResult(renderRequest(req, res)));
32
- },
33
- });
34
- function renderRequest(request, response) {
35
- const result = [];
36
- result.push(`[${request.method().toUpperCase()}] ${request.url()}`);
37
- if (response)
38
- result.push(`=> [${response.status()}] ${response.statusText()}`);
39
- return result.join(' ');
40
- }
41
- exports.default = [
42
- requests,
43
- ];
@@ -1,76 +0,0 @@
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 pdfSchema = bundle_1.z.object({
55
- filename: bundle_1.z.string().optional().describe('File name to save the pdf to. Defaults to `page-{timestamp}.pdf` if not specified.'),
56
- });
57
- const pdf = (0, tool_1.defineTabTool)({
58
- capability: 'pdf',
59
- schema: {
60
- name: 'browser_pdf_save',
61
- title: 'Save as PDF',
62
- description: 'Save page as PDF',
63
- inputSchema: pdfSchema,
64
- type: 'readOnly',
65
- },
66
- handle: async (tab, params, response) => {
67
- var _a;
68
- const fileName = await tab.context.outputFile((_a = params.filename) !== null && _a !== void 0 ? _a : `page-${new Date().toISOString()}.pdf`);
69
- response.addCode(`await page.pdf(${javascript.formatObject({ path: fileName })});`);
70
- response.addResult(`Saved page as ${fileName}`);
71
- await tab.page.pdf({ path: fileName });
72
- },
73
- });
74
- exports.default = [
75
- pdf,
76
- ];