@cotestdev/mcp_playwright 0.0.58 → 0.0.59

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.
@@ -169,8 +169,8 @@ function configFromCLIOptions(cliOptions) {
169
169
  executablePath: cliOptions.executablePath,
170
170
  headless: cliOptions.headless
171
171
  };
172
- if (cliOptions.sandbox !== void 0)
173
- launchOptions.chromiumSandbox = cliOptions.sandbox;
172
+ if (cliOptions.chromiumSandbox !== void 0)
173
+ launchOptions.chromiumSandbox = cliOptions.chromiumSandbox;
174
174
  if (cliOptions.proxyServer) {
175
175
  launchOptions.proxy = {
176
176
  server: cliOptions.proxyServer
@@ -270,7 +270,7 @@ function configFromEnv() {
270
270
  options.isolated = envToBoolean(process.env.PLAYWRIGHT_MCP_ISOLATED);
271
271
  if (process.env.PLAYWRIGHT_MCP_IMAGE_RESPONSES)
272
272
  options.imageResponses = enumParser("--image-responses", ["allow", "omit"], process.env.PLAYWRIGHT_MCP_IMAGE_RESPONSES);
273
- options.sandbox = envToBoolean(process.env.PLAYWRIGHT_MCP_SANDBOX);
273
+ options.chromiumSandbox = envToBoolean(process.env.PLAYWRIGHT_MCP_CHROMIUM_SANDBOX);
274
274
  options.outputDir = envToString(process.env.PLAYWRIGHT_MCP_OUTPUT_DIR);
275
275
  options.port = numberParser(process.env.PLAYWRIGHT_MCP_PORT);
276
276
  options.proxyBypass = envToString(process.env.PLAYWRIGHT_MCP_PROXY_BYPASS);
@@ -236,8 +236,10 @@ class Context {
236
236
  const result = await this._browserContextFactory.createContext(this._clientInfo, this._abortController.signal, { toolName: this._runningToolName });
237
237
  const { browserContext } = result;
238
238
  if (!this.config.allowUnrestrictedFileAccess) {
239
- browserContext._setAllowedProtocols(["http:", "https:", "about:", "data:"]);
240
- browserContext._setAllowedDirectories(allRootPaths(this._clientInfo));
239
+ if (typeof browserContext._setAllowedProtocols === "function")
240
+ browserContext._setAllowedProtocols(["http:", "https:", "about:", "data:"]);
241
+ if (typeof browserContext._setAllowedDirectories === "function")
242
+ browserContext._setAllowedDirectories(allRootPaths(this._clientInfo));
241
243
  }
242
244
  await this._setupRequestInterception(browserContext);
243
245
  for (const page of browserContext.pages())
@@ -24,6 +24,7 @@ module.exports = __toCommonJS(common_exports);
24
24
  var import_mcpBundle = require("../../../mcpBundle");
25
25
  var import_tool = require("./tool");
26
26
  var import_response = require("../response");
27
+ var import_schema = require("./schema");
27
28
  const close = (0, import_tool.defineTool)({
28
29
  capability: "core",
29
30
  schema: {
@@ -46,7 +47,7 @@ const resize = (0, import_tool.defineTabTool)({
46
47
  name: "browser_resize",
47
48
  title: "Resize browser window",
48
49
  description: "Resize the browser window",
49
- inputSchema: import_mcpBundle.z.object({
50
+ inputSchema: import_schema.baseSchema.extend({
50
51
  width: import_mcpBundle.z.number().describe("Width of the browser window"),
51
52
  height: import_mcpBundle.z.number().describe("Height of the browser window")
52
53
  }),
@@ -0,0 +1,42 @@
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 devtools_exports = {};
20
+ __export(devtools_exports, {
21
+ default: () => devtools_default
22
+ });
23
+ module.exports = __toCommonJS(devtools_exports);
24
+ var import_mcpBundle = require("../../../mcpBundle");
25
+ var import_tool = require("./tool");
26
+ const devtoolsConnect = (0, import_tool.defineTool)({
27
+ capability: "devtools",
28
+ skillOnly: true,
29
+ schema: {
30
+ name: "browser_devtools_start",
31
+ title: "Start browser DevTools",
32
+ description: "Start browser DevTools",
33
+ inputSchema: import_mcpBundle.z.object({}),
34
+ type: "action"
35
+ },
36
+ handle: async (context, params, response) => {
37
+ const browserContext = await context.ensureBrowserContext();
38
+ const { url } = await browserContext._devtoolsStart();
39
+ response.addTextResult("Server is listening on: " + url);
40
+ }
41
+ });
42
+ var devtools_default = [devtoolsConnect];
@@ -24,13 +24,14 @@ __export(dialogs_exports, {
24
24
  module.exports = __toCommonJS(dialogs_exports);
25
25
  var import_mcpBundle = require("../../../mcpBundle");
26
26
  var import_tool = require("./tool");
27
+ var import_schema = require("./schema");
27
28
  const handleDialog = (0, import_tool.defineTabTool)({
28
29
  capability: "core",
29
30
  schema: {
30
31
  name: "browser_handle_dialog",
31
32
  title: "Handle a dialog",
32
33
  description: "Handle a dialog",
33
- inputSchema: import_mcpBundle.z.object({
34
+ inputSchema: import_schema.baseSchema.extend({
34
35
  accept: import_mcpBundle.z.boolean().describe("Whether to accept the dialog."),
35
36
  promptText: import_mcpBundle.z.string().optional().describe("The text of the prompt in case of a prompt dialog.")
36
37
  }),
@@ -24,7 +24,8 @@ module.exports = __toCommonJS(evaluate_exports);
24
24
  var import_mcpBundle = require("../../../mcpBundle");
25
25
  var import_utils = require("playwright-core/lib/utils");
26
26
  var import_tool = require("./tool");
27
- const evaluateSchema = import_mcpBundle.z.object({
27
+ var import_schema = require("./schema");
28
+ const evaluateSchema = import_schema.baseSchema.extend({
28
29
  function: import_mcpBundle.z.string().describe("() => { /* code */ } or (element) => { /* code */ } when element is provided"),
29
30
  element: import_mcpBundle.z.string().optional().describe("Human-readable element description used to obtain permission to interact with the element"),
30
31
  ref: import_mcpBundle.z.string().optional().describe("Exact target element reference from the page snapshot")
@@ -24,13 +24,14 @@ __export(files_exports, {
24
24
  module.exports = __toCommonJS(files_exports);
25
25
  var import_mcpBundle = require("../../../mcpBundle");
26
26
  var import_tool = require("./tool");
27
+ var import_schema = require("./schema");
27
28
  const uploadFile = (0, import_tool.defineTabTool)({
28
29
  capability: "core",
29
30
  schema: {
30
31
  name: "browser_file_upload",
31
32
  title: "Upload files",
32
33
  description: "Upload one or multiple files",
33
- inputSchema: import_mcpBundle.z.object({
34
+ inputSchema: import_schema.baseSchema.extend({
34
35
  paths: import_mcpBundle.z.array(import_mcpBundle.z.string()).optional().describe("The absolute paths to the files to upload. Can be single file or multiple files. If omitted, file chooser is cancelled.")
35
36
  }),
36
37
  type: "action"
@@ -24,13 +24,14 @@ module.exports = __toCommonJS(form_exports);
24
24
  var import_mcpBundle = require("../../../mcpBundle");
25
25
  var import_utils = require("playwright-core/lib/utils");
26
26
  var import_tool = require("./tool");
27
+ var import_schema = require("./schema");
27
28
  const fillForm = (0, import_tool.defineTabTool)({
28
29
  capability: "core",
29
30
  schema: {
30
31
  name: "browser_fill_form",
31
32
  title: "Fill form",
32
33
  description: "Fill multiple form fields",
33
- inputSchema: import_mcpBundle.z.object({
34
+ inputSchema: import_schema.baseSchema.extend({
34
35
  fields: import_mcpBundle.z.array(import_mcpBundle.z.object({
35
36
  name: import_mcpBundle.z.string().describe("Human-readable field name"),
36
37
  type: import_mcpBundle.z.enum(["textbox", "checkbox", "radio", "combobox", "slider"]).describe("Type of the field"),
@@ -24,13 +24,14 @@ module.exports = __toCommonJS(keyboard_exports);
24
24
  var import_mcpBundle = require("../../../mcpBundle");
25
25
  var import_tool = require("./tool");
26
26
  var import_snapshot = require("./snapshot");
27
+ var import_schema = require("./schema");
27
28
  const press = (0, import_tool.defineTabTool)({
28
29
  capability: "core-input",
29
30
  schema: {
30
31
  name: "browser_press_key",
31
32
  title: "Press a key",
32
33
  description: "Press a key on the keyboard",
33
- inputSchema: import_mcpBundle.z.object({
34
+ inputSchema: import_schema.baseSchema.extend({
34
35
  key: import_mcpBundle.z.string().describe("Name of the key to press or a character to generate, such as `ArrowLeft` or `a`")
35
36
  }),
36
37
  type: "input"
@@ -55,7 +56,7 @@ const pressSequentially = (0, import_tool.defineTabTool)({
55
56
  name: "browser_press_sequentially",
56
57
  title: "Type text key by key",
57
58
  description: "Type text key by key on the keyboard",
58
- inputSchema: import_mcpBundle.z.object({
59
+ inputSchema: import_schema.baseSchema.extend({
59
60
  text: import_mcpBundle.z.string().describe("Text to type"),
60
61
  submit: import_mcpBundle.z.boolean().optional().describe("Whether to submit entered text (press Enter after)")
61
62
  }),
@@ -115,7 +116,7 @@ const keydown = (0, import_tool.defineTabTool)({
115
116
  name: "browser_keydown",
116
117
  title: "Press a key down",
117
118
  description: "Press a key down on the keyboard",
118
- inputSchema: import_mcpBundle.z.object({
119
+ inputSchema: import_schema.baseSchema.extend({
119
120
  key: import_mcpBundle.z.string().describe("Name of the key to press or a character to generate, such as `ArrowLeft` or `a`")
120
121
  }),
121
122
  type: "input"
@@ -132,7 +133,7 @@ const keyup = (0, import_tool.defineTabTool)({
132
133
  name: "browser_keyup",
133
134
  title: "Press a key up",
134
135
  description: "Press a key up on the keyboard",
135
- inputSchema: import_mcpBundle.z.object({
136
+ inputSchema: import_schema.baseSchema.extend({
136
137
  key: import_mcpBundle.z.string().describe("Name of the key to press or a character to generate, such as `ArrowLeft` or `a`")
137
138
  }),
138
139
  type: "input"
@@ -23,13 +23,14 @@ __export(navigate_exports, {
23
23
  module.exports = __toCommonJS(navigate_exports);
24
24
  var import_mcpBundle = require("../../../mcpBundle");
25
25
  var import_tool = require("./tool");
26
+ var import_schema = require("./schema");
26
27
  const navigate = (0, import_tool.defineTool)({
27
28
  capability: "core-navigation",
28
29
  schema: {
29
30
  name: "browser_navigate",
30
31
  title: "Navigate to a URL",
31
32
  description: "Navigate to a URL",
32
- inputSchema: import_mcpBundle.z.object({
33
+ inputSchema: import_schema.baseSchema.extend({
33
34
  url: import_mcpBundle.z.string().describe("The URL to navigate to")
34
35
  }),
35
36
  type: "action"
@@ -56,7 +57,7 @@ const goBack = (0, import_tool.defineTabTool)({
56
57
  name: "browser_navigate_back",
57
58
  title: "Go back",
58
59
  description: "Go back to the previous page in the history",
59
- inputSchema: import_mcpBundle.z.object({}),
60
+ inputSchema: import_schema.baseSchema.extend({}),
60
61
  type: "action"
61
62
  },
62
63
  handle: async (tab, params, response) => {
@@ -72,7 +73,7 @@ const goForward = (0, import_tool.defineTabTool)({
72
73
  name: "browser_navigate_forward",
73
74
  title: "Go forward",
74
75
  description: "Go forward to the next page in the history",
75
- inputSchema: import_mcpBundle.z.object({}),
76
+ inputSchema: import_schema.baseSchema.extend({}),
76
77
  type: "action"
77
78
  },
78
79
  handle: async (tab, params, response) => {
@@ -88,7 +89,7 @@ const reload = (0, import_tool.defineTabTool)({
88
89
  name: "browser_reload",
89
90
  title: "Reload the page",
90
91
  description: "Reload the current page",
91
- inputSchema: import_mcpBundle.z.object({}),
92
+ inputSchema: import_schema.baseSchema.extend({}),
92
93
  type: "action"
93
94
  },
94
95
  handle: async (tab, params, response) => {
@@ -34,8 +34,10 @@ module.exports = __toCommonJS(runCode_exports);
34
34
  var import_vm = __toESM(require("vm"));
35
35
  var import_utils = require("playwright-core/lib/utils");
36
36
  var import_mcpBundle = require("../../../mcpBundle");
37
+ var import_ai_runner_fake = require("@cotestdev/ai-runner-fake");
37
38
  var import_tool = require("./tool");
38
- const codeSchema = import_mcpBundle.z.object({
39
+ var import_schema = require("./schema");
40
+ const codeSchema = import_schema.baseSchema.extend({
39
41
  code: import_mcpBundle.z.string().describe(`A JavaScript function containing Playwright code to execute. It will be invoked with a single argument, page, which you can use for any page interaction. For example: \`async (page) => { await page.getByRole('button', { name: 'Submit' }).click(); return await page.title(); }\``)
40
42
  });
41
43
  const runCode = (0, import_tool.defineTabTool)({
@@ -71,6 +73,33 @@ const runCode = (0, import_tool.defineTabTool)({
71
73
  });
72
74
  }
73
75
  });
76
+ const scriptSchema = import_mcpBundle.z.object({
77
+ code: import_mcpBundle.z.string().describe(`A JavaScript function containing Playwright code to execute. It will be invoked with a single argument, page, which you can use for any page interaction. For example: \`async (page) => { await page.getByRole('button', { name: 'Submit' }).click(); return await page.title(); }\``),
78
+ params: import_mcpBundle.z.record(import_mcpBundle.z.string(), import_mcpBundle.z.any()).optional().describe("Parameters to pass to the script."),
79
+ projectId: import_mcpBundle.z.string().describe("Project ID"),
80
+ testId: import_mcpBundle.z.string().describe("Test ID")
81
+ });
82
+ const runScript = (0, import_tool.defineTabTool)({
83
+ capability: "extra",
84
+ schema: {
85
+ name: "run_test_script",
86
+ title: "Run test script with runner",
87
+ description: "Run Playwright script",
88
+ inputSchema: scriptSchema,
89
+ type: "action"
90
+ },
91
+ handle: async (tab, params, response) => {
92
+ response.setIncludeSnapshot();
93
+ const runner = import_ai_runner_fake.Runner.NewInstance(params.projectId, params.testId);
94
+ await runner.init(tab.page, tab.page.context(), params.params);
95
+ const result = await runner.runScript(params.testId, params.code);
96
+ const code = `// Returns the out parameters of the reusable test
97
+ const result = await runner.reuseTest('${params.testId}');`;
98
+ response.addCode(code);
99
+ response.addTextResult(`Out Parameters: ${JSON.stringify(result)}`);
100
+ }
101
+ });
74
102
  var runCode_default = [
75
- runCode
103
+ runCode,
104
+ runScript
76
105
  ];
@@ -27,7 +27,8 @@ var import_utilsBundle = require("playwright-core/lib/utilsBundle");
27
27
  var import_utils2 = require("playwright-core/lib/utils");
28
28
  var import_mcpBundle = require("../../../mcpBundle");
29
29
  var import_tool = require("./tool");
30
- const screenshotSchema = import_mcpBundle.z.object({
30
+ var import_schema = require("./schema");
31
+ const screenshotSchema = import_schema.baseSchema.extend({
31
32
  type: import_mcpBundle.z.enum(["png", "jpeg"]).default("png").describe("Image format for the screenshot. Default is png."),
32
33
  filename: import_mcpBundle.z.string().optional().describe("File name to save the screenshot to. Defaults to `page-{timestamp}.{png|jpeg}` if not specified. Prefer relative file names to stay within the output directory."),
33
34
  element: import_mcpBundle.z.string().optional().describe("Human-readable element description used to obtain permission to screenshot the element. If not provided, the screenshot will be taken of viewport. If element is provided, ref must be provided too."),
@@ -25,6 +25,7 @@ module.exports = __toCommonJS(snapshot_exports);
25
25
  var import_mcpBundle = require("../../../mcpBundle");
26
26
  var import_utils = require("playwright-core/lib/utils");
27
27
  var import_tool = require("./tool");
28
+ var import_schema = require("./schema");
28
29
  const snapshot = (0, import_tool.defineTool)({
29
30
  capability: "core",
30
31
  schema: {
@@ -41,7 +42,7 @@ const snapshot = (0, import_tool.defineTool)({
41
42
  response.setIncludeFullSnapshot(params.filename);
42
43
  }
43
44
  });
44
- const elementSchema = import_mcpBundle.z.object({
45
+ const elementSchema = import_schema.baseSchema.extend({
45
46
  element: import_mcpBundle.z.string().optional().describe("Human-readable element description used to obtain permission to interact with the element"),
46
47
  ref: import_mcpBundle.z.string().describe("Exact target element reference from the page snapshot")
47
48
  });
@@ -86,7 +87,7 @@ const drag = (0, import_tool.defineTabTool)({
86
87
  name: "browser_drag",
87
88
  title: "Drag mouse",
88
89
  description: "Perform drag and drop between two elements",
89
- inputSchema: import_mcpBundle.z.object({
90
+ inputSchema: import_schema.baseSchema.extend({
90
91
  startElement: import_mcpBundle.z.string().describe("Human-readable source element description used to obtain the permission to interact with the element"),
91
92
  startRef: import_mcpBundle.z.string().describe("Exact source element reference from the page snapshot"),
92
93
  endElement: import_mcpBundle.z.string().describe("Human-readable target element description used to obtain the permission to interact with the element"),
@@ -24,13 +24,14 @@ module.exports = __toCommonJS(tabs_exports);
24
24
  var import_mcpBundle = require("../../../mcpBundle");
25
25
  var import_tool = require("./tool");
26
26
  var import_response = require("../response");
27
+ var import_schema = require("./schema");
27
28
  const browserTabs = (0, import_tool.defineTool)({
28
29
  capability: "core-tabs",
29
30
  schema: {
30
31
  name: "browser_tabs",
31
32
  title: "Manage tabs",
32
33
  description: "List, create, close, or select a browser tab.",
33
- inputSchema: import_mcpBundle.z.object({
34
+ inputSchema: import_schema.baseSchema.extend({
34
35
  action: import_mcpBundle.z.enum(["list", "new", "close", "select"]).describe("Operation to perform"),
35
36
  index: import_mcpBundle.z.number().optional().describe("Tab index, used for close/select. If omitted for close, current tab is closed.")
36
37
  }),
@@ -24,13 +24,14 @@ module.exports = __toCommonJS(verify_exports);
24
24
  var import_mcpBundle = require("../../../mcpBundle");
25
25
  var import_utils = require("playwright-core/lib/utils");
26
26
  var import_tool = require("./tool");
27
+ var import_schema = require("./schema");
27
28
  const verifyElement = (0, import_tool.defineTabTool)({
28
29
  capability: "testing",
29
30
  schema: {
30
31
  name: "browser_verify_element_visible",
31
32
  title: "Verify element visible",
32
33
  description: "Verify element is visible on the page",
33
- inputSchema: import_mcpBundle.z.object({
34
+ inputSchema: import_schema.baseSchema.extend({
34
35
  role: import_mcpBundle.z.string().describe('ROLE of the element. Can be found in the snapshot like this: `- {ROLE} "Accessible Name":`'),
35
36
  accessibleName: import_mcpBundle.z.string().describe('ACCESSIBLE_NAME of the element. Can be found in the snapshot like this: `- role "{ACCESSIBLE_NAME}"`')
36
37
  }),
@@ -52,7 +53,7 @@ const verifyText = (0, import_tool.defineTabTool)({
52
53
  name: "browser_verify_text_visible",
53
54
  title: "Verify text visible",
54
55
  description: `Verify text is visible on the page. Prefer ${verifyElement.schema.name} if possible.`,
55
- inputSchema: import_mcpBundle.z.object({
56
+ inputSchema: import_schema.baseSchema.extend({
56
57
  text: import_mcpBundle.z.string().describe('TEXT to verify. Can be found in the snapshot like this: `- role "Accessible Name": {TEXT}` or like this: `- text: {TEXT}`')
57
58
  }),
58
59
  type: "assertion"
@@ -73,7 +74,7 @@ const verifyList = (0, import_tool.defineTabTool)({
73
74
  name: "browser_verify_list_visible",
74
75
  title: "Verify list visible",
75
76
  description: "Verify list is visible on the page",
76
- inputSchema: import_mcpBundle.z.object({
77
+ inputSchema: import_schema.baseSchema.extend({
77
78
  element: import_mcpBundle.z.string().describe("Human-readable list description"),
78
79
  ref: import_mcpBundle.z.string().describe("Exact target element reference that points to the list"),
79
80
  items: import_mcpBundle.z.array(import_mcpBundle.z.string()).describe("Items to verify")
@@ -105,7 +106,7 @@ const verifyValue = (0, import_tool.defineTabTool)({
105
106
  name: "browser_verify_value",
106
107
  title: "Verify value",
107
108
  description: "Verify element value",
108
- inputSchema: import_mcpBundle.z.object({
109
+ inputSchema: import_schema.baseSchema.extend({
109
110
  type: import_mcpBundle.z.enum(["textbox", "checkbox", "radio", "combobox", "slider"]).describe("Type of the element"),
110
111
  element: import_mcpBundle.z.string().describe("Human-readable element description"),
111
112
  ref: import_mcpBundle.z.string().describe("Exact target element reference that points to the element"),
@@ -23,13 +23,14 @@ __export(wait_exports, {
23
23
  module.exports = __toCommonJS(wait_exports);
24
24
  var import_mcpBundle = require("../../../mcpBundle");
25
25
  var import_tool = require("./tool");
26
+ var import_schema = require("./schema");
26
27
  const wait = (0, import_tool.defineTool)({
27
28
  capability: "core",
28
29
  schema: {
29
30
  name: "browser_wait_for",
30
31
  title: "Wait for",
31
32
  description: "Wait for text to appear or disappear or a specified time to pass",
32
- inputSchema: import_mcpBundle.z.object({
33
+ inputSchema: import_schema.baseSchema.extend({
33
34
  time: import_mcpBundle.z.number().optional().describe("The time to wait in seconds"),
34
35
  text: import_mcpBundle.z.string().optional().describe("The text to wait for"),
35
36
  textGone: import_mcpBundle.z.string().optional().describe("The text to wait for to disappear")
@@ -36,6 +36,7 @@ var import_common = __toESM(require("./tools/common"));
36
36
  var import_config = __toESM(require("./tools/config"));
37
37
  var import_console = __toESM(require("./tools/console"));
38
38
  var import_cookies = __toESM(require("./tools/cookies"));
39
+ var import_devtools = __toESM(require("./tools/devtools"));
39
40
  var import_dialogs = __toESM(require("./tools/dialogs"));
40
41
  var import_evaluate = __toESM(require("./tools/evaluate"));
41
42
  var import_files = __toESM(require("./tools/files"));
@@ -62,6 +63,7 @@ const browserTools = [
62
63
  ...import_config.default,
63
64
  ...import_console.default,
64
65
  ...import_cookies.default,
66
+ ...import_devtools.default,
65
67
  ...import_dialogs.default,
66
68
  ...import_evaluate.default,
67
69
  ...import_files.default,
@@ -37,11 +37,10 @@ var import_utils = require("playwright-core/lib/utils");
37
37
  var import_cdpRelay = require("./cdpRelay");
38
38
  const debugLogger = (0, import_utilsBundle.debug)("pw:mcp:relay");
39
39
  class ExtensionContextFactory {
40
- constructor(browserChannel, userDataDir, executablePath, forceNewTab) {
40
+ constructor(browserChannel, userDataDir, executablePath) {
41
41
  this._browserChannel = browserChannel;
42
42
  this._userDataDir = userDataDir;
43
43
  this._executablePath = executablePath;
44
- this._forceNewTab = forceNewTab;
45
44
  }
46
45
  async createContext(clientInfo, abortSignal, options) {
47
46
  const browser = await this._obtainBrowser(clientInfo, abortSignal, options?.toolName);
@@ -55,7 +54,7 @@ class ExtensionContextFactory {
55
54
  }
56
55
  async _obtainBrowser(clientInfo, abortSignal, toolName) {
57
56
  const relay = await this._startRelay(abortSignal);
58
- const forceNewTab = this._forceNewTab || toolName === "browser_navigate";
57
+ const forceNewTab = toolName === "browser_navigate";
59
58
  await relay.ensureExtensionConnectionForMCPContext(clientInfo, abortSignal, forceNewTab);
60
59
  return await playwright.chromium.connectOverCDP(relay.cdpEndpoint(), { isLocal: true });
61
60
  }
@@ -42,8 +42,8 @@ var import_browserContextFactory = require("./browser/browserContextFactory");
42
42
  var import_browserServerBackend = require("./browser/browserServerBackend");
43
43
  var import_extensionContextFactory = require("./extension/extensionContextFactory");
44
44
  function decorateCommand(command, version) {
45
- command.option("--allowed-hosts <hosts...>", "comma-separated list of hosts this server is allowed to serve from. Defaults to the host the server is bound to. Pass '*' to disable the host check.", import_config.commaSeparatedList).option("--allowed-origins <origins>", "semicolon-separated list of TRUSTED origins to allow the browser to request. Default is to allow all.\nImportant: *does not* serve as a security boundary and *does not* affect redirects. ", import_config.semicolonSeparatedList).option("--allow-unrestricted-file-access", "allow access to files outside of the workspace roots. Also allows unrestricted access to file:// URLs. By default access to file system is restricted to workspace root directories (or cwd if no roots are configured) only, and navigation to file:// URLs is blocked.").option("--blocked-origins <origins>", "semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed.\nImportant: *does not* serve as a security boundary and *does not* affect redirects.", import_config.semicolonSeparatedList).option("--block-service-workers", "block service workers").option("--browser <browser>", "browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge.").option("--caps <caps>", "comma-separated list of additional capabilities to enable, possible values: vision, pdf, devtools.", import_config.commaSeparatedList).option("--cdp-endpoint <endpoint>", "CDP endpoint to connect to.").option("--cdp-header <headers...>", "CDP headers to send with the connect request, multiple can be specified.", import_config.headerParser).option("--cdp-timeout <timeout>", "timeout in milliseconds for connecting to CDP endpoint, defaults to 30000ms", import_config.numberParser).option("--codegen <lang>", 'specify the language to use for code generation, possible values: "typescript", "none". Default is "typescript".', import_config.enumParser.bind(null, "--codegen", ["none", "typescript"])).option("--config <path>", "path to the configuration file.").option("--console-level <level>", 'level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels.', import_config.enumParser.bind(null, "--console-level", ["error", "warning", "info", "debug"])).option("--device <device>", 'device to emulate, for example: "iPhone 15"').option("--executable-path <path>", "path to the browser executable.").option("--extension", 'Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed.').option("--grant-permissions <permissions...>", 'List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write".', import_config.commaSeparatedList).option("--headless", "run browser in headless mode, headed by default").option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.").option("--ignore-https-errors", "ignore https errors").option("--init-page <path...>", "path to TypeScript file to evaluate on Playwright page object").option("--init-script <path...>", "path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times.").option("--isolated", "keep the browser profile in memory, do not save it to disk.").option("--image-responses <mode>", 'whether to send image responses to the client. Can be "allow" or "omit", Defaults to "allow".', import_config.enumParser.bind(null, "--image-responses", ["allow", "omit"])).option("--no-sandbox", "disable the sandbox for all process types that are normally sandboxed.").option("--output-dir <path>", "path to the directory for output files.").option("--output-mode <mode>", 'whether to save snapshots, console messages, network logs to a file or to the standard output. Can be "file" or "stdout". Default is "stdout".', import_config.enumParser.bind(null, "--output-mode", ["file", "stdout"])).option("--port <port>", "port to listen on for SSE transport.").option("--proxy-bypass <bypass>", 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"').option("--proxy-server <proxy>", 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"').option("--sandbox", "enable the sandbox for all process types that are normally not sandboxed.").option("--save-session", "Whether to save the Playwright MCP session into the output directory.").option("--save-trace", "Whether to save the Playwright Trace of the session into the output directory.").option("--save-video <size>", 'Whether to save the video of the session into the output directory. For example "--save-video=800x600"', import_config.resolutionParser.bind(null, "--save-video")).option("--secrets <path>", "path to a file containing secrets in the dotenv format", import_config.dotenvFileLoader).option("--shared-browser-context", "reuse the same browser context between all connected HTTP clients.").option("--snapshot-mode <mode>", 'when taking snapshots for responses, specifies the mode to use. Can be "incremental", "full", or "none". Default is incremental.').option("--storage-state <path>", "path to the storage state file for isolated sessions.").option("--test-id-attribute <attribute>", 'specify the attribute to use for test ids, defaults to "data-testid"').option("--timeout-action <timeout>", "specify action timeout in milliseconds, defaults to 5000ms", import_config.numberParser).option("--timeout-navigation <timeout>", "specify navigation timeout in milliseconds, defaults to 60000ms", import_config.numberParser).option("--user-agent <ua string>", "specify user agent string").option("--user-data-dir <path>", "path to the user data directory. If not specified, a temporary directory will be created.").option("--viewport-size <size>", 'specify browser viewport size in pixels, for example "1280x720"', import_config.resolutionParser.bind(null, "--viewport-size")).addOption(new import_utilsBundle.ProgramOption("--vision", "Legacy option, use --caps=vision instead").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--daemon-session <path>", "path to the daemon config.").hideHelp()).action(async (options) => {
46
- options.sandbox = options.sandbox === true ? void 0 : false;
45
+ command.option("--allowed-hosts <hosts...>", "comma-separated list of hosts this server is allowed to serve from. Defaults to the host the server is bound to. Pass '*' to disable the host check.", import_config.commaSeparatedList).option("--allowed-origins <origins>", "semicolon-separated list of TRUSTED origins to allow the browser to request. Default is to allow all.\nImportant: *does not* serve as a security boundary and *does not* affect redirects. ", import_config.semicolonSeparatedList).option("--allow-unrestricted-file-access", "allow access to files outside of the workspace roots. Also allows unrestricted access to file:// URLs. By default access to file system is restricted to workspace root directories (or cwd if no roots are configured) only, and navigation to file:// URLs is blocked.").option("--blocked-origins <origins>", "semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed.\nImportant: *does not* serve as a security boundary and *does not* affect redirects.", import_config.semicolonSeparatedList).option("--block-service-workers", "block service workers").option("--browser <browser>", "browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge.").option("--caps <caps>", "comma-separated list of additional capabilities to enable, possible values: vision, pdf, devtools.", import_config.commaSeparatedList).option("--cdp-endpoint <endpoint>", "CDP endpoint to connect to.").option("--cdp-header <headers...>", "CDP headers to send with the connect request, multiple can be specified.", import_config.headerParser).option("--cdp-timeout <timeout>", "timeout in milliseconds for connecting to CDP endpoint, defaults to 30000ms", import_config.numberParser).option("--chromium-sandbox", "enable the chromium sandbox. disable with --no-chromium-sandbox.").option("--no-chromium-sandbox", "disable the chromium sandbox.").option("--codegen <lang>", 'specify the language to use for code generation, possible values: "typescript", "none". Default is "typescript".', import_config.enumParser.bind(null, "--codegen", ["none", "typescript"])).option("--config <path>", "path to the configuration file.").option("--console-level <level>", 'level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels.', import_config.enumParser.bind(null, "--console-level", ["error", "warning", "info", "debug"])).option("--device <device>", 'device to emulate, for example: "iPhone 15"').option("--executable-path <path>", "path to the browser executable.").option("--extension", 'Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed.').option("--grant-permissions <permissions...>", 'List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write".', import_config.commaSeparatedList).option("--headless", "run browser in headless mode, headed by default").option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.").option("--ignore-https-errors", "ignore https errors").option("--init-page <path...>", "path to TypeScript file to evaluate on Playwright page object").option("--init-script <path...>", "path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times.").option("--isolated", "keep the browser profile in memory, do not save it to disk.").option("--image-responses <mode>", 'whether to send image responses to the client. Can be "allow" or "omit", Defaults to "allow".', import_config.enumParser.bind(null, "--image-responses", ["allow", "omit"])).option("--output-dir <path>", "path to the directory for output files.").option("--output-mode <mode>", 'whether to save snapshots, console messages, network logs to a file or to the standard output. Can be "file" or "stdout". Default is "stdout".', import_config.enumParser.bind(null, "--output-mode", ["file", "stdout"])).option("--port <port>", "port to listen on for SSE transport.").option("--proxy-bypass <bypass>", 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"').option("--proxy-server <proxy>", 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"').option("--save-session", "Whether to save the Playwright MCP session into the output directory.").option("--save-trace", "Whether to save the Playwright Trace of the session into the output directory.").option("--save-video <size>", 'Whether to save the video of the session into the output directory. For example "--save-video=800x600"', import_config.resolutionParser.bind(null, "--save-video")).option("--secrets <path>", "path to a file containing secrets in the dotenv format", import_config.dotenvFileLoader).option("--shared-browser-context", "reuse the same browser context between all connected HTTP clients.").option("--snapshot-mode <mode>", 'when taking snapshots for responses, specifies the mode to use. Can be "incremental", "full", or "none". Default is incremental.').option("--storage-state <path>", "path to the storage state file for isolated sessions.").option("--test-id-attribute <attribute>", 'specify the attribute to use for test ids, defaults to "data-testid"').option("--timeout-action <timeout>", "specify action timeout in milliseconds, defaults to 5000ms", import_config.numberParser).option("--timeout-navigation <timeout>", "specify navigation timeout in milliseconds, defaults to 60000ms", import_config.numberParser).option("--user-agent <ua string>", "specify user agent string").option("--user-data-dir <path>", "path to the user data directory. If not specified, a temporary directory will be created.").option("--viewport-size <size>", 'specify browser viewport size in pixels, for example "1280x720"', import_config.resolutionParser.bind(null, "--viewport-size")).addOption(new import_utilsBundle.ProgramOption("--vision", "Legacy option, use --caps=vision instead").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--daemon-session <path>", "path to the daemon config.").hideHelp()).action(async (options) => {
46
+ options.chromiumSandbox = options.chromiumSandbox === true ? void 0 : false;
47
47
  (0, import_watchdog.setupExitWatchdog)();
48
48
  if (options.vision) {
49
49
  console.error("The --vision option is deprecated, use --caps=vision instead");
@@ -63,8 +63,7 @@ Please run the command below. It will install a local copy of ffmpeg and will no
63
63
  process.exit(1);
64
64
  }
65
65
  const browserContextFactory = (0, import_browserContextFactory.contextFactory)(config);
66
- const forceNewTab = !!config.sessionConfig;
67
- const extensionContextFactory = new import_extensionContextFactory.ExtensionContextFactory(config.browser.launchOptions.channel || "chrome", config.browser.userDataDir, config.browser.launchOptions.executablePath, forceNewTab);
66
+ const extensionContextFactory = new import_extensionContextFactory.ExtensionContextFactory(config.browser.launchOptions.channel || "chrome", config.browser.userDataDir, config.browser.launchOptions.executablePath);
68
67
  if (config.sessionConfig) {
69
68
  const contextFactory2 = config.extension ? extensionContextFactory : browserContextFactory;
70
69
  try {
@@ -28,7 +28,7 @@ function toMcpTool(tool) {
28
28
  return {
29
29
  name: tool.name,
30
30
  description: tool.description,
31
- inputSchema: import_mcpBundle.zodToJsonSchema(tool.inputSchema),
31
+ inputSchema: import_mcpBundle.z.toJSONSchema(tool.inputSchema),
32
32
  annotations: {
33
33
  title: tool.title,
34
34
  readOnlyHint: readOnly,
@@ -1,28 +1,6 @@
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
2
  var import_program = require("./program");
25
- (0, import_program.program)(require.resolve("../../../package.json")).catch((e) => {
3
+ (0, import_program.program)().catch((e) => {
26
4
  console.error(e.message);
27
5
  process.exit(1);
28
6
  });
@@ -49,7 +49,7 @@ const open = (0, import_command.declareCommand)({
49
49
  persistent: import_mcpBundle.z.boolean().optional().describe("Use persistent browser profile"),
50
50
  profile: import_mcpBundle.z.string().optional().describe("Use persistent browser profile, store profile in specified directory.")
51
51
  }),
52
- toolName: "browser_navigate",
52
+ toolName: ({ url }) => url ? "browser_navigate" : "browser_snapshot",
53
53
  toolParams: ({ url }) => ({ url: url || "about:blank" })
54
54
  });
55
55
  const close = (0, import_command.declareCommand)({
@@ -681,6 +681,22 @@ const videoStop = (0, import_command.declareCommand)({
681
681
  toolName: "browser_stop_video",
682
682
  toolParams: ({ filename }) => ({ filename })
683
683
  });
684
+ const devtoolsShow = (0, import_command.declareCommand)({
685
+ name: "show",
686
+ description: "Show browser DevTools",
687
+ category: "devtools",
688
+ args: import_mcpBundle.z.object({}),
689
+ toolName: "",
690
+ toolParams: () => ({})
691
+ });
692
+ const devtoolsStart = (0, import_command.declareCommand)({
693
+ name: "devtools-start",
694
+ description: "Show browser DevTools",
695
+ category: "devtools",
696
+ args: import_mcpBundle.z.object({}),
697
+ toolName: "browser_devtools_start",
698
+ toolParams: () => ({})
699
+ });
684
700
  const sessionList = (0, import_command.declareCommand)({
685
701
  name: "list",
686
702
  description: "List browser sessions",
@@ -742,6 +758,14 @@ const installBrowser = (0, import_command.declareCommand)({
742
758
  toolName: "browser_install",
743
759
  toolParams: () => ({})
744
760
  });
761
+ const tray = (0, import_command.declareCommand)({
762
+ name: "tray",
763
+ description: "Run tray",
764
+ category: "config",
765
+ hidden: true,
766
+ toolName: "",
767
+ toolParams: () => ({})
768
+ });
745
769
  const commandsArray = [
746
770
  // core category
747
771
  open,
@@ -819,10 +843,14 @@ const commandsArray = [
819
843
  tracingStop,
820
844
  videoStart,
821
845
  videoStop,
846
+ devtoolsShow,
847
+ devtoolsStart,
822
848
  // session category
823
849
  sessionList,
824
850
  sessionCloseAll,
825
- killAll
851
+ killAll,
852
+ // Hidden commands
853
+ tray
826
854
  ];
827
855
  const commands = Object.fromEntries(commandsArray.map((cmd) => [cmd.name, cmd]));
828
856
  // Annotate the CommonJS export names for ESM import in node: