@cotestdev/mcp_playwright 0.0.1 → 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.
Files changed (54) hide show
  1. package/lib/cli.d.ts +8 -0
  2. package/lib/cli.d.ts.map +1 -0
  3. package/lib/cli.js +11 -0
  4. package/lib/cli.js.map +1 -0
  5. package/lib/index.d.ts +5 -2
  6. package/lib/index.d.ts.map +1 -1
  7. package/lib/index.js +28 -5
  8. package/lib/index.js.map +1 -1
  9. package/lib/mcp/browser/actions.d.js +16 -0
  10. package/lib/mcp/browser/browserContextFactory.js +285 -0
  11. package/lib/mcp/browser/browserServerBackend.js +74 -0
  12. package/lib/mcp/browser/codegen.js +66 -0
  13. package/lib/mcp/browser/config.js +346 -0
  14. package/lib/mcp/browser/context.js +260 -0
  15. package/lib/mcp/browser/processUtils.js +102 -0
  16. package/lib/mcp/browser/response.js +169 -0
  17. package/lib/mcp/browser/sessionLog.js +160 -0
  18. package/lib/mcp/browser/tab.js +301 -0
  19. package/lib/mcp/browser/tools/common.js +71 -0
  20. package/lib/mcp/browser/tools/console.js +41 -0
  21. package/lib/mcp/browser/tools/dialogs.js +61 -0
  22. package/lib/mcp/browser/tools/evaluate.js +71 -0
  23. package/lib/mcp/browser/tools/files.js +54 -0
  24. package/lib/mcp/browser/tools/form.js +75 -0
  25. package/lib/mcp/browser/tools/install.js +69 -0
  26. package/lib/mcp/browser/tools/keyboard.js +85 -0
  27. package/lib/mcp/browser/tools/mouse.js +107 -0
  28. package/lib/mcp/browser/tools/navigate.js +63 -0
  29. package/lib/mcp/browser/tools/network.js +49 -0
  30. package/lib/mcp/browser/tools/pdf.js +59 -0
  31. package/lib/mcp/browser/tools/screenshot.js +95 -0
  32. package/lib/mcp/browser/tools/script.js +60 -0
  33. package/lib/mcp/browser/tools/snapshot.js +183 -0
  34. package/lib/mcp/browser/tools/tabs.js +71 -0
  35. package/lib/mcp/browser/tools/tool.js +49 -0
  36. package/lib/mcp/browser/tools/tracing.js +74 -0
  37. package/lib/mcp/browser/tools/utils.js +96 -0
  38. package/lib/mcp/browser/tools/verify.js +155 -0
  39. package/lib/mcp/browser/tools/wait.js +64 -0
  40. package/lib/mcp/browser/tools.js +79 -0
  41. package/lib/mcp/browser/watchdog.js +44 -0
  42. package/lib/mcp/sdk/bundle.js +75 -0
  43. package/lib/mcp/sdk/exports.js +32 -0
  44. package/lib/mcp/sdk/http.js +165 -0
  45. package/lib/mcp/sdk/inProcessTransport.js +71 -0
  46. package/lib/mcp/sdk/mdb.js +208 -0
  47. package/lib/mcp/sdk/proxyBackend.js +128 -0
  48. package/lib/mcp/sdk/server.js +155 -0
  49. package/lib/mcp/sdk/tool.js +46 -0
  50. package/lib/server.d.ts +8 -0
  51. package/lib/server.d.ts.map +1 -0
  52. package/lib/server.js +27 -0
  53. package/lib/server.js.map +1 -0
  54. package/package.json +10 -4
