@cotestdev/mcp_playwright 0.0.34 → 0.0.36

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 (40) hide show
  1. package/lib/common/testType.js +1 -1
  2. package/lib/mcp/browser/browserContextFactory.js +12 -12
  3. package/lib/mcp/browser/browserServerBackend.js +24 -12
  4. package/lib/mcp/browser/config.js +37 -7
  5. package/lib/mcp/browser/context.js +17 -63
  6. package/lib/mcp/browser/response.js +183 -251
  7. package/lib/mcp/browser/sessionLog.js +19 -104
  8. package/lib/mcp/browser/tab.js +49 -28
  9. package/lib/mcp/browser/tools/common.js +4 -4
  10. package/lib/mcp/browser/tools/console.js +20 -3
  11. package/lib/mcp/browser/tools/dialogs.js +0 -1
  12. package/lib/mcp/browser/tools/evaluate.js +6 -4
  13. package/lib/mcp/browser/tools/install.js +4 -1
  14. package/lib/mcp/browser/tools/keyboard.js +75 -8
  15. package/lib/mcp/browser/tools/mouse.js +59 -7
  16. package/lib/mcp/browser/tools/navigate.js +48 -5
  17. package/lib/mcp/browser/tools/network.js +21 -3
  18. package/lib/mcp/browser/tools/pdf.js +4 -3
  19. package/lib/mcp/browser/tools/runCode.js +6 -10
  20. package/lib/mcp/browser/tools/screenshot.js +8 -26
  21. package/lib/mcp/browser/tools/snapshot.js +38 -22
  22. package/lib/mcp/browser/tools/tabs.js +8 -8
  23. package/lib/mcp/browser/tools/tool.js +3 -6
  24. package/lib/mcp/browser/tools/tracing.js +3 -3
  25. package/lib/mcp/browser/tools/utils.js +2 -2
  26. package/lib/mcp/browser/tools/verify.js +4 -4
  27. package/lib/mcp/browser/tools/wait.js +1 -1
  28. package/lib/mcp/browser/tools.js +2 -2
  29. package/lib/mcp/extension/extensionContextFactory.js +2 -2
  30. package/lib/mcp/program.js +3 -2
  31. package/lib/mcp/terminal/cli.js +4 -216
  32. package/lib/mcp/terminal/command.js +56 -0
  33. package/lib/mcp/terminal/commands.js +528 -0
  34. package/lib/mcp/terminal/daemon.js +42 -25
  35. package/lib/mcp/terminal/helpGenerator.js +152 -0
  36. package/lib/mcp/terminal/program.js +434 -0
  37. package/lib/mcp/terminal/socketConnection.js +2 -4
  38. package/lib/mcpBundleImpl/index.js +44 -44
  39. package/lib/util.js +3 -6
  40. package/package.json +3 -2
@@ -1,219 +1,7 @@
1
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 __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from))
11
- if (!__hasOwnProp.call(to, key) && key !== except)
12
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- }
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- // If the importer is in node compatibility mode or this is not an ESM
18
- // file that has been converted to a CommonJS file using a Babel-
19
- // compatible transform (i.e. "__esModule" has not been set), then set
20
- // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
- var import_child_process = require("child_process");
25
- var import_fs = __toESM(require("fs"));
26
- var import_net = __toESM(require("net"));
27
- var import_os = __toESM(require("os"));
28
- var import_path = __toESM(require("path"));
29
- var import_utilsBundle = require("playwright-core/lib/utilsBundle");
30
- var import_socketConnection = require("./socketConnection");
31
- const debugCli = (0, import_utilsBundle.debug)("pw:cli");
2
+ var import_program = require("./program");
32
3
  const packageJSON = require("../../../package.json");
