playwright 1.58.0-alpha-2025-12-18 → 1.58.0-alpha-2025-12-19
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/index.js +10 -7
- package/lib/mcp/browser/browserContextFactory.js +12 -2
- package/lib/mcp/browser/config.js +4 -9
- package/lib/mcp/browser/tab.js +3 -5
- package/lib/mcp/browser/tools/utils.js +21 -0
- package/lib/mcp/extension/extensionContextFactory.js +1 -1
- package/lib/mcp/program.js +1 -24
- package/lib/mcp/sdk/exports.js +0 -2
- package/lib/runner/dispatcher.js +2 -2
- package/lib/runner/storage.js +31 -44
- package/lib/worker/testInfo.js +6 -4
- package/package.json +2 -2
- package/test.mjs +1 -0
- package/lib/mcp/sdk/proxyBackend.js +0 -128
package/lib/index.js
CHANGED
|
@@ -612,18 +612,21 @@ class ArtifactsRecorder {
|
|
|
612
612
|
if (!this._agent)
|
|
613
613
|
return;
|
|
614
614
|
const cachePathTemplate = this._agent.cachePathTemplate ?? "{testDir}/{testFilePath}-cache.json";
|
|
615
|
-
|
|
616
|
-
|
|
615
|
+
this._agentCacheFile = this._testInfo._applyPathTemplate(cachePathTemplate, "", ".json");
|
|
616
|
+
this._agentCacheOutFile = import_path.default.join(this._testInfo.artifactsDir(), "agent-cache-" + (0, import_utils.createGuid)() + ".json");
|
|
617
|
+
const cacheFile = this._testInfo.config.runAgents ? void 0 : await this._testInfo._cloneStorage(this._agentCacheFile);
|
|
617
618
|
options.agent = {
|
|
618
619
|
...this._agent,
|
|
619
|
-
cacheFile
|
|
620
|
-
|
|
620
|
+
cacheFile,
|
|
621
|
+
cacheOutFile: this._agentCacheOutFile
|
|
621
622
|
};
|
|
622
623
|
}
|
|
623
624
|
async _upstreamAgentCache(context) {
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
625
|
+
if (!this._agentCacheFile || !this._agentCacheOutFile)
|
|
626
|
+
return;
|
|
627
|
+
if (this._testInfo.status !== "passed")
|
|
628
|
+
return;
|
|
629
|
+
await this._testInfo._upstreamStorage(this._agentCacheFile, this._agentCacheOutFile);
|
|
627
630
|
}
|
|
628
631
|
async didCreateRequestContext(context) {
|
|
629
632
|
await this._startTraceChunkOnContextCreation(context, context._tracing);
|
|
@@ -134,7 +134,7 @@ class IsolatedContextFactory extends BaseContextFactory {
|
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
136
|
async _doCreateContext(browser) {
|
|
137
|
-
return browser.newContext(this.config
|
|
137
|
+
return browser.newContext(browserContextOptionsFromConfig(this.config));
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
class CdpContextFactory extends BaseContextFactory {
|
|
@@ -184,7 +184,7 @@ class PersistentContextFactory {
|
|
|
184
184
|
const launchOptions = {
|
|
185
185
|
tracesDir,
|
|
186
186
|
...this.config.browser.launchOptions,
|
|
187
|
-
...this.config
|
|
187
|
+
...browserContextOptionsFromConfig(this.config),
|
|
188
188
|
handleSIGINT: false,
|
|
189
189
|
handleSIGTERM: false,
|
|
190
190
|
ignoreDefaultArgs: [
|
|
@@ -303,6 +303,16 @@ async function computeTracesDir(config, clientInfo) {
|
|
|
303
303
|
return;
|
|
304
304
|
return await (0, import_config.outputFile)(config, clientInfo, `traces`, { origin: "code", reason: "Collecting trace" });
|
|
305
305
|
}
|
|
306
|
+
function browserContextOptionsFromConfig(config) {
|
|
307
|
+
const result = { ...config.browser.contextOptions };
|
|
308
|
+
if (config.saveVideo) {
|
|
309
|
+
result.recordVideo = {
|
|
310
|
+
dir: (0, import_config.tmpDir)(),
|
|
311
|
+
size: config.saveVideo
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
return result;
|
|
315
|
+
}
|
|
306
316
|
// Annotate the CommonJS export names for ESM import in node:
|
|
307
317
|
0 && (module.exports = {
|
|
308
318
|
SharedContextFactory,
|
|
@@ -40,7 +40,8 @@ __export(config_exports, {
|
|
|
40
40
|
resolutionParser: () => resolutionParser,
|
|
41
41
|
resolveCLIConfig: () => resolveCLIConfig,
|
|
42
42
|
resolveConfig: () => resolveConfig,
|
|
43
|
-
semicolonSeparatedList: () => semicolonSeparatedList
|
|
43
|
+
semicolonSeparatedList: () => semicolonSeparatedList,
|
|
44
|
+
tmpDir: () => tmpDir
|
|
44
45
|
});
|
|
45
46
|
module.exports = __toCommonJS(config_exports);
|
|
46
47
|
var import_fs = __toESM(require("fs"));
|
|
@@ -161,13 +162,6 @@ function configFromCLIOptions(cliOptions) {
|
|
|
161
162
|
contextOptions.serviceWorkers = "block";
|
|
162
163
|
if (cliOptions.grantPermissions)
|
|
163
164
|
contextOptions.permissions = cliOptions.grantPermissions;
|
|
164
|
-
if (cliOptions.saveVideo) {
|
|
165
|
-
contextOptions.recordVideo = {
|
|
166
|
-
// Videos are moved to output directory on saveAs.
|
|
167
|
-
dir: tmpDir(),
|
|
168
|
-
size: cliOptions.saveVideo
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
165
|
const result = {
|
|
172
166
|
browser: {
|
|
173
167
|
browserName,
|
|
@@ -419,5 +413,6 @@ function sanitizeForFilePath(s) {
|
|
|
419
413
|
resolutionParser,
|
|
420
414
|
resolveCLIConfig,
|
|
421
415
|
resolveConfig,
|
|
422
|
-
semicolonSeparatedList
|
|
416
|
+
semicolonSeparatedList,
|
|
417
|
+
tmpDir
|
|
423
418
|
});
|
package/lib/mcp/browser/tab.js
CHANGED
|
@@ -154,18 +154,16 @@ class Tab extends import_events.EventEmitter {
|
|
|
154
154
|
async navigate(url) {
|
|
155
155
|
await this._initializedPromise;
|
|
156
156
|
this._clearCollectedArtifacts();
|
|
157
|
-
const downloadEvent = (0, import_utils2.
|
|
157
|
+
const { promise: downloadEvent, abort: abortDownloadEvent } = (0, import_utils2.eventWaiter)(this.page, "download", 3e3);
|
|
158
158
|
try {
|
|
159
159
|
await this.page.goto(url, { waitUntil: "domcontentloaded" });
|
|
160
|
+
abortDownloadEvent();
|
|
160
161
|
} catch (_e) {
|
|
161
162
|
const e = _e;
|
|
162
163
|
const mightBeDownload = e.message.includes("net::ERR_ABORTED") || e.message.includes("Download is starting");
|
|
163
164
|
if (!mightBeDownload)
|
|
164
165
|
throw e;
|
|
165
|
-
const download = await
|
|
166
|
-
downloadEvent,
|
|
167
|
-
new Promise((resolve) => setTimeout(resolve, 3e3))
|
|
168
|
-
]);
|
|
166
|
+
const download = await downloadEvent;
|
|
169
167
|
if (!download)
|
|
170
168
|
throw e;
|
|
171
169
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
@@ -20,6 +20,7 @@ var utils_exports = {};
|
|
|
20
20
|
__export(utils_exports, {
|
|
21
21
|
callOnPageNoTrace: () => callOnPageNoTrace,
|
|
22
22
|
dateAsFileName: () => dateAsFileName,
|
|
23
|
+
eventWaiter: () => eventWaiter,
|
|
23
24
|
waitForCompletion: () => waitForCompletion
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -65,9 +66,29 @@ function dateAsFileName(extension) {
|
|
|
65
66
|
const date = /* @__PURE__ */ new Date();
|
|
66
67
|
return `page-${date.toISOString().replace(/[:.]/g, "-")}.${extension}`;
|
|
67
68
|
}
|
|
69
|
+
function eventWaiter(page, event, timeout) {
|
|
70
|
+
const disposables = [];
|
|
71
|
+
const eventPromise = new Promise((resolve, reject) => {
|
|
72
|
+
page.on(event, resolve);
|
|
73
|
+
disposables.push(() => page.off(event, resolve));
|
|
74
|
+
});
|
|
75
|
+
let abort;
|
|
76
|
+
const abortPromise = new Promise((resolve, reject) => {
|
|
77
|
+
abort = () => resolve(void 0);
|
|
78
|
+
});
|
|
79
|
+
const timeoutPromise = new Promise((f) => {
|
|
80
|
+
const timeoutId = setTimeout(() => f(void 0), timeout);
|
|
81
|
+
disposables.push(() => clearTimeout(timeoutId));
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
promise: Promise.race([eventPromise, abortPromise, timeoutPromise]).finally(() => disposables.forEach((dispose) => dispose())),
|
|
85
|
+
abort
|
|
86
|
+
};
|
|
87
|
+
}
|
|
68
88
|
// Annotate the CommonJS export names for ESM import in node:
|
|
69
89
|
0 && (module.exports = {
|
|
70
90
|
callOnPageNoTrace,
|
|
71
91
|
dateAsFileName,
|
|
92
|
+
eventWaiter,
|
|
72
93
|
waitForCompletion
|
|
73
94
|
});
|
|
@@ -55,7 +55,7 @@ class ExtensionContextFactory {
|
|
|
55
55
|
async _obtainBrowser(clientInfo, abortSignal, toolName) {
|
|
56
56
|
const relay = await this._startRelay(abortSignal);
|
|
57
57
|
await relay.ensureExtensionConnectionForMCPContext(clientInfo, abortSignal, toolName);
|
|
58
|
-
return await playwright.chromium.connectOverCDP(relay.cdpEndpoint());
|
|
58
|
+
return await playwright.chromium.connectOverCDP(relay.cdpEndpoint(), { isLocal: true });
|
|
59
59
|
}
|
|
60
60
|
async _startRelay(abortSignal) {
|
|
61
61
|
const httpServer = await (0, import_http.startHttpServer)({});
|
package/lib/mcp/program.js
CHANGED
|
@@ -38,11 +38,10 @@ var mcpServer = __toESM(require("./sdk/server"));
|
|
|
38
38
|
var import_config = require("./browser/config");
|
|
39
39
|
var import_watchdog = require("./browser/watchdog");
|
|
40
40
|
var import_browserContextFactory = require("./browser/browserContextFactory");
|
|
41
|
-
var import_proxyBackend = require("./sdk/proxyBackend");
|
|
42
41
|
var import_browserServerBackend = require("./browser/browserServerBackend");
|
|
43
42
|
var import_extensionContextFactory = require("./extension/extensionContextFactory");
|
|
44
43
|
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("--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("--
|
|
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) => {
|
|
46
45
|
(0, import_watchdog.setupExitWatchdog)();
|
|
47
46
|
if (options.vision) {
|
|
48
47
|
console.error("The --vision option is deprecated, use --caps=vision instead");
|
|
@@ -71,28 +70,6 @@ Please run the command below. It will install a local copy of ffmpeg and will no
|
|
|
71
70
|
await mcpServer.start(serverBackendFactory, config.server);
|
|
72
71
|
return;
|
|
73
72
|
}
|
|
74
|
-
if (options.connectTool) {
|
|
75
|
-
const providers = [
|
|
76
|
-
{
|
|
77
|
-
name: "default",
|
|
78
|
-
description: "Starts standalone browser",
|
|
79
|
-
connect: () => mcpServer.wrapInProcess(new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory))
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: "extension",
|
|
83
|
-
description: "Connect to a browser using the Playwright MCP extension",
|
|
84
|
-
connect: () => mcpServer.wrapInProcess(new import_browserServerBackend.BrowserServerBackend(config, extensionContextFactory))
|
|
85
|
-
}
|
|
86
|
-
];
|
|
87
|
-
const factory2 = {
|
|
88
|
-
name: "Playwright w/ switch",
|
|
89
|
-
nameInConfig: "playwright-switch",
|
|
90
|
-
version,
|
|
91
|
-
create: () => new import_proxyBackend.ProxyBackend(providers)
|
|
92
|
-
};
|
|
93
|
-
await mcpServer.start(factory2, config.server);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
73
|
const factory = {
|
|
97
74
|
name: "Playwright",
|
|
98
75
|
nameInConfig: "playwright",
|
package/lib/mcp/sdk/exports.js
CHANGED
|
@@ -16,14 +16,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var exports_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(exports_exports);
|
|
18
18
|
__reExport(exports_exports, require("./inProcessTransport"), module.exports);
|
|
19
|
-
__reExport(exports_exports, require("./proxyBackend"), module.exports);
|
|
20
19
|
__reExport(exports_exports, require("./server"), module.exports);
|
|
21
20
|
__reExport(exports_exports, require("./tool"), module.exports);
|
|
22
21
|
__reExport(exports_exports, require("./http"), module.exports);
|
|
23
22
|
// Annotate the CommonJS export names for ESM import in node:
|
|
24
23
|
0 && (module.exports = {
|
|
25
24
|
...require("./inProcessTransport"),
|
|
26
|
-
...require("./proxyBackend"),
|
|
27
25
|
...require("./server"),
|
|
28
26
|
...require("./tool"),
|
|
29
27
|
...require("./http")
|
package/lib/runner/dispatcher.js
CHANGED
|
@@ -199,10 +199,10 @@ class Dispatcher {
|
|
|
199
199
|
this._producedEnvByProjectId.set(testGroup.projectId, { ...producedEnv, ...worker.producedEnv() });
|
|
200
200
|
});
|
|
201
201
|
worker.onRequest("cloneStorage", async (params) => {
|
|
202
|
-
return await import_storage.Storage.clone(params.storageFile,
|
|
202
|
+
return await import_storage.Storage.clone(params.storageFile, outputDir);
|
|
203
203
|
});
|
|
204
204
|
worker.onRequest("upstreamStorage", async (params) => {
|
|
205
|
-
await import_storage.Storage.upstream(params.
|
|
205
|
+
await import_storage.Storage.upstream(params.storageFile, params.storageOutFile);
|
|
206
206
|
});
|
|
207
207
|
return worker;
|
|
208
208
|
}
|
package/lib/runner/storage.js
CHANGED
|
@@ -35,68 +35,55 @@ var import_fs = __toESM(require("fs"));
|
|
|
35
35
|
var import_path = __toESM(require("path"));
|
|
36
36
|
var import_utils = require("playwright-core/lib/utils");
|
|
37
37
|
class Storage {
|
|
38
|
-
constructor(fileName) {
|
|
39
|
-
this._writeChain = Promise.resolve();
|
|
40
|
-
this._fileName = fileName;
|
|
41
|
-
}
|
|
42
38
|
static {
|
|
43
39
|
this._storages = /* @__PURE__ */ new Map();
|
|
44
40
|
}
|
|
45
41
|
static {
|
|
46
|
-
this.
|
|
42
|
+
this._serializeQueue = Promise.resolve();
|
|
47
43
|
}
|
|
48
|
-
static
|
|
49
|
-
|
|
50
|
-
const stat = await import_fs.default.promises.stat(workerFile);
|
|
51
|
-
const lastModified = stat.mtime.getTime();
|
|
52
|
-
Storage._workerFiles.set(workerFile, { storageFile, lastModified });
|
|
53
|
-
return workerFile;
|
|
44
|
+
static clone(storageFile, outputDir) {
|
|
45
|
+
return Storage._withStorage(storageFile, (storage) => storage._clone(outputDir));
|
|
54
46
|
}
|
|
55
|
-
static
|
|
56
|
-
|
|
57
|
-
if (!entry)
|
|
58
|
-
return;
|
|
59
|
-
const { storageFile, lastModified } = entry;
|
|
60
|
-
const stat = await import_fs.default.promises.stat(workerFile);
|
|
61
|
-
const newLastModified = stat.mtime.getTime();
|
|
62
|
-
if (lastModified !== newLastModified)
|
|
63
|
-
await this._storage(storageFile)._upstream(workerFile);
|
|
64
|
-
Storage._workerFiles.delete(workerFile);
|
|
47
|
+
static upstream(storageFile, storageOutFile) {
|
|
48
|
+
return Storage._withStorage(storageFile, (storage) => storage._upstream(storageOutFile));
|
|
65
49
|
}
|
|
66
|
-
static
|
|
67
|
-
|
|
68
|
-
Storage._storages.
|
|
69
|
-
|
|
50
|
+
static _withStorage(fileName, runnable) {
|
|
51
|
+
this._serializeQueue = this._serializeQueue.then(() => {
|
|
52
|
+
let storage = Storage._storages.get(fileName);
|
|
53
|
+
if (!storage) {
|
|
54
|
+
storage = new Storage(fileName);
|
|
55
|
+
Storage._storages.set(fileName, storage);
|
|
56
|
+
}
|
|
57
|
+
return runnable(storage);
|
|
58
|
+
});
|
|
59
|
+
return this._serializeQueue;
|
|
70
60
|
}
|
|
71
|
-
|
|
61
|
+
constructor(fileName) {
|
|
62
|
+
this._fileName = fileName;
|
|
63
|
+
}
|
|
64
|
+
async _clone(outputDir) {
|
|
72
65
|
const entries = await this._load();
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
if (this._lastSnapshotFileName)
|
|
67
|
+
return this._lastSnapshotFileName;
|
|
68
|
+
const snapshotFile = import_path.default.join(outputDir, `pw-storage-${(0, import_utils.createGuid)()}.json`);
|
|
69
|
+
await import_fs.default.promises.writeFile(snapshotFile, JSON.stringify(entries, null, 2)).catch(() => {
|
|
75
70
|
});
|
|
76
|
-
|
|
71
|
+
this._lastSnapshotFileName = snapshotFile;
|
|
72
|
+
return snapshotFile;
|
|
77
73
|
}
|
|
78
|
-
async _upstream(
|
|
74
|
+
async _upstream(storageOutFile) {
|
|
79
75
|
const entries = await this._load();
|
|
80
|
-
const newEntries = await import_fs.default.promises.readFile(
|
|
81
|
-
for (const [key, newValue] of Object.entries(newEntries))
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
await this._writeFile(entries);
|
|
76
|
+
const newEntries = await import_fs.default.promises.readFile(storageOutFile, "utf8").then(JSON.parse).catch(() => ({}));
|
|
77
|
+
for (const [key, newValue] of Object.entries(newEntries))
|
|
78
|
+
entries[key] = newValue;
|
|
79
|
+
this._lastSnapshotFileName = void 0;
|
|
80
|
+
await import_fs.default.promises.writeFile(this._fileName, JSON.stringify(entries, null, 2));
|
|
87
81
|
}
|
|
88
82
|
async _load() {
|
|
89
83
|
if (!this._entriesPromise)
|
|
90
84
|
this._entriesPromise = import_fs.default.promises.readFile(this._fileName, "utf8").then(JSON.parse).catch(() => ({}));
|
|
91
85
|
return this._entriesPromise;
|
|
92
86
|
}
|
|
93
|
-
_writeFile(entries) {
|
|
94
|
-
this._writeChain = this._writeChain.then(() => import_fs.default.promises.writeFile(this._fileName, JSON.stringify(entries, null, 2)));
|
|
95
|
-
return this._writeChain;
|
|
96
|
-
}
|
|
97
|
-
async flush() {
|
|
98
|
-
await this._writeChain;
|
|
99
|
-
}
|
|
100
87
|
}
|
|
101
88
|
// Annotate the CommonJS export names for ESM import in node:
|
|
102
89
|
0 && (module.exports = {
|
package/lib/worker/testInfo.js
CHANGED
|
@@ -493,12 +493,14 @@ ${(0, import_utils.stringifyStackFrames)(step.boxedStack).join("\n")}`;
|
|
|
493
493
|
setTimeout(timeout) {
|
|
494
494
|
this._timeoutManager.setTimeout(timeout);
|
|
495
495
|
}
|
|
496
|
-
async _cloneStorage(
|
|
497
|
-
const storageFile = this._applyPathTemplate(cacheFileTemplate, "cache", ".json");
|
|
496
|
+
async _cloneStorage(storageFile) {
|
|
498
497
|
return await this._callbacks.onCloneStorage({ storageFile });
|
|
499
498
|
}
|
|
500
|
-
async _upstreamStorage(
|
|
501
|
-
await this._callbacks.onUpstreamStorage
|
|
499
|
+
async _upstreamStorage(storageFile, storageOutFile) {
|
|
500
|
+
await this._callbacks.onUpstreamStorage({ storageFile, storageOutFile });
|
|
501
|
+
}
|
|
502
|
+
artifactsDir() {
|
|
503
|
+
return this._workerParams.artifactsDir;
|
|
502
504
|
}
|
|
503
505
|
}
|
|
504
506
|
class TestStepInfoImpl {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playwright",
|
|
3
|
-
"version": "1.58.0-alpha-2025-12-
|
|
3
|
+
"version": "1.58.0-alpha-2025-12-19",
|
|
4
4
|
"description": "A high-level API to automate web browsers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"license": "Apache-2.0",
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"playwright-core": "1.58.0-alpha-2025-12-
|
|
67
|
+
"playwright-core": "1.58.0-alpha-2025-12-19"
|
|
68
68
|
},
|
|
69
69
|
"optionalDependencies": {
|
|
70
70
|
"fsevents": "2.3.2"
|
package/test.mjs
CHANGED
|
@@ -25,6 +25,7 @@ export const errors = playwright.errors;
|
|
|
25
25
|
export const request = playwright.request;
|
|
26
26
|
export const _electron = playwright._electron;
|
|
27
27
|
export const _android = playwright._android;
|
|
28
|
+
export const _baseTest = playwright._baseTest;
|
|
28
29
|
export const test = playwright.test;
|
|
29
30
|
export const expect = playwright.expect;
|
|
30
31
|
export const defineConfig = playwright.defineConfig;
|
|
@@ -1,128 +0,0 @@
|
|
|
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 proxyBackend_exports = {};
|
|
30
|
-
__export(proxyBackend_exports, {
|
|
31
|
-
ProxyBackend: () => ProxyBackend
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(proxyBackend_exports);
|
|
34
|
-
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
35
|
-
var mcpBundle = __toESM(require("playwright-core/lib/mcpBundle"));
|
|
36
|
-
const errorsDebug = (0, import_utilsBundle.debug)("pw:mcp:errors");
|
|
37
|
-
const { z, zodToJsonSchema } = mcpBundle;
|
|
38
|
-
class ProxyBackend {
|
|
39
|
-
constructor(mcpProviders) {
|
|
40
|
-
this._mcpProviders = mcpProviders;
|
|
41
|
-
this._contextSwitchTool = this._defineContextSwitchTool();
|
|
42
|
-
}
|
|
43
|
-
async initialize(clientInfo) {
|
|
44
|
-
this._clientInfo = clientInfo;
|
|
45
|
-
}
|
|
46
|
-
async listTools() {
|
|
47
|
-
const currentClient = await this._ensureCurrentClient();
|
|
48
|
-
const response = await currentClient.listTools();
|
|
49
|
-
if (this._mcpProviders.length === 1)
|
|
50
|
-
return response.tools;
|
|
51
|
-
return [
|
|
52
|
-
...response.tools,
|
|
53
|
-
this._contextSwitchTool
|
|
54
|
-
];
|
|
55
|
-
}
|
|
56
|
-
async callTool(name, args) {
|
|
57
|
-
if (name === this._contextSwitchTool.name)
|
|
58
|
-
return this._callContextSwitchTool(args);
|
|
59
|
-
const currentClient = await this._ensureCurrentClient();
|
|
60
|
-
return await currentClient.callTool({
|
|
61
|
-
name,
|
|
62
|
-
arguments: args
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
serverClosed() {
|
|
66
|
-
void this._currentClient?.close().catch(errorsDebug);
|
|
67
|
-
}
|
|
68
|
-
async _callContextSwitchTool(params) {
|
|
69
|
-
try {
|
|
70
|
-
const factory = this._mcpProviders.find((factory2) => factory2.name === params.name);
|
|
71
|
-
if (!factory)
|
|
72
|
-
throw new Error("Unknown connection method: " + params.name);
|
|
73
|
-
await this._setCurrentClient(factory);
|
|
74
|
-
return {
|
|
75
|
-
content: [{ type: "text", text: "### Result\nSuccessfully changed connection method.\n" }]
|
|
76
|
-
};
|
|
77
|
-
} catch (error) {
|
|
78
|
-
return {
|
|
79
|
-
content: [{ type: "text", text: `### Result
|
|
80
|
-
Error: ${error}
|
|
81
|
-
` }],
|
|
82
|
-
isError: true
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
_defineContextSwitchTool() {
|
|
87
|
-
return {
|
|
88
|
-
name: "browser_connect",
|
|
89
|
-
description: [
|
|
90
|
-
"Connect to a browser using one of the available methods:",
|
|
91
|
-
...this._mcpProviders.map((factory) => `- "${factory.name}": ${factory.description}`)
|
|
92
|
-
].join("\n"),
|
|
93
|
-
inputSchema: zodToJsonSchema(z.object({
|
|
94
|
-
name: z.enum(this._mcpProviders.map((factory) => factory.name)).default(this._mcpProviders[0].name).describe("The method to use to connect to the browser")
|
|
95
|
-
}), { strictUnions: true }),
|
|
96
|
-
annotations: {
|
|
97
|
-
title: "Connect to a browser context",
|
|
98
|
-
readOnlyHint: true,
|
|
99
|
-
openWorldHint: false
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
async _ensureCurrentClient() {
|
|
104
|
-
if (this._currentClient)
|
|
105
|
-
return this._currentClient;
|
|
106
|
-
return await this._setCurrentClient(this._mcpProviders[0]);
|
|
107
|
-
}
|
|
108
|
-
async _setCurrentClient(factory) {
|
|
109
|
-
await this._currentClient?.close();
|
|
110
|
-
this._currentClient = void 0;
|
|
111
|
-
const client = new mcpBundle.Client({ name: "Playwright MCP Proxy", version: "0.0.0" });
|
|
112
|
-
client.registerCapabilities({
|
|
113
|
-
roots: {
|
|
114
|
-
listRoots: true
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
client.setRequestHandler(mcpBundle.ListRootsRequestSchema, () => ({ roots: this._clientInfo?.roots || [] }));
|
|
118
|
-
client.setRequestHandler(mcpBundle.PingRequestSchema, () => ({}));
|
|
119
|
-
const transport = factory.connect();
|
|
120
|
-
await client.connect(transport);
|
|
121
|
-
this._currentClient = client;
|
|
122
|
-
return client;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
126
|
-
0 && (module.exports = {
|
|
127
|
-
ProxyBackend
|
|
128
|
-
});
|