@@ -0,0 +1,183 @@
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 snapshot_exports = {};
30
+ __export(snapshot_exports, {
31
+ default: () => snapshot_default,
32
+ elementSchema: () => elementSchema
33
+ });
34
+ module.exports = __toCommonJS(snapshot_exports);
35
+ var import_bundle = require("../../sdk/bundle");
36
+ var import_tool = require("./tool");
37
+ var javascript = __toESM(require("../codegen"));
38
+ var import_utils = require("./utils");
39
+ var import_common = require("./common");
40
+ const snapshot = (0, import_tool.defineTool)({
41
+ capability: "core",
42
+ schema: {
43
+ name: "browser_snapshot",
44
+ title: "Page snapshot",
45
+ description: "Capture accessibility snapshot of the current page, this is better than screenshot",
46
+ inputSchema: import_bundle.z.object({}),
47
+ type: "readOnly"
48
+ },
49
+ handle: async (context, params, response) => {
50
+ await context.ensureTab();
51
+ response.setIncludeSnapshot("full");
52
+ }
53
+ });
54
+ const elementSchema = import_common.baseSchema.extend({
55
+ element: import_bundle.z.string().describe("Human-readable element description used to obtain permission to interact with the element"),
56
+ ref: import_bundle.z.string().describe("Exact target element reference from the page snapshot")
57
+ });
58
+ const clickSchema = elementSchema.extend({
59
+ doubleClick: import_bundle.z.boolean().optional().describe("Whether to perform a double click instead of a single click"),
60
+ button: import_bundle.z.enum(["left", "right", "middle"]).optional().describe("Button to click, defaults to left"),
61
+ modifiers: import_bundle.z.array(import_bundle.z.enum(["Alt", "Control", "ControlOrMeta", "Meta", "Shift"])).optional().describe("Modifier keys to press")
62
+ });
63
+ const click = (0, import_tool.defineTabTool)({
64
+ capability: "core",
65
+ schema: {
66
+ name: "browser_click",
67
+ title: "Click",
68
+ description: "Perform click on a web page",
69
+ inputSchema: clickSchema,
70
+ type: "destructive"
71
+ },
72
+ handle: async (tab, params, response) => {
73
+ response.setIncludeSnapshot();
74
+ const locator = await tab.refLocator(params);
75
+ const options = {
76
+ button: params.button,
77
+ modifiers: params.modifiers
78
+ };
79
+ const formatted = javascript.formatObject(options, " ", "oneline");
80
+ const optionsAttr = formatted !== "{}" ? formatted : "";
81
+ if (params.doubleClick)
82
+ response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.dblclick(${optionsAttr});`);
83
+ else
84
+ response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.click(${optionsAttr});`);
85
+ await tab.waitForCompletion(async () => {
86
+ if (params.doubleClick)
87
+ await locator.dblclick(options);
88
+ else
89
+ await locator.click(options);
90
+ });
91
+ }
92
+ });
93
+ const drag = (0, import_tool.defineTabTool)({
94
+ capability: "core",
95
+ schema: {
96
+ name: "browser_drag",
97
+ title: "Drag mouse",
98
+ description: "Perform drag and drop between two elements",
99
+ inputSchema: import_bundle.z.object({
100
+ startElement: import_bundle.z.string().describe("Human-readable source element description used to obtain the permission to interact with the element"),
101
+ startRef: import_bundle.z.string().describe("Exact source element reference from the page snapshot"),
102
+ endElement: import_bundle.z.string().describe("Human-readable target element description used to obtain the permission to interact with the element"),
103
+ endRef: import_bundle.z.string().describe("Exact target element reference from the page snapshot")
104
+ }),
105
+ type: "destructive"
106
+ },
107
+ handle: async (tab, params, response) => {
108
+ response.setIncludeSnapshot();
109
+ const [startLocator, endLocator] = await tab.refLocators([
110
+ { ref: params.startRef, element: params.startElement },
111
+ { ref: params.endRef, element: params.endElement }
112
+ ]);
113
+ await tab.waitForCompletion(async () => {
114
+ await startLocator.dragTo(endLocator);
115
+ });
116
+ response.addCode(`await page.${await (0, import_utils.generateLocator)(startLocator)}.dragTo(page.${await (0, import_utils.generateLocator)(endLocator)});`);
117
+ }
118
+ });
119
+ const hover = (0, import_tool.defineTabTool)({
120
+ capability: "core",
121
+ schema: {
122
+ name: "browser_hover",
123
+ title: "Hover mouse",
124
+ description: "Hover over element on page",
125
+ inputSchema: elementSchema,
126
+ type: "readOnly"
127
+ },
128
+ handle: async (tab, params, response) => {
129
+ response.setIncludeSnapshot();
130
+ const locator = await tab.refLocator(params);
131
+ response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.hover();`);
132
+ await tab.waitForCompletion(async () => {
133
+ await locator.hover();
134
+ });
135
+ }
136
+ });
137
+ const selectOptionSchema = elementSchema.extend({
138
+ values: import_bundle.z.array(import_bundle.z.string()).describe("Array of values to select in the dropdown. This can be a single value or multiple values.")
139
+ });
140
+ const selectOption = (0, import_tool.defineTabTool)({
141
+ capability: "core",
142
+ schema: {
143
+ name: "browser_select_option",
144
+ title: "Select option",
145
+ description: "Select an option in a dropdown",
146
+ inputSchema: selectOptionSchema,
147
+ type: "destructive"
148
+ },
149
+ handle: async (tab, params, response) => {
150
+ response.setIncludeSnapshot();
151
+ const locator = await tab.refLocator(params);
152
+ response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.selectOption(${javascript.formatObject(params.values)});`);
153
+ await tab.waitForCompletion(async () => {
154
+ await locator.selectOption(params.values);
155
+ });
156
+ }
157
+ });
158
+ const pickLocator = (0, import_tool.defineTabTool)({
159
+ capability: "testing",
160
+ schema: {
161
+ name: "browser_generate_locator",
162
+ title: "Create locator for element",
163
+ description: "Generate locator for the given element to use in tests",
164
+ inputSchema: elementSchema,
165
+ type: "readOnly"
166
+ },
167
+ handle: async (tab, params, response) => {
168
+ const locator = await tab.refLocator(params);
169
+ response.addResult(await (0, import_utils.generateLocator)(locator));
170
+ }
171
+ });
172
+ var snapshot_default = [
173
+ snapshot,
174
+ click,
175
+ drag,
176
+ hover,
177
+ selectOption,
178
+ pickLocator
179
+ ];
180
+ // Annotate the CommonJS export names for ESM import in node:
181
+ 0 && (module.exports = {
182
+ elementSchema
183
+ });
@@ -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 tabs_exports = {};
20
+ __export(tabs_exports, {
21
+ default: () => tabs_default
22
+ });
23
+ module.exports = __toCommonJS(tabs_exports);
24
+ var import_bundle = require("../../sdk/bundle");
25
+ var import_common = require("./common");
26
+ var import_tool = require("./tool");
27
+ const browserTabs = (0, import_tool.defineTool)({
28
+ capability: "core-tabs",
29
+ schema: {
30
+ name: "browser_tabs",
31
+ title: "Manage tabs",
32
+ description: "List, create, close, or select a browser tab.",
33
+ inputSchema: import_common.baseSchema.extend({
34
+ action: import_bundle.z.enum(["list", "new", "close", "select"]).describe("Operation to perform"),
35
+ index: import_bundle.z.number().optional().describe("Tab index, used for close/select. If omitted for close, current tab is closed.")
36
+ }),
37
+ type: "destructive"
38
+ },
39
+ handle: async (context, params, response) => {
40
+ switch (params.action) {
41
+ case "list": {
42
+ await context.ensureTab();
43
+ response.setIncludeTabs();
44
+ return;
45
+ }
46
+ case "new": {
47
+ response.addCode(`page = await context.newPage();`);
48
+ await context.newTab();
49
+ response.setIncludeTabs();
50
+ return;
51
+ }
52
+ case "close": {
53
+ response.addCode(`await page.close();`);
54
+ await context.closeTab(params.index);
55
+ response.setIncludeSnapshot();
56
+ return;
57
+ }
58
+ case "select": {
59
+ if (params.index === void 0)
60
+ throw new Error("Tab index is required");
61
+ response.addCode(`page = pages[${params.index}];`);
62
+ await context.selectTab(params.index);
63
+ response.setIncludeSnapshot();
64
+ return;
65
+ }
66
+ }
67
+ }
68
+ });
69
+ var tabs_default = [
70
+ browserTabs
71
+ ];
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var tool_exports = {};
20
+ __export(tool_exports, {
21
+ defineTabTool: () => defineTabTool,
22
+ defineTool: () => defineTool
23
+ });
24
+ module.exports = __toCommonJS(tool_exports);
25
+ function defineTool(tool) {
26
+ return tool;
27
+ }
28
+ function defineTabTool(tool) {
29
+ return {
30
+ ...tool,
31
+ handle: async (context, params, response) => {
32
+ const tab = await context.ensureTab();
33
+ const modalStates = tab.modalStates().map((state) => state.type);
34
+ if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState))
35
+ response.addError(`Error: The tool "${tool.schema.name}" can only be used when there is related modal state present.
36
+ ` + tab.modalStatesMarkdown().join("\n"));
37
+ else if (!tool.clearsModalState && modalStates.length)
38
+ response.addError(`Error: Tool "${tool.schema.name}" does not handle the modal state.
39
+ ` + tab.modalStatesMarkdown().join("\n"));
40
+ else
41
+ return tool.handle(tab, params, response);
42
+ }
43
+ };
44
+ }
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ defineTabTool,
48
+ defineTool
49
+ });
@@ -0,0 +1,74 @@
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 tracing_exports = {};
20
+ __export(tracing_exports, {
21
+ default: () => tracing_default
22
+ });
23
+ module.exports = __toCommonJS(tracing_exports);
24
+ var import_bundle = require("../../sdk/bundle");
25
+ var import_tool = require("./tool");
26
+ const tracingStart = (0, import_tool.defineTool)({
27
+ capability: "tracing",
28
+ schema: {
29
+ name: "browser_start_tracing",
30
+ title: "Start tracing",
31
+ description: "Start trace recording",
32
+ inputSchema: import_bundle.z.object({}),
33
+ type: "readOnly"
34
+ },
35
+ handle: async (context, params, response) => {
36
+ const browserContext = await context.ensureBrowserContext();
37
+ const tracesDir = await context.outputFile(`traces`, { origin: "code" });
38
+ const name = "trace-" + Date.now();
39
+ await browserContext.tracing.start({
40
+ name,
41
+ screenshots: true,
42
+ snapshots: true,
43
+ _live: true
44
+ });
45
+ const traceLegend = `- Action log: ${tracesDir}/${name}.trace
46
+ - Network log: ${tracesDir}/${name}.network
47
+ - Resources with content by sha1: ${tracesDir}/resources`;
48
+ response.addResult(`Tracing started, saving to ${tracesDir}.
49
+ ${traceLegend}`);
50
+ browserContext.tracing[traceLegendSymbol] = traceLegend;
51
+ }
52
+ });
53
+ const tracingStop = (0, import_tool.defineTool)({
54
+ capability: "tracing",
55
+ schema: {
56
+ name: "browser_stop_tracing",
57
+ title: "Stop tracing",
58
+ description: "Stop trace recording",
59
+ inputSchema: import_bundle.z.object({}),
60
+ type: "readOnly"
61
+ },
62
+ handle: async (context, params, response) => {
63
+ const browserContext = await context.ensureBrowserContext();
64
+ await browserContext.tracing.stop();
65
+ const traceLegend = browserContext.tracing[traceLegendSymbol];
66
+ response.addResult(`Tracing stopped.
67
+ ${traceLegend}`);
68
+ }
69
+ });
70
+ var tracing_default = [
71
+ tracingStart,
72
+ tracingStop
73
+ ];
74
+ const traceLegendSymbol = Symbol("tracesDir");
@@ -0,0 +1,96 @@
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 utils_exports = {};
20
+ __export(utils_exports, {
21
+ callOnPageNoTrace: () => callOnPageNoTrace,
22
+ dateAsFileName: () => dateAsFileName,
23
+ generateLocator: () => generateLocator,
24
+ waitForCompletion: () => waitForCompletion
25
+ });
26
+ module.exports = __toCommonJS(utils_exports);
27
+ var import_utils = require("playwright-core/lib/utils");
28
+ async function waitForCompletion(tab, callback) {
29
+ const requests = /* @__PURE__ */ new Set();
30
+ let frameNavigated = false;
31
+ let waitCallback = () => {
32
+ };
33
+ const waitBarrier = new Promise((f) => {
34
+ waitCallback = f;
35
+ });
36
+ const requestListener = (request) => requests.add(request);
37
+ const requestFinishedListener = (request) => {
38
+ requests.delete(request);
39
+ if (!requests.size)
40
+ waitCallback();
41
+ };
42
+ const frameNavigateListener = (frame) => {
43
+ if (frame.parentFrame())
44
+ return;
45
+ frameNavigated = true;
46
+ dispose();
47
+ clearTimeout(timeout);
48
+ void tab.waitForLoadState("load").then(waitCallback);
49
+ };
50
+ const onTimeout = () => {
51
+ dispose();
52
+ waitCallback();
53
+ };
54
+ tab.page.on("request", requestListener);
55
+ tab.page.on("requestfinished", requestFinishedListener);
56
+ tab.page.on("framenavigated", frameNavigateListener);
57
+ const timeout = setTimeout(onTimeout, 1e4);
58
+ const dispose = () => {
59
+ tab.page.off("request", requestListener);
60
+ tab.page.off("requestfinished", requestFinishedListener);
61
+ tab.page.off("framenavigated", frameNavigateListener);
62
+ clearTimeout(timeout);
63
+ };
64
+ try {
65
+ const result = await callback();
66
+ if (!requests.size && !frameNavigated)
67
+ waitCallback();
68
+ await waitBarrier;
69
+ await tab.waitForTimeout(1e3);
70
+ return result;
71
+ } finally {
72
+ dispose();
73
+ }
74
+ }
75
+ async function generateLocator(locator) {
76
+ try {
77
+ const { resolvedSelector } = await locator._resolveSelector();
78
+ return (0, import_utils.asLocator)("javascript", resolvedSelector);
79
+ } catch (e) {
80
+ throw new Error("Ref not found, likely because element was removed. Use browser_snapshot to see what elements are currently on the page.");
81
+ }
82
+ }
83
+ async function callOnPageNoTrace(page, callback) {
84
+ return await page._wrapApiCall(() => callback(page), { internal: true });
85
+ }
86
+ function dateAsFileName() {
87
+ const date = /* @__PURE__ */ new Date();
88
+ return date.toISOString().replace(/[:.]/g, "-");
89
+ }
90
+ // Annotate the CommonJS export names for ESM import in node:
91
+ 0 && (module.exports = {
92
+ callOnPageNoTrace,
93
+ dateAsFileName,
94
+ generateLocator,
95
+ waitForCompletion
96
+ });
@@ -0,0 +1,155 @@
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 verify_exports = {};
30
+ __export(verify_exports, {
31
+ default: () => verify_default
32
+ });
33
+ module.exports = __toCommonJS(verify_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 verifyElement = (0, import_tool.defineTabTool)({
40
+ capability: "testing",
41
+ schema: {
42
+ name: "browser_verify_element_visible",
43
+ title: "Verify element visible",
44
+ description: "Verify element is visible on the page",
45
+ inputSchema: import_common.baseSchema.extend({
46
+ role: import_bundle.z.string().describe('ROLE of the element. Can be found in the snapshot like this: `- {ROLE} "Accessible Name":`'),
47
+ accessibleName: import_bundle.z.string().describe('ACCESSIBLE_NAME of the element. Can be found in the snapshot like this: `- role "{ACCESSIBLE_NAME}"`')
48
+ }),
49
+ type: "readOnly"
50
+ },
51
+ handle: async (tab, params, response) => {
52
+ const locator = tab.page.getByRole(params.role, { name: params.accessibleName });
53
+ if (await locator.count() === 0) {
54
+ response.addError(`Element with role "${params.role}" and accessible name "${params.accessibleName}" not found`);
55
+ return;
56
+ }
57
+ response.addCode(`await expect(page.getByRole(${javascript.escapeWithQuotes(params.role)}, { name: ${javascript.escapeWithQuotes(params.accessibleName)} })).toBeVisible();`);
58
+ response.addResult("Done");
59
+ }
60
+ });
61
+ const verifyText = (0, import_tool.defineTabTool)({
62
+ capability: "testing",
63
+ schema: {
64
+ name: "browser_verify_text_visible",
65
+ title: "Verify text visible",
66
+ description: `Verify text is visible on the page. Prefer ${verifyElement.schema.name} if possible.`,
67
+ inputSchema: import_common.baseSchema.extend({
68
+ text: import_bundle.z.string().describe('TEXT to verify. Can be found in the snapshot like this: `- role "Accessible Name": {TEXT}` or like this: `- text: {TEXT}`')
69
+ }),
70
+ type: "readOnly"
71
+ },
72
+ handle: async (tab, params, response) => {
73
+ const locator = tab.page.getByText(params.text).filter({ visible: true });
74
+ if (await locator.count() === 0) {
75
+ response.addError("Text not found");
76
+ return;
77
+ }
78
+ response.addCode(`await expect(page.getByText(${javascript.escapeWithQuotes(params.text)})).toBeVisible();`);
79
+ response.addResult("Done");
80
+ }
81
+ });
82
+ const verifyList = (0, import_tool.defineTabTool)({
83
+ capability: "testing",
84
+ schema: {
85
+ name: "browser_verify_list_visible",
86
+ title: "Verify list visible",
87
+ description: "Verify list is visible on the page",
88
+ inputSchema: import_common.baseSchema.extend({
89
+ element: import_bundle.z.string().describe("Human-readable list description"),
90
+ ref: import_bundle.z.string().describe("Exact target element reference that points to the list"),
91
+ items: import_bundle.z.array(import_bundle.z.string()).describe("Items to verify")
92
+ }),
93
+ type: "readOnly"
94
+ },
95
+ handle: async (tab, params, response) => {
96
+ const locator = await tab.refLocator({ ref: params.ref, element: params.element });
97
+ const itemTexts = [];
98
+ for (const item of params.items) {
99
+ const itemLocator = locator.getByText(item);
100
+ if (await itemLocator.count() === 0) {
101
+ response.addError(`Item "${item}" not found`);
102
+ return;
103
+ }
104
+ itemTexts.push(await itemLocator.textContent());
105
+ }
106
+ const ariaSnapshot = `\`
107
+ - list:
108
+ ${itemTexts.map((t) => ` - listitem: ${javascript.escapeWithQuotes(t, '"')}`).join("\n")}
109
+ \``;
110
+ response.addCode(`await expect(page.locator('body')).toMatchAriaSnapshot(${ariaSnapshot});`);
111
+ response.addResult("Done");
112
+ }
113
+ });
114
+ const verifyValue = (0, import_tool.defineTabTool)({
115
+ capability: "testing",
116
+ schema: {
117
+ name: "browser_verify_value",
118
+ title: "Verify value",
119
+ description: "Verify element value",
120
+ inputSchema: import_common.baseSchema.extend({
121
+ type: import_bundle.z.enum(["textbox", "checkbox", "radio", "combobox", "slider"]).describe("Type of the element"),
122
+ element: import_bundle.z.string().describe("Human-readable element description"),
123
+ ref: import_bundle.z.string().describe("Exact target element reference that points to the element"),
124
+ value: import_bundle.z.string().describe('Value to verify. For checkbox, use "true" or "false".')
125
+ }),
126
+ type: "readOnly"
127
+ },
128
+ handle: async (tab, params, response) => {
129
+ const locator = await tab.refLocator({ ref: params.ref, element: params.element });
130
+ const locatorSource = `page.${await (0, import_utils.generateLocator)(locator)}`;
131
+ if (params.type === "textbox" || params.type === "slider" || params.type === "combobox") {
132
+ const value = await locator.inputValue();
133
+ if (value !== params.value) {
134
+ response.addError(`Expected value "${params.value}", but got "${value}"`);
135
+ return;
136
+ }
137
+ response.addCode(`await expect(${locatorSource}).toHaveValue(${javascript.quote(params.value)});`);
138
+ } else if (params.type === "checkbox" || params.type === "radio") {
139
+ const value = await locator.isChecked();
140
+ if (value !== (params.value === "true")) {
141
+ response.addError(`Expected value "${params.value}", but got "${value}"`);
142
+ return;
143
+ }
144
+ const matcher = value ? "toBeChecked" : "not.toBeChecked";
145
+ response.addCode(`await expect(${locatorSource}).${matcher}();`);
146
+ }
147
+ response.addResult("Done");
148
+ }
149
+ });
150
+ var verify_default = [
151
+ verifyElement,
152
+ verifyText,
153
+ verifyList,
154
+ verifyValue
155
+ ];