@cotestdev/mcp_playwright 0.0.24 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/mcp/browser/browserContextFactory.js +13 -15
- package/lib/mcp/browser/config.js +4 -4
- package/lib/mcp/browser/context.js +26 -23
- package/lib/mcp/browser/tools/runCode.js +45 -2
- package/lib/mcp/browser/tools.js +6 -4
- package/lib/mcp/program.js +1 -1
- package/lib/mcp/sdk/server.js +16 -0
- package/lib/mcp/test/plannerTools.js +9 -8
- package/lib/mcp/test/testContext.js +8 -2
- package/lib/mcpBundleImpl/index.js +33 -33
- package/package.json +1 -1
|
@@ -90,22 +90,21 @@ class BaseContextFactory {
|
|
|
90
90
|
async createContext(clientInfo) {
|
|
91
91
|
(0, import_log.testDebug)(`create browser context (${this._logName})`);
|
|
92
92
|
const browser = await this._obtainBrowser(clientInfo);
|
|
93
|
-
const browserContext = await this._doCreateContext(browser);
|
|
93
|
+
const browserContext = await this._doCreateContext(browser, clientInfo);
|
|
94
94
|
await addInitScript(browserContext, this.config.browser.initScript);
|
|
95
95
|
return {
|
|
96
96
|
browserContext,
|
|
97
|
-
close: (
|
|
97
|
+
close: () => this._closeBrowserContext(browserContext, browser)
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
|
-
async _doCreateContext(browser) {
|
|
100
|
+
async _doCreateContext(browser, clientInfo) {
|
|
101
101
|
throw new Error("Not implemented");
|
|
102
102
|
}
|
|
103
|
-
async _closeBrowserContext(browserContext, browser
|
|
103
|
+
async _closeBrowserContext(browserContext, browser) {
|
|
104
104
|
(0, import_log.testDebug)(`close browser context (${this._logName})`);
|
|
105
105
|
if (browser.contexts().length === 1)
|
|
106
106
|
this._browserPromise = void 0;
|
|
107
107
|
await browserContext.close().catch(import_log.logUnhandledError);
|
|
108
|
-
await afterClose();
|
|
109
108
|
if (browser.contexts().length === 0) {
|
|
110
109
|
(0, import_log.testDebug)(`close browser (${this._logName})`);
|
|
111
110
|
await browser.close().catch(import_log.logUnhandledError);
|
|
@@ -133,8 +132,8 @@ class IsolatedContextFactory extends BaseContextFactory {
|
|
|
133
132
|
throw error;
|
|
134
133
|
});
|
|
135
134
|
}
|
|
136
|
-
async _doCreateContext(browser) {
|
|
137
|
-
return browser.newContext(browserContextOptionsFromConfig(this.config));
|
|
135
|
+
async _doCreateContext(browser, clientInfo) {
|
|
136
|
+
return browser.newContext(await browserContextOptionsFromConfig(this.config, clientInfo));
|
|
138
137
|
}
|
|
139
138
|
}
|
|
140
139
|
class CdpContextFactory extends BaseContextFactory {
|
|
@@ -184,7 +183,7 @@ class PersistentContextFactory {
|
|
|
184
183
|
const launchOptions = {
|
|
185
184
|
tracesDir,
|
|
186
185
|
...this.config.browser.launchOptions,
|
|
187
|
-
...browserContextOptionsFromConfig(this.config),
|
|
186
|
+
...await browserContextOptionsFromConfig(this.config, clientInfo),
|
|
188
187
|
handleSIGINT: false,
|
|
189
188
|
handleSIGTERM: false,
|
|
190
189
|
ignoreDefaultArgs: [
|
|
@@ -195,7 +194,7 @@ class PersistentContextFactory {
|
|
|
195
194
|
try {
|
|
196
195
|
const browserContext = await browserType.launchPersistentContext(userDataDir, launchOptions);
|
|
197
196
|
await addInitScript(browserContext, this.config.browser.initScript);
|
|
198
|
-
const close = (
|
|
197
|
+
const close = () => this._closeBrowserContext(browserContext, userDataDir);
|
|
199
198
|
return { browserContext, close };
|
|
200
199
|
} catch (error) {
|
|
201
200
|
if (error.message.includes("Executable doesn't exist"))
|
|
@@ -209,12 +208,11 @@ class PersistentContextFactory {
|
|
|
209
208
|
}
|
|
210
209
|
throw new Error(`Browser is already in use for ${userDataDir}, use --isolated to run multiple instances of the same browser`);
|
|
211
210
|
}
|
|
212
|
-
async _closeBrowserContext(browserContext, userDataDir
|
|
211
|
+
async _closeBrowserContext(browserContext, userDataDir) {
|
|
213
212
|
(0, import_log.testDebug)("close browser context (persistent)");
|
|
214
213
|
(0, import_log.testDebug)("release user data dir", userDataDir);
|
|
215
214
|
await browserContext.close().catch(() => {
|
|
216
215
|
});
|
|
217
|
-
await afterClose();
|
|
218
216
|
this._userDataDirs.delete(userDataDir);
|
|
219
217
|
if (process.env.PWMCP_PROFILES_DIR_FOR_TEST && userDataDir.startsWith(process.env.PWMCP_PROFILES_DIR_FOR_TEST))
|
|
220
218
|
await import_fs.default.promises.rm(userDataDir, { recursive: true }).catch(import_log.logUnhandledError);
|
|
@@ -294,8 +292,7 @@ class SharedContextFactory {
|
|
|
294
292
|
if (!contextPromise)
|
|
295
293
|
return;
|
|
296
294
|
const { close } = await contextPromise;
|
|
297
|
-
await close(
|
|
298
|
-
});
|
|
295
|
+
await close();
|
|
299
296
|
}
|
|
300
297
|
}
|
|
301
298
|
async function computeTracesDir(config, clientInfo) {
|
|
@@ -303,11 +300,12 @@ async function computeTracesDir(config, clientInfo) {
|
|
|
303
300
|
return;
|
|
304
301
|
return await (0, import_config.outputFile)(config, clientInfo, `traces`, { origin: "code", reason: "Collecting trace" });
|
|
305
302
|
}
|
|
306
|
-
function browserContextOptionsFromConfig(config) {
|
|
303
|
+
async function browserContextOptionsFromConfig(config, clientInfo) {
|
|
307
304
|
const result = { ...config.browser.contextOptions };
|
|
308
305
|
if (config.saveVideo) {
|
|
306
|
+
const dir = await (0, import_config.outputFile)(config, clientInfo, `videos`, { origin: "code", reason: "Saving video" });
|
|
309
307
|
result.recordVideo = {
|
|
310
|
-
dir
|
|
308
|
+
dir,
|
|
311
309
|
size: config.saveVideo
|
|
312
310
|
};
|
|
313
311
|
}
|
|
@@ -40,8 +40,7 @@ __export(config_exports, {
|
|
|
40
40
|
resolutionParser: () => resolutionParser,
|
|
41
41
|
resolveCLIConfig: () => resolveCLIConfig,
|
|
42
42
|
resolveConfig: () => resolveConfig,
|
|
43
|
-
semicolonSeparatedList: () => semicolonSeparatedList
|
|
44
|
-
tmpDir: () => tmpDir
|
|
43
|
+
semicolonSeparatedList: () => semicolonSeparatedList
|
|
45
44
|
});
|
|
46
45
|
module.exports = __toCommonJS(config_exports);
|
|
47
46
|
var import_fs = __toESM(require("fs"));
|
|
@@ -187,6 +186,7 @@ function configFromCLIOptions(cliOptions) {
|
|
|
187
186
|
allowedOrigins: cliOptions.allowedOrigins,
|
|
188
187
|
blockedOrigins: cliOptions.blockedOrigins
|
|
189
188
|
},
|
|
189
|
+
allowUnrestrictedFileAccess: cliOptions.allowUnrestrictedFileAccess,
|
|
190
190
|
saveSession: cliOptions.saveSession,
|
|
191
191
|
saveTrace: cliOptions.saveTrace,
|
|
192
192
|
saveVideo: cliOptions.saveVideo,
|
|
@@ -207,6 +207,7 @@ function configFromEnv() {
|
|
|
207
207
|
const options = {};
|
|
208
208
|
options.allowedHosts = commaSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_HOSTNAMES);
|
|
209
209
|
options.allowedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_ORIGINS);
|
|
210
|
+
options.allowUnrestrictedFileAccess = envToBoolean(process.env.PLAYWRIGHT_MCP_ALLOW_UNRESTRICTED_FILE_ACCESS);
|
|
210
211
|
options.blockedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_BLOCKED_ORIGINS);
|
|
211
212
|
options.blockServiceWorkers = envToBoolean(process.env.PLAYWRIGHT_MCP_BLOCK_SERVICE_WORKERS);
|
|
212
213
|
options.browser = envToString(process.env.PLAYWRIGHT_MCP_BROWSER);
|
|
@@ -413,6 +414,5 @@ function sanitizeForFilePath(s) {
|
|
|
413
414
|
resolutionParser,
|
|
414
415
|
resolveCLIConfig,
|
|
415
416
|
resolveConfig,
|
|
416
|
-
semicolonSeparatedList
|
|
417
|
-
tmpDir
|
|
417
|
+
semicolonSeparatedList
|
|
418
418
|
});
|
|
@@ -32,14 +32,14 @@ __export(context_exports, {
|
|
|
32
32
|
InputRecorder: () => InputRecorder
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(context_exports);
|
|
35
|
-
var import_fs = __toESM(require("fs"));
|
|
36
35
|
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
37
36
|
var import_utils = require("playwright-core/lib/utils");
|
|
38
37
|
var import_playwright_core = require("playwright-core");
|
|
38
|
+
var import_url = require("url");
|
|
39
|
+
var import_os = __toESM(require("os"));
|
|
39
40
|
var import_log = require("../log");
|
|
40
41
|
var import_tab = require("./tab");
|
|
41
42
|
var import_config = require("./config");
|
|
42
|
-
var import_utils2 = require("./tools/utils");
|
|
43
43
|
const testDebug = (0, import_utilsBundle.debug)("pw:mcp:test");
|
|
44
44
|
class Context {
|
|
45
45
|
constructor(options) {
|
|
@@ -138,27 +138,7 @@ class Context {
|
|
|
138
138
|
await promise.then(async ({ browserContext, close }) => {
|
|
139
139
|
if (this.config.saveTrace)
|
|
140
140
|
await browserContext.tracing.stop();
|
|
141
|
-
|
|
142
|
-
await close(async () => {
|
|
143
|
-
for (const video of videos) {
|
|
144
|
-
const name = await this.outputFile((0, import_utils2.dateAsFileName)("webm"), { origin: "code", reason: "Saving video" });
|
|
145
|
-
const p = await video.path();
|
|
146
|
-
if (import_fs.default.existsSync(p)) {
|
|
147
|
-
try {
|
|
148
|
-
await import_fs.default.promises.rename(p, name);
|
|
149
|
-
} catch (e) {
|
|
150
|
-
if (e.code !== "EXDEV")
|
|
151
|
-
(0, import_log.logUnhandledError)(e);
|
|
152
|
-
try {
|
|
153
|
-
await import_fs.default.promises.copyFile(p, name);
|
|
154
|
-
await import_fs.default.promises.unlink(p);
|
|
155
|
-
} catch (e2) {
|
|
156
|
-
(0, import_log.logUnhandledError)(e2);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
});
|
|
141
|
+
await close();
|
|
162
142
|
});
|
|
163
143
|
}
|
|
164
144
|
async dispose() {
|
|
@@ -197,6 +177,10 @@ class Context {
|
|
|
197
177
|
import_playwright_core.selectors.setTestIdAttribute(this.config.testIdAttribute);
|
|
198
178
|
const result = await this._browserContextFactory.createContext(this._clientInfo, this._abortController.signal, this._runningToolName);
|
|
199
179
|
const { browserContext } = result;
|
|
180
|
+
if (!this.config.allowUnrestrictedFileAccess) {
|
|
181
|
+
browserContext._setAllowedProtocols(["http:", "https:", "about:", "data:"]);
|
|
182
|
+
browserContext._setAllowedDirectories(allRootPaths(this._clientInfo));
|
|
183
|
+
}
|
|
200
184
|
await this._setupRequestInterception(browserContext);
|
|
201
185
|
if (this.sessionLog)
|
|
202
186
|
await InputRecorder.create(this, browserContext);
|
|
@@ -222,6 +206,25 @@ class Context {
|
|
|
222
206
|
};
|
|
223
207
|
}
|
|
224
208
|
}
|
|
209
|
+
function allRootPaths(clientInfo) {
|
|
210
|
+
const paths = [];
|
|
211
|
+
for (const root of clientInfo.roots) {
|
|
212
|
+
const url = new URL(root.uri);
|
|
213
|
+
let rootPath;
|
|
214
|
+
try {
|
|
215
|
+
rootPath = (0, import_url.fileURLToPath)(url);
|
|
216
|
+
} catch (e) {
|
|
217
|
+
if (e.code === "ERR_INVALID_FILE_URL_PATH" && import_os.default.platform() === "win32")
|
|
218
|
+
rootPath = decodeURIComponent(url.pathname);
|
|
219
|
+
}
|
|
220
|
+
if (!rootPath)
|
|
221
|
+
continue;
|
|
222
|
+
paths.push(rootPath);
|
|
223
|
+
}
|
|
224
|
+
if (paths.length === 0)
|
|
225
|
+
paths.push(process.cwd());
|
|
226
|
+
return paths;
|
|
227
|
+
}
|
|
225
228
|
function originOrHostGlob(originOrHost) {
|
|
226
229
|
try {
|
|
227
230
|
const url = new URL(originOrHost);
|
|
@@ -40,7 +40,7 @@ const codeSchema = import_common.baseSchema.extend({
|
|
|
40
40
|
code: import_mcpBundle.z.string().describe(`A Typescript 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(); }\``)
|
|
41
41
|
});
|
|
42
42
|
const runCode = (0, import_tool.defineTabTool)({
|
|
43
|
-
capability: "
|
|
43
|
+
capability: "core",
|
|
44
44
|
schema: {
|
|
45
45
|
name: "browser_run_code",
|
|
46
46
|
title: "Run Playwright code",
|
|
@@ -73,6 +73,49 @@ const runCode = (0, import_tool.defineTabTool)({
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
|
+
const scriptSchema = import_common.baseSchema.extend({
|
|
77
|
+
code: import_mcpBundle.z.string().describe(`A Typescript 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.any()).optional().describe("Parameters to pass to the script.")
|
|
79
|
+
});
|
|
80
|
+
const runScript = (0, import_tool.defineTabTool)({
|
|
81
|
+
capability: "extra",
|
|
82
|
+
schema: {
|
|
83
|
+
name: "browser_run_script",
|
|
84
|
+
title: "Run Playwright script",
|
|
85
|
+
description: "Run Playwright script",
|
|
86
|
+
inputSchema: scriptSchema,
|
|
87
|
+
type: "action"
|
|
88
|
+
},
|
|
89
|
+
handle: async (tab, params, response) => {
|
|
90
|
+
response.setIncludeSnapshot();
|
|
91
|
+
response.addCode(`await (${params.code})(page);`);
|
|
92
|
+
const __end__ = new import_utils.ManualPromise();
|
|
93
|
+
const context = {
|
|
94
|
+
page: tab.page,
|
|
95
|
+
__end__
|
|
96
|
+
};
|
|
97
|
+
if (params.params) {
|
|
98
|
+
for (const [key, value] of Object.entries(params.params))
|
|
99
|
+
context[key] = value;
|
|
100
|
+
}
|
|
101
|
+
import_vm.default.createContext(context);
|
|
102
|
+
await tab.waitForCompletion(async () => {
|
|
103
|
+
const snippet = `(async () => {
|
|
104
|
+
try {
|
|
105
|
+
const result = await (${params.code})(page);
|
|
106
|
+
__end__.resolve(JSON.stringify(result));
|
|
107
|
+
} catch (e) {
|
|
108
|
+
__end__.reject(e);
|
|
109
|
+
}
|
|
110
|
+
})()`;
|
|
111
|
+
await import_vm.default.runInContext(snippet, context);
|
|
112
|
+
const result = await __end__;
|
|
113
|
+
if (typeof result === "string")
|
|
114
|
+
response.addResult(result);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
76
118
|
var runCode_default = [
|
|
77
|
-
runCode
|
|
119
|
+
runCode,
|
|
120
|
+
runScript
|
|
78
121
|
];
|
package/lib/mcp/browser/tools.js
CHANGED
|
@@ -46,20 +46,22 @@ var import_snapshot = __toESM(require("./tools/snapshot"));
|
|
|
46
46
|
var import_screenshot = __toESM(require("./tools/screenshot"));
|
|
47
47
|
var import_tabs = __toESM(require("./tools/tabs"));
|
|
48
48
|
var import_tracing = __toESM(require("./tools/tracing"));
|
|
49
|
+
var import_console = __toESM(require("./tools/console"));
|
|
50
|
+
var import_install = __toESM(require("./tools/install"));
|
|
49
51
|
var import_wait = __toESM(require("./tools/wait"));
|
|
50
52
|
var import_verify = __toESM(require("./tools/verify"));
|
|
53
|
+
var import_network = __toESM(require("./tools/network"));
|
|
51
54
|
const browserTools = [
|
|
52
55
|
...import_common.default,
|
|
53
|
-
...
|
|
54
|
-
// ...console,
|
|
56
|
+
...import_console.default,
|
|
55
57
|
...import_dialogs.default,
|
|
56
58
|
...import_evaluate.default,
|
|
57
59
|
...import_files.default,
|
|
58
60
|
...import_form.default,
|
|
59
|
-
|
|
61
|
+
...import_install.default,
|
|
60
62
|
...import_keyboard.default,
|
|
61
63
|
...import_navigate.default,
|
|
62
|
-
|
|
64
|
+
...import_network.default,
|
|
63
65
|
...import_mouse.default,
|
|
64
66
|
...import_pdf.default,
|
|
65
67
|
...import_runCode.default,
|
package/lib/mcp/program.js
CHANGED
|
@@ -41,7 +41,7 @@ var import_browserContextFactory = require("./browser/browserContextFactory");
|
|
|
41
41
|
var import_browserServerBackend = require("./browser/browserServerBackend");
|
|
42
42
|
var import_extensionContextFactory = require("./extension/extensionContextFactory");
|
|
43
43
|
function decorateCommand(command, version) {
|
|
44
|
-
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("--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.", 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("--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("--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()).action(async (options) => {
|
|
44
|
+
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.", 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("--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("--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()).action(async (options) => {
|
|
45
45
|
(0, import_watchdog.setupExitWatchdog)();
|
|
46
46
|
if (options.vision) {
|
|
47
47
|
console.error("The --vision option is deprecated, use --caps=vision instead");
|
package/lib/mcp/sdk/server.js
CHANGED
|
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var server_exports = {};
|
|
30
30
|
__export(server_exports, {
|
|
31
|
+
allRootPaths: () => allRootPaths,
|
|
31
32
|
connect: () => connect,
|
|
32
33
|
createServer: () => createServer,
|
|
33
34
|
firstRootPath: () => firstRootPath,
|
|
@@ -175,6 +176,20 @@ function firstRootPath(clientInfo) {
|
|
|
175
176
|
return void 0;
|
|
176
177
|
}
|
|
177
178
|
}
|
|
179
|
+
function allRootPaths(clientInfo) {
|
|
180
|
+
const paths = [];
|
|
181
|
+
for (const root of clientInfo.roots) {
|
|
182
|
+
try {
|
|
183
|
+
const url = new URL(root.uri);
|
|
184
|
+
const path = (0, import_url.fileURLToPath)(url);
|
|
185
|
+
if (path)
|
|
186
|
+
paths.push(path);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
serverDebug(error);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return paths;
|
|
192
|
+
}
|
|
178
193
|
function mergeTextParts(result) {
|
|
179
194
|
const content = [];
|
|
180
195
|
const testParts = [];
|
|
@@ -198,6 +213,7 @@ function mergeTextParts(result) {
|
|
|
198
213
|
}
|
|
199
214
|
// Annotate the CommonJS export names for ESM import in node:
|
|
200
215
|
0 && (module.exports = {
|
|
216
|
+
allRootPaths,
|
|
201
217
|
connect,
|
|
202
218
|
createServer,
|
|
203
219
|
firstRootPath,
|
|
@@ -62,8 +62,10 @@ const planSchema = import_mcpBundle.z.object({
|
|
|
62
62
|
tests: import_mcpBundle.z.array(import_mcpBundle.z.object({
|
|
63
63
|
name: import_mcpBundle.z.string().describe("The name of the test"),
|
|
64
64
|
file: import_mcpBundle.z.string().describe('The file the test should be saved to, for example: "tests/<suite-name>/<test-name>.spec.ts".'),
|
|
65
|
-
steps: import_mcpBundle.z.array(import_mcpBundle.z.
|
|
66
|
-
|
|
65
|
+
steps: import_mcpBundle.z.array(import_mcpBundle.z.object({
|
|
66
|
+
perform: import_mcpBundle.z.string().optional().describe(`Action to perform. For example: 'Click on the "Submit" button'.`),
|
|
67
|
+
expect: import_mcpBundle.z.string().array().describe(`Expected result of the action where appropriate. For example: 'The page should show the "Thank you for your submission" message'`)
|
|
68
|
+
}))
|
|
67
69
|
}))
|
|
68
70
|
}))
|
|
69
71
|
});
|
|
@@ -118,12 +120,11 @@ const saveTestPlan = (0, import_testTool.defineTestTool)({
|
|
|
118
120
|
lines.push(`**File:** \`${test.file}\``);
|
|
119
121
|
lines.push(``);
|
|
120
122
|
lines.push(`**Steps:**`);
|
|
121
|
-
for (let k = 0; k < test.steps.length; k++)
|
|
122
|
-
lines.push(` ${k + 1}. ${test.steps[k]}`);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
lines.push(` - ${result}`);
|
|
123
|
+
for (let k = 0; k < test.steps.length; k++) {
|
|
124
|
+
lines.push(` ${k + 1}. ${test.steps[k].perform ?? "-"}`);
|
|
125
|
+
for (const expect of test.steps[k].expect)
|
|
126
|
+
lines.push(` - expect: ${expect}`);
|
|
127
|
+
}
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
lines.push(``);
|
|
@@ -172,7 +172,7 @@ class TestContext {
|
|
|
172
172
|
const { testRunner, screen, claimStdio, releaseStdio } = testRunnerAndScreen;
|
|
173
173
|
claimStdio();
|
|
174
174
|
try {
|
|
175
|
-
const setupReporter = new
|
|
175
|
+
const setupReporter = new MCPListReporter({ configDir, screen, includeTestId: true });
|
|
176
176
|
const { status: status2 } = await testRunner.runGlobalSetup([setupReporter]);
|
|
177
177
|
if (status2 !== "passed")
|
|
178
178
|
return { output: testRunnerAndScreen.output.join("\n"), status: status2 };
|
|
@@ -191,7 +191,7 @@ class TestContext {
|
|
|
191
191
|
}
|
|
192
192
|
};
|
|
193
193
|
try {
|
|
194
|
-
const reporter = new
|
|
194
|
+
const reporter = new MCPListReporter({ configDir, screen, includeTestId: true });
|
|
195
195
|
status = await Promise.race([
|
|
196
196
|
testRunner.runTests(reporter, params).then((result) => result.status),
|
|
197
197
|
testRunnerAndScreen.waitForTestPaused().then(() => "paused")
|
|
@@ -271,6 +271,12 @@ const bestPracticesMarkdown = `
|
|
|
271
271
|
- NEVER! use page.waitForTimeout()
|
|
272
272
|
- NEVER! use page.evaluate()
|
|
273
273
|
`;
|
|
274
|
+
class MCPListReporter extends import_list.default {
|
|
275
|
+
async onTestPaused() {
|
|
276
|
+
await new Promise(() => {
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
274
280
|
// Annotate the CommonJS export names for ESM import in node:
|
|
275
281
|
0 && (module.exports = {
|
|
276
282
|
GeneratorJournal,
|