33
- import_utilsBundle.program.version("Version " + (process.env.PW_CLI_DISPLAY_VERSION || packageJSON.version)).name("playwright-command");
34
- function addCommand(name, description, action) {
35
- import_utilsBundle.program.command(name).description(description).action(action);
36
- }
37
- addCommand("navigate <url>", "open url in the browser", async (url) => {
38
- await runMcpCommand("browser_navigate", { url });
4
+ (0, import_program.program)({ version: packageJSON.version }).catch((e) => {
5
+ console.error(e.message);
6
+ process.exit(1);
39
7
  });
40
- addCommand("close", "close the browser", async () => {
41
- await runMcpCommand("browser_close", {});
42
- });
43
- addCommand("click <ref>", "click an element using a ref from a snapshot, e.g. e67", async (ref) => {
44
- await runMcpCommand("browser_click", { ref });
45
- });
46
- addCommand("snapshot", "get accessible snapshot of the current page", async () => {
47
- await runMcpCommand("browser_snapshot", {});
48
- });
49
- addCommand("drag <startRef> <endRef>", "drag from one element to another", async (startRef, endRef) => {
50
- await runMcpCommand("browser_drag", { startRef, endRef });
51
- });
52
- addCommand("hover <ref>", "hover over an element", async (ref) => {
53
- await runMcpCommand("browser_hover", { ref });
54
- });
55
- addCommand("select <ref> <values...>", "select option(s) in a dropdown", async (ref, values) => {
56
- await runMcpCommand("browser_select_option", { ref, values });
57
- });
58
- addCommand("locator <ref>", "generate a locator for an element", async (ref) => {
59
- await runMcpCommand("browser_generate_locator", { ref });
60
- });
61
- addCommand("press <key>", "press a key on the keyboard", async (key) => {
62
- await runMcpCommand("browser_press_key", { key });
63
- });
64
- addCommand("type <ref> <text>", "type text into an element", async (ref, text) => {
65
- await runMcpCommand("browser_type", { ref, text });
66
- });
67
- addCommand("back", "go back to the previous page", async () => {
68
- await runMcpCommand("browser_navigate_back", {});
69
- });
70
- addCommand("wait <time>", "wait for a specified time in seconds", async (time) => {
71
- await runMcpCommand("browser_wait_for", { time: parseFloat(time) });
72
- });
73
- addCommand("wait-for-text <text>", "wait for text to appear", async (text) => {
74
- await runMcpCommand("browser_wait_for", { text });
75
- });
76
- addCommand("dialog-accept [promptText]", "accept a dialog", async (promptText) => {
77
- await runMcpCommand("browser_handle_dialog", { accept: true, promptText });
78
- });
79
- addCommand("dialog-dismiss", "dismiss a dialog", async () => {
80
- await runMcpCommand("browser_handle_dialog", { accept: false });
81
- });
82
- addCommand("screenshot [filename]", "take a screenshot of the current page", async (filename) => {
83
- await runMcpCommand("browser_take_screenshot", { filename });
84
- });
85
- addCommand("resize <width> <height>", "resize the browser window", async (width, height) => {
86
- await runMcpCommand("browser_resize", { width: parseInt(width, 10), height: parseInt(height, 10) });
87
- });
88
- addCommand("upload <paths...>", "upload files", async (paths) => {
89
- await runMcpCommand("browser_file_upload", { paths });
90
- });
91
- addCommand("tabs", "list all browser tabs", async () => {
92
- await runMcpCommand("browser_tabs", { action: "list" });
93
- });
94
- addCommand("tab-new", "create a new browser tab", async () => {
95
- await runMcpCommand("browser_tabs", { action: "new" });
96
- });
97
- addCommand("tab-close [index]", "close a browser tab", async (index) => {
98
- await runMcpCommand("browser_tabs", { action: "close", index: index !== void 0 ? parseInt(index, 10) : void 0 });
99
- });
100
- addCommand("tab-select <index>", "select a browser tab", async (index) => {
101
- await runMcpCommand("browser_tabs", { action: "select", index: parseInt(index, 10) });
102
- });
103
- async function runMcpCommand(name, args) {
104
- const session = await connectToDaemon();
105
- const result = await session.callTool(name, args);
106
- printResult(result);
107
- session.dispose();
108
- }
109
- function printResult(result) {
110
- for (const content of result.content) {
111
- if (content.type === "text")
112
- console.log(content.text);
113
- else
114
- console.log(`<${content.type} content>`);
115
- }
116
- }
117
- async function socketExists(socketPath) {
118
- try {
119
- const stat = await import_fs.default.promises.stat(socketPath);
120
- if (stat?.isSocket())
121
- return true;
122
- } catch (e) {
123
- }
124
- return false;
125
- }
126
- class SocketSession {
127
- constructor(connection) {
128
- this._nextMessageId = 1;
129
- this._callbacks = /* @__PURE__ */ new Map();
130
- this._connection = connection;
131
- this._connection.onmessage = (message) => this._onMessage(message);
132
- this._connection.onclose = () => this.dispose();
133
- }
134
- async callTool(name, args) {
135
- return this._send(name, args);
136
- }
137
- async _send(method, params = {}) {
138
- const messageId = this._nextMessageId++;
139
- const message = {
140
- id: messageId,
141
- method,
142
- params
143
- };
144
- await this._connection.send(message);
145
- return new Promise((resolve, reject) => {
146
- this._callbacks.set(messageId, { resolve, reject, error: new Error(`Error in method: ${method}`) });
147
- });
148
- }
149
- dispose() {
150
- for (const callback of this._callbacks.values())
151
- callback.reject(callback.error);
152
- this._callbacks.clear();
153
- this._connection.close();
154
- }
155
- _onMessage(object) {
156
- if (object.id && this._callbacks.has(object.id)) {
157
- const callback = this._callbacks.get(object.id);
158
- this._callbacks.delete(object.id);
159
- if (object.error) {
160
- callback.error.cause = new Error(object.error);
161
- callback.reject(callback.error);
162
- } else {
163
- callback.resolve(object.result);
164
- }
165
- } else if (object.id) {
166
- throw new Error(`Unexpected message id: ${object.id}`);
167
- } else {
168
- throw new Error(`Unexpected message without id: ${JSON.stringify(object)}`);
169
- }
170
- }
171
- }
172
- function daemonSocketPath() {
173
- if (import_os.default.platform() === "win32")
174
- return import_path.default.join("\\\\.\\pipe", "pw-daemon.sock");
175
- return import_path.default.join(import_os.default.homedir(), ".playwright", "pw-daemon.sock");
176
- }
177
- async function connectToDaemon() {
178
- const socketPath = daemonSocketPath();
179
- debugCli(`Connecting to daemon at ${socketPath}`);
180
- if (await socketExists(socketPath)) {
181
- debugCli(`Socket file exists, attempting to connect...`);
182
- try {
183
- return await connectToSocket(socketPath);
184
- } catch (e) {
185
- import_fs.default.unlinkSync(socketPath);
186
- }
187
- }
188
- const cliPath = import_path.default.join(__dirname, "../../../cli.js");
189
- debugCli(`Will launch daemon process: ${cliPath}`);
190
- const child = (0, import_child_process.spawn)(process.execPath, [cliPath, "run-mcp-server", `--daemon=${socketPath}`], {
191
- detached: true,
192
- stdio: "ignore"
193
- });
194
- child.unref();
195
- const maxRetries = 50;
196
- const retryDelay = 100;
197
- for (let i = 0; i < maxRetries; i++) {
198
- await new Promise((resolve) => setTimeout(resolve, 100));
199
- try {
200
- return await connectToSocket(socketPath);
201
- } catch (e) {
202
- if (e.code !== "ENOENT")
203
- throw e;
204
- debugCli(`Retrying to connect to daemon at ${socketPath} (${i + 1}/${maxRetries})`);
205
- }
206
- }
207
- throw new Error(`Failed to connect to daemon at ${socketPath} after ${maxRetries * retryDelay}ms`);
208
- }
209
- async function connectToSocket(socketPath) {
210
- const socket = await new Promise((resolve, reject) => {
211
- const socket2 = import_net.default.createConnection(socketPath, () => {
212
- debugCli(`Connected to daemon at ${socketPath}`);
213
- resolve(socket2);
214
- });
215
- socket2.on("error", reject);
216
- });
217
- return new SocketSession(new import_socketConnection.SocketConnection(socket));
218
- }
219
- void import_utilsBundle.program.parseAsync(process.argv);
@@ -0,0 +1,56 @@
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 command_exports = {};
20
+ __export(command_exports, {
21
+ declareCommand: () => declareCommand,
22
+ parseCommand: () => parseCommand
23
+ });
24
+ module.exports = __toCommonJS(command_exports);
25
+ function declareCommand(command) {
26
+ return command;
27
+ }
28
+ function parseCommand(command, args) {
29
+ const shape = command.args ? command.args.shape : {};
30
+ const argv = args["_"];
31
+ const options = command.options?.parse({ ...args, _: void 0 }) ?? {};
32
+ const argsObject = {};
33
+ let i = 0;
34
+ for (const name of Object.keys(shape))
35
+ argsObject[name] = argv[++i];
36
+ let parsedArgsObject = {};
37
+ try {
38
+ parsedArgsObject = command.args?.parse(argsObject) ?? {};
39
+ } catch (e) {
40
+ throw new Error(formatZodError(e));
41
+ }
42
+ const toolName = typeof command.toolName === "function" ? command.toolName({ ...parsedArgsObject, ...options }) : command.toolName;
43
+ const toolParams = command.toolParams({ ...parsedArgsObject, ...options });
44
+ return { toolName, toolParams };
45
+ }
46
+ function formatZodError(error) {
47
+ const issue = error.issues[0];
48
+ if (issue.code === "invalid_type")
49
+ return `${issue.message} in <${issue.path.join(".")}>`;
50
+ return error.issues.map((i) => i.message).join("\n");
51
+ }
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ declareCommand,
55
+ parseCommand
56
+ });