playwright 1.54.1 → 1.56.1
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/README.md +3 -3
- package/ThirdPartyNotices.txt +2727 -434
- package/lib/agents/generateAgents.js +263 -0
- package/lib/agents/generator.md +102 -0
- package/lib/agents/healer.md +78 -0
- package/lib/agents/planner.md +135 -0
- package/lib/common/config.js +3 -1
- package/lib/common/configLoader.js +2 -1
- package/lib/common/expectBundle.js +3 -0
- package/lib/common/expectBundleImpl.js +51 -51
- package/lib/common/fixtures.js +1 -1
- package/lib/common/suiteUtils.js +0 -9
- package/lib/index.js +127 -115
- package/lib/isomorphic/testTree.js +35 -8
- package/lib/matchers/expect.js +6 -7
- package/lib/matchers/matcherHint.js +43 -15
- package/lib/matchers/matchers.js +10 -4
- package/lib/matchers/toBeTruthy.js +16 -14
- package/lib/matchers/toEqual.js +18 -13
- package/lib/matchers/toHaveURL.js +12 -27
- package/lib/matchers/toMatchAriaSnapshot.js +26 -31
- package/lib/matchers/toMatchSnapshot.js +15 -12
- package/lib/matchers/toMatchText.js +29 -35
- package/lib/mcp/browser/actions.d.js +16 -0
- package/lib/mcp/browser/browserContextFactory.js +296 -0
- package/lib/mcp/browser/browserServerBackend.js +76 -0
- package/lib/mcp/browser/codegen.js +66 -0
- package/lib/mcp/browser/config.js +383 -0
- package/lib/mcp/browser/context.js +284 -0
- package/lib/mcp/browser/response.js +228 -0
- package/lib/mcp/browser/sessionLog.js +160 -0
- package/lib/mcp/browser/tab.js +277 -0
- package/lib/mcp/browser/tools/common.js +63 -0
- package/lib/mcp/browser/tools/console.js +44 -0
- package/lib/mcp/browser/tools/dialogs.js +60 -0
- package/lib/mcp/browser/tools/evaluate.js +70 -0
- package/lib/mcp/browser/tools/files.js +58 -0
- package/lib/mcp/browser/tools/form.js +74 -0
- package/lib/mcp/browser/tools/install.js +69 -0
- package/lib/mcp/browser/tools/keyboard.js +85 -0
- package/lib/mcp/browser/tools/mouse.js +107 -0
- package/lib/mcp/browser/tools/navigate.js +62 -0
- package/lib/mcp/browser/tools/network.js +54 -0
- package/lib/mcp/browser/tools/pdf.js +59 -0
- package/lib/mcp/browser/tools/screenshot.js +88 -0
- package/lib/mcp/browser/tools/snapshot.js +182 -0
- package/lib/mcp/browser/tools/tabs.js +67 -0
- package/lib/mcp/browser/tools/tool.js +49 -0
- package/lib/mcp/browser/tools/tracing.js +74 -0
- package/lib/mcp/browser/tools/utils.js +100 -0
- package/lib/mcp/browser/tools/verify.js +154 -0
- package/lib/mcp/browser/tools/wait.js +63 -0
- package/lib/mcp/browser/tools.js +80 -0
- package/lib/mcp/browser/watchdog.js +44 -0
- package/lib/mcp/config.d.js +16 -0
- package/lib/mcp/extension/cdpRelay.js +351 -0
- package/lib/mcp/extension/extensionContextFactory.js +75 -0
- package/lib/mcp/extension/protocol.js +28 -0
- package/lib/mcp/index.js +61 -0
- package/lib/mcp/log.js +35 -0
- package/lib/mcp/program.js +96 -0
- package/lib/mcp/sdk/bundle.js +81 -0
- package/lib/mcp/sdk/exports.js +32 -0
- package/lib/mcp/sdk/http.js +180 -0
- package/lib/mcp/sdk/inProcessTransport.js +71 -0
- package/lib/mcp/sdk/mdb.js +208 -0
- package/lib/mcp/sdk/proxyBackend.js +128 -0
- package/lib/mcp/sdk/server.js +190 -0
- package/lib/mcp/sdk/tool.js +51 -0
- package/lib/mcp/test/browserBackend.js +98 -0
- package/lib/mcp/test/generatorTools.js +122 -0
- package/lib/mcp/test/plannerTools.js +46 -0
- package/lib/mcp/test/seed.js +72 -0
- package/lib/mcp/test/streams.js +39 -0
- package/lib/mcp/test/testBackend.js +97 -0
- package/lib/mcp/test/testContext.js +176 -0
- package/lib/mcp/test/testTool.js +30 -0
- package/lib/mcp/test/testTools.js +115 -0
- package/lib/mcpBundleImpl.js +41 -0
- package/lib/plugins/webServerPlugin.js +2 -0
- package/lib/program.js +77 -57
- package/lib/reporters/base.js +34 -29
- package/lib/reporters/dot.js +11 -11
- package/lib/reporters/github.js +2 -1
- package/lib/reporters/html.js +58 -41
- package/lib/reporters/internalReporter.js +2 -1
- package/lib/reporters/line.js +15 -15
- package/lib/reporters/list.js +24 -19
- package/lib/reporters/listModeReporter.js +69 -0
- package/lib/reporters/markdown.js +3 -3
- package/lib/reporters/merge.js +3 -1
- package/lib/reporters/teleEmitter.js +3 -1
- package/lib/runner/dispatcher.js +9 -2
- package/lib/runner/failureTracker.js +12 -2
- package/lib/runner/lastRun.js +7 -4
- package/lib/runner/loadUtils.js +46 -12
- package/lib/runner/projectUtils.js +8 -2
- package/lib/runner/reporters.js +7 -32
- package/lib/runner/tasks.js +20 -10
- package/lib/runner/testRunner.js +390 -0
- package/lib/runner/testServer.js +57 -276
- package/lib/runner/watchMode.js +5 -1
- package/lib/runner/workerHost.js +8 -6
- package/lib/transform/babelBundleImpl.js +179 -195
- package/lib/transform/compilationCache.js +22 -5
- package/lib/transform/transform.js +1 -1
- package/lib/util.js +12 -35
- package/lib/utilsBundleImpl.js +1 -1
- package/lib/worker/fixtureRunner.js +7 -2
- package/lib/worker/testInfo.js +76 -45
- package/lib/worker/testTracing.js +8 -7
- package/lib/worker/workerMain.js +12 -3
- package/package.json +10 -2
- package/types/test.d.ts +63 -44
- package/types/testReporter.d.ts +1 -1
- package/lib/runner/runner.js +0 -110
|
@@ -0,0 +1,81 @@
|
|
|
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 bundle_exports = {};
|
|
30
|
+
__export(bundle_exports, {
|
|
31
|
+
CallToolRequestSchema: () => CallToolRequestSchema,
|
|
32
|
+
Client: () => Client,
|
|
33
|
+
ListRootsRequestSchema: () => ListRootsRequestSchema,
|
|
34
|
+
ListToolsRequestSchema: () => ListToolsRequestSchema,
|
|
35
|
+
PingRequestSchema: () => PingRequestSchema,
|
|
36
|
+
ProgressNotificationSchema: () => ProgressNotificationSchema,
|
|
37
|
+
SSEClientTransport: () => SSEClientTransport,
|
|
38
|
+
SSEServerTransport: () => SSEServerTransport,
|
|
39
|
+
Server: () => Server,
|
|
40
|
+
StdioClientTransport: () => StdioClientTransport,
|
|
41
|
+
StdioServerTransport: () => StdioServerTransport,
|
|
42
|
+
StreamableHTTPClientTransport: () => StreamableHTTPClientTransport,
|
|
43
|
+
StreamableHTTPServerTransport: () => StreamableHTTPServerTransport,
|
|
44
|
+
z: () => z,
|
|
45
|
+
zodToJsonSchema: () => zodToJsonSchema
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(bundle_exports);
|
|
48
|
+
var bundle = __toESM(require("../../mcpBundleImpl"));
|
|
49
|
+
const zodToJsonSchema = bundle.zodToJsonSchema;
|
|
50
|
+
const Client = bundle.Client;
|
|
51
|
+
const Server = bundle.Server;
|
|
52
|
+
const SSEClientTransport = bundle.SSEClientTransport;
|
|
53
|
+
const SSEServerTransport = bundle.SSEServerTransport;
|
|
54
|
+
const StdioClientTransport = bundle.StdioClientTransport;
|
|
55
|
+
const StdioServerTransport = bundle.StdioServerTransport;
|
|
56
|
+
const StreamableHTTPServerTransport = bundle.StreamableHTTPServerTransport;
|
|
57
|
+
const StreamableHTTPClientTransport = bundle.StreamableHTTPClientTransport;
|
|
58
|
+
const CallToolRequestSchema = bundle.CallToolRequestSchema;
|
|
59
|
+
const ListRootsRequestSchema = bundle.ListRootsRequestSchema;
|
|
60
|
+
const ProgressNotificationSchema = bundle.ProgressNotificationSchema;
|
|
61
|
+
const ListToolsRequestSchema = bundle.ListToolsRequestSchema;
|
|
62
|
+
const PingRequestSchema = bundle.PingRequestSchema;
|
|
63
|
+
const z = bundle.z;
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
CallToolRequestSchema,
|
|
67
|
+
Client,
|
|
68
|
+
ListRootsRequestSchema,
|
|
69
|
+
ListToolsRequestSchema,
|
|
70
|
+
PingRequestSchema,
|
|
71
|
+
ProgressNotificationSchema,
|
|
72
|
+
SSEClientTransport,
|
|
73
|
+
SSEServerTransport,
|
|
74
|
+
Server,
|
|
75
|
+
StdioClientTransport,
|
|
76
|
+
StdioServerTransport,
|
|
77
|
+
StreamableHTTPClientTransport,
|
|
78
|
+
StreamableHTTPServerTransport,
|
|
79
|
+
z,
|
|
80
|
+
zodToJsonSchema
|
|
81
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var exports_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(exports_exports);
|
|
18
|
+
__reExport(exports_exports, require("./inProcessTransport"), module.exports);
|
|
19
|
+
__reExport(exports_exports, require("./proxyBackend"), module.exports);
|
|
20
|
+
__reExport(exports_exports, require("./server"), module.exports);
|
|
21
|
+
__reExport(exports_exports, require("./tool"), module.exports);
|
|
22
|
+
__reExport(exports_exports, require("./http"), module.exports);
|
|
23
|
+
__reExport(exports_exports, require("./mdb"), module.exports);
|
|
24
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
25
|
+
0 && (module.exports = {
|
|
26
|
+
...require("./inProcessTransport"),
|
|
27
|
+
...require("./proxyBackend"),
|
|
28
|
+
...require("./server"),
|
|
29
|
+
...require("./tool"),
|
|
30
|
+
...require("./http"),
|
|
31
|
+
...require("./mdb")
|
|
32
|
+
});
|
|
@@ -0,0 +1,180 @@
|
|
|
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 http_exports = {};
|
|
30
|
+
__export(http_exports, {
|
|
31
|
+
httpAddressToString: () => httpAddressToString,
|
|
32
|
+
installHttpTransport: () => installHttpTransport,
|
|
33
|
+
startHttpServer: () => startHttpServer
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(http_exports);
|
|
36
|
+
var import_assert = __toESM(require("assert"));
|
|
37
|
+
var import_http = __toESM(require("http"));
|
|
38
|
+
var import_crypto = __toESM(require("crypto"));
|
|
39
|
+
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
40
|
+
var mcpBundle = __toESM(require("./bundle"));
|
|
41
|
+
var mcpServer = __toESM(require("./server"));
|
|
42
|
+
const testDebug = (0, import_utilsBundle.debug)("pw:mcp:test");
|
|
43
|
+
async function startHttpServer(config, abortSignal) {
|
|
44
|
+
const { host, port } = config;
|
|
45
|
+
const httpServer = import_http.default.createServer();
|
|
46
|
+
decorateServer(httpServer);
|
|
47
|
+
await new Promise((resolve, reject) => {
|
|
48
|
+
httpServer.on("error", reject);
|
|
49
|
+
abortSignal?.addEventListener("abort", () => {
|
|
50
|
+
httpServer.close();
|
|
51
|
+
reject(new Error("Aborted"));
|
|
52
|
+
});
|
|
53
|
+
httpServer.listen(port, host, () => {
|
|
54
|
+
resolve();
|
|
55
|
+
httpServer.removeListener("error", reject);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
return httpServer;
|
|
59
|
+
}
|
|
60
|
+
function httpAddressToString(address) {
|
|
61
|
+
(0, import_assert.default)(address, "Could not bind server socket");
|
|
62
|
+
if (typeof address === "string")
|
|
63
|
+
return address;
|
|
64
|
+
const resolvedPort = address.port;
|
|
65
|
+
let resolvedHost = address.family === "IPv4" ? address.address : `[${address.address}]`;
|
|
66
|
+
if (resolvedHost === "0.0.0.0" || resolvedHost === "[::]")
|
|
67
|
+
resolvedHost = "localhost";
|
|
68
|
+
return `http://${resolvedHost}:${resolvedPort}`;
|
|
69
|
+
}
|
|
70
|
+
async function installHttpTransport(httpServer, serverBackendFactory, allowedHosts) {
|
|
71
|
+
const url = httpAddressToString(httpServer.address());
|
|
72
|
+
const host = new URL(url).host;
|
|
73
|
+
allowedHosts = (allowedHosts || [host]).map((h) => h.toLowerCase());
|
|
74
|
+
const allowAnyHost = allowedHosts.includes("*");
|
|
75
|
+
const sseSessions = /* @__PURE__ */ new Map();
|
|
76
|
+
const streamableSessions = /* @__PURE__ */ new Map();
|
|
77
|
+
httpServer.on("request", async (req, res) => {
|
|
78
|
+
if (!allowAnyHost) {
|
|
79
|
+
const host2 = req.headers.host?.toLowerCase();
|
|
80
|
+
if (!host2) {
|
|
81
|
+
res.statusCode = 400;
|
|
82
|
+
return res.end("Missing host");
|
|
83
|
+
}
|
|
84
|
+
if (!allowedHosts.includes(host2)) {
|
|
85
|
+
res.statusCode = 403;
|
|
86
|
+
return res.end("Access is only allowed at " + allowedHosts.join(", "));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const url2 = new URL(`http://localhost${req.url}`);
|
|
90
|
+
if (url2.pathname === "/killkillkill" && req.method === "GET") {
|
|
91
|
+
res.statusCode = 200;
|
|
92
|
+
res.end("Killing process");
|
|
93
|
+
process.emit("SIGINT");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (url2.pathname.startsWith("/sse"))
|
|
97
|
+
await handleSSE(serverBackendFactory, req, res, url2, sseSessions);
|
|
98
|
+
else
|
|
99
|
+
await handleStreamable(serverBackendFactory, req, res, streamableSessions);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
async function handleSSE(serverBackendFactory, req, res, url, sessions) {
|
|
103
|
+
if (req.method === "POST") {
|
|
104
|
+
const sessionId = url.searchParams.get("sessionId");
|
|
105
|
+
if (!sessionId) {
|
|
106
|
+
res.statusCode = 400;
|
|
107
|
+
return res.end("Missing sessionId");
|
|
108
|
+
}
|
|
109
|
+
const transport = sessions.get(sessionId);
|
|
110
|
+
if (!transport) {
|
|
111
|
+
res.statusCode = 404;
|
|
112
|
+
return res.end("Session not found");
|
|
113
|
+
}
|
|
114
|
+
return await transport.handlePostMessage(req, res);
|
|
115
|
+
} else if (req.method === "GET") {
|
|
116
|
+
const transport = new mcpBundle.SSEServerTransport("/sse", res);
|
|
117
|
+
sessions.set(transport.sessionId, transport);
|
|
118
|
+
testDebug(`create SSE session: ${transport.sessionId}`);
|
|
119
|
+
await mcpServer.connect(serverBackendFactory, transport, false);
|
|
120
|
+
res.on("close", () => {
|
|
121
|
+
testDebug(`delete SSE session: ${transport.sessionId}`);
|
|
122
|
+
sessions.delete(transport.sessionId);
|
|
123
|
+
});
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
res.statusCode = 405;
|
|
127
|
+
res.end("Method not allowed");
|
|
128
|
+
}
|
|
129
|
+
async function handleStreamable(serverBackendFactory, req, res, sessions) {
|
|
130
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
131
|
+
if (sessionId) {
|
|
132
|
+
const transport = sessions.get(sessionId);
|
|
133
|
+
if (!transport) {
|
|
134
|
+
res.statusCode = 404;
|
|
135
|
+
res.end("Session not found");
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
return await transport.handleRequest(req, res);
|
|
139
|
+
}
|
|
140
|
+
if (req.method === "POST") {
|
|
141
|
+
const transport = new mcpBundle.StreamableHTTPServerTransport({
|
|
142
|
+
sessionIdGenerator: () => import_crypto.default.randomUUID(),
|
|
143
|
+
onsessioninitialized: async (sessionId2) => {
|
|
144
|
+
testDebug(`create http session: ${transport.sessionId}`);
|
|
145
|
+
await mcpServer.connect(serverBackendFactory, transport, true);
|
|
146
|
+
sessions.set(sessionId2, transport);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
transport.onclose = () => {
|
|
150
|
+
if (!transport.sessionId)
|
|
151
|
+
return;
|
|
152
|
+
sessions.delete(transport.sessionId);
|
|
153
|
+
testDebug(`delete http session: ${transport.sessionId}`);
|
|
154
|
+
};
|
|
155
|
+
await transport.handleRequest(req, res);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
res.statusCode = 400;
|
|
159
|
+
res.end("Invalid request");
|
|
160
|
+
}
|
|
161
|
+
function decorateServer(server) {
|
|
162
|
+
const sockets = /* @__PURE__ */ new Set();
|
|
163
|
+
server.on("connection", (socket) => {
|
|
164
|
+
sockets.add(socket);
|
|
165
|
+
socket.once("close", () => sockets.delete(socket));
|
|
166
|
+
});
|
|
167
|
+
const close = server.close;
|
|
168
|
+
server.close = (callback) => {
|
|
169
|
+
for (const socket of sockets)
|
|
170
|
+
socket.destroy();
|
|
171
|
+
sockets.clear();
|
|
172
|
+
return close.call(server, callback);
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
176
|
+
0 && (module.exports = {
|
|
177
|
+
httpAddressToString,
|
|
178
|
+
installHttpTransport,
|
|
179
|
+
startHttpServer
|
|
180
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var inProcessTransport_exports = {};
|
|
20
|
+
__export(inProcessTransport_exports, {
|
|
21
|
+
InProcessTransport: () => InProcessTransport
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(inProcessTransport_exports);
|
|
24
|
+
class InProcessTransport {
|
|
25
|
+
constructor(server) {
|
|
26
|
+
this._connected = false;
|
|
27
|
+
this._server = server;
|
|
28
|
+
this._serverTransport = new InProcessServerTransport(this);
|
|
29
|
+
}
|
|
30
|
+
async start() {
|
|
31
|
+
if (this._connected)
|
|
32
|
+
throw new Error("InprocessTransport already started!");
|
|
33
|
+
await this._server.connect(this._serverTransport);
|
|
34
|
+
this._connected = true;
|
|
35
|
+
}
|
|
36
|
+
async send(message, options) {
|
|
37
|
+
if (!this._connected)
|
|
38
|
+
throw new Error("Transport not connected");
|
|
39
|
+
this._serverTransport._receiveFromClient(message);
|
|
40
|
+
}
|
|
41
|
+
async close() {
|
|
42
|
+
if (this._connected) {
|
|
43
|
+
this._connected = false;
|
|
44
|
+
this.onclose?.();
|
|
45
|
+
this._serverTransport.onclose?.();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
_receiveFromServer(message, extra) {
|
|
49
|
+
this.onmessage?.(message, extra);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
class InProcessServerTransport {
|
|
53
|
+
constructor(clientTransport) {
|
|
54
|
+
this._clientTransport = clientTransport;
|
|
55
|
+
}
|
|
56
|
+
async start() {
|
|
57
|
+
}
|
|
58
|
+
async send(message, options) {
|
|
59
|
+
this._clientTransport._receiveFromServer(message);
|
|
60
|
+
}
|
|
61
|
+
async close() {
|
|
62
|
+
this.onclose?.();
|
|
63
|
+
}
|
|
64
|
+
_receiveFromClient(message) {
|
|
65
|
+
this.onmessage?.(message);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
InProcessTransport
|
|
71
|
+
});
|
|
@@ -0,0 +1,208 @@
|
|
|
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 mdb_exports = {};
|
|
30
|
+
__export(mdb_exports, {
|
|
31
|
+
MDBBackend: () => MDBBackend,
|
|
32
|
+
runMainBackend: () => runMainBackend,
|
|
33
|
+
runOnPauseBackendLoop: () => runOnPauseBackendLoop
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(mdb_exports);
|
|
36
|
+
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
37
|
+
var import_utils = require("playwright-core/lib/utils");
|
|
38
|
+
var import_tool = require("./tool");
|
|
39
|
+
var mcpBundle = __toESM(require("./bundle"));
|
|
40
|
+
var mcpServer = __toESM(require("./server"));
|
|
41
|
+
var mcpHttp = __toESM(require("./http"));
|
|
42
|
+
const mdbDebug = (0, import_utilsBundle.debug)("pw:mcp:mdb");
|
|
43
|
+
const errorsDebug = (0, import_utilsBundle.debug)("pw:mcp:errors");
|
|
44
|
+
const z = mcpBundle.z;
|
|
45
|
+
class MDBBackend {
|
|
46
|
+
constructor(mainBackend) {
|
|
47
|
+
this._progress = [];
|
|
48
|
+
this._mainBackend = mainBackend;
|
|
49
|
+
this._progressCallback = (params) => {
|
|
50
|
+
if (params.message)
|
|
51
|
+
this._progress.push({ type: "text", text: params.message });
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async initialize(server, clientInfo) {
|
|
55
|
+
if (!this._clientInfo) {
|
|
56
|
+
this._clientInfo = clientInfo;
|
|
57
|
+
await this._mainBackend.initialize?.(server, clientInfo);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async listTools() {
|
|
61
|
+
return await this._mainBackend.listTools();
|
|
62
|
+
}
|
|
63
|
+
async callTool(name, args) {
|
|
64
|
+
if (name === pushToolsSchema.name) {
|
|
65
|
+
await this._createOnPauseClient(pushToolsSchema.inputSchema.parse(args || {}));
|
|
66
|
+
return { content: [{ type: "text", text: "Tools pushed" }] };
|
|
67
|
+
}
|
|
68
|
+
if (this._onPauseClient?.tools.find((tool) => tool.name === name)) {
|
|
69
|
+
const result2 = await this._onPauseClient.client.callTool({
|
|
70
|
+
name,
|
|
71
|
+
arguments: args
|
|
72
|
+
});
|
|
73
|
+
await this._mainBackend.afterCallTool?.(name, args, result2);
|
|
74
|
+
return result2;
|
|
75
|
+
}
|
|
76
|
+
await this._onPauseClient?.transport.terminateSession().catch(errorsDebug);
|
|
77
|
+
await this._onPauseClient?.client.close().catch(errorsDebug);
|
|
78
|
+
this._onPauseClient = void 0;
|
|
79
|
+
const resultPromise = new import_utils.ManualPromise();
|
|
80
|
+
const interruptPromise = new import_utils.ManualPromise();
|
|
81
|
+
this._interruptPromise = interruptPromise;
|
|
82
|
+
this._mainBackend.callTool(name, args, this._progressCallback).then((result2) => {
|
|
83
|
+
resultPromise.resolve(result2);
|
|
84
|
+
}).catch((e) => {
|
|
85
|
+
resultPromise.resolve({ content: [{ type: "text", text: String(e) }], isError: true });
|
|
86
|
+
});
|
|
87
|
+
const result = await Promise.race([interruptPromise, resultPromise]);
|
|
88
|
+
if (interruptPromise.isDone())
|
|
89
|
+
mdbDebug("client call intercepted", result);
|
|
90
|
+
else
|
|
91
|
+
mdbDebug("client call result", result);
|
|
92
|
+
result.content.unshift(...this._progress);
|
|
93
|
+
this._progress.length = 0;
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
async _createOnPauseClient(params) {
|
|
97
|
+
if (this._onPauseClient)
|
|
98
|
+
await this._onPauseClient.client.close().catch(errorsDebug);
|
|
99
|
+
this._onPauseClient = await this._createClient(params.mcpUrl);
|
|
100
|
+
this._interruptPromise?.resolve({
|
|
101
|
+
content: [{
|
|
102
|
+
type: "text",
|
|
103
|
+
text: params.introMessage || ""
|
|
104
|
+
}]
|
|
105
|
+
});
|
|
106
|
+
this._interruptPromise = void 0;
|
|
107
|
+
}
|
|
108
|
+
async _createClient(url) {
|
|
109
|
+
const client = new mcpBundle.Client({ name: "Interrupting client", version: "0.0.0" }, { capabilities: { roots: {} } });
|
|
110
|
+
client.setRequestHandler(mcpBundle.ListRootsRequestSchema, () => ({ roots: this._clientInfo?.roots || [] }));
|
|
111
|
+
client.setRequestHandler(mcpBundle.PingRequestSchema, () => ({}));
|
|
112
|
+
client.setNotificationHandler(mcpBundle.ProgressNotificationSchema, (notification) => {
|
|
113
|
+
if (notification.method === "notifications/progress") {
|
|
114
|
+
const { message } = notification.params;
|
|
115
|
+
if (message)
|
|
116
|
+
this._progress.push({ type: "text", text: message });
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
const transport = new mcpBundle.StreamableHTTPClientTransport(new URL(url));
|
|
120
|
+
await client.connect(transport);
|
|
121
|
+
const { tools } = await client.listTools();
|
|
122
|
+
return { client, tools, transport };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const pushToolsSchema = (0, import_tool.defineToolSchema)({
|
|
126
|
+
name: "mdb_push_tools",
|
|
127
|
+
title: "Push MCP tools to the tools stack",
|
|
128
|
+
description: "Push MCP tools to the tools stack",
|
|
129
|
+
inputSchema: z.object({
|
|
130
|
+
mcpUrl: z.string(),
|
|
131
|
+
introMessage: z.string().optional()
|
|
132
|
+
}),
|
|
133
|
+
type: "readOnly"
|
|
134
|
+
});
|
|
135
|
+
async function runMainBackend(backendFactory, options) {
|
|
136
|
+
const mdbBackend = new MDBBackend(backendFactory.create());
|
|
137
|
+
const factory = {
|
|
138
|
+
...backendFactory,
|
|
139
|
+
create: () => mdbBackend
|
|
140
|
+
};
|
|
141
|
+
const url = await startAsHttp(factory, { port: options?.port || 0 });
|
|
142
|
+
process.env.PLAYWRIGHT_DEBUGGER_MCP = url;
|
|
143
|
+
if (options?.port !== void 0)
|
|
144
|
+
return url;
|
|
145
|
+
await mcpServer.connect(factory, new mcpBundle.StdioServerTransport(), false);
|
|
146
|
+
}
|
|
147
|
+
async function runOnPauseBackendLoop(backend, introMessage) {
|
|
148
|
+
const wrappedBackend = new ServerBackendWithCloseListener(backend);
|
|
149
|
+
const factory = {
|
|
150
|
+
name: "on-pause-backend",
|
|
151
|
+
nameInConfig: "on-pause-backend",
|
|
152
|
+
version: "0.0.0",
|
|
153
|
+
create: () => wrappedBackend
|
|
154
|
+
};
|
|
155
|
+
const httpServer = await mcpHttp.startHttpServer({ port: 0 });
|
|
156
|
+
await mcpHttp.installHttpTransport(httpServer, factory);
|
|
157
|
+
const url = mcpHttp.httpAddressToString(httpServer.address());
|
|
158
|
+
const client = new mcpBundle.Client({ name: "Pushing client", version: "0.0.0" });
|
|
159
|
+
client.setRequestHandler(mcpBundle.PingRequestSchema, () => ({}));
|
|
160
|
+
const transport = new mcpBundle.StreamableHTTPClientTransport(new URL(process.env.PLAYWRIGHT_DEBUGGER_MCP));
|
|
161
|
+
await client.connect(transport);
|
|
162
|
+
const pushToolsResult = await client.callTool({
|
|
163
|
+
name: pushToolsSchema.name,
|
|
164
|
+
arguments: {
|
|
165
|
+
mcpUrl: url,
|
|
166
|
+
introMessage
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
if (pushToolsResult.isError)
|
|
170
|
+
errorsDebug("Failed to push tools", pushToolsResult.content);
|
|
171
|
+
await transport.terminateSession();
|
|
172
|
+
await client.close();
|
|
173
|
+
await wrappedBackend.waitForClosed();
|
|
174
|
+
httpServer.close();
|
|
175
|
+
}
|
|
176
|
+
async function startAsHttp(backendFactory, options) {
|
|
177
|
+
const httpServer = await mcpHttp.startHttpServer(options);
|
|
178
|
+
await mcpHttp.installHttpTransport(httpServer, backendFactory);
|
|
179
|
+
return mcpHttp.httpAddressToString(httpServer.address());
|
|
180
|
+
}
|
|
181
|
+
class ServerBackendWithCloseListener {
|
|
182
|
+
constructor(backend) {
|
|
183
|
+
this._serverClosedPromise = new import_utils.ManualPromise();
|
|
184
|
+
this._backend = backend;
|
|
185
|
+
}
|
|
186
|
+
async initialize(server, clientInfo) {
|
|
187
|
+
await this._backend.initialize?.(server, clientInfo);
|
|
188
|
+
}
|
|
189
|
+
async listTools() {
|
|
190
|
+
return this._backend.listTools();
|
|
191
|
+
}
|
|
192
|
+
async callTool(name, args, progress) {
|
|
193
|
+
return this._backend.callTool(name, args, progress);
|
|
194
|
+
}
|
|
195
|
+
serverClosed(server) {
|
|
196
|
+
this._backend.serverClosed?.(server);
|
|
197
|
+
this._serverClosedPromise.resolve();
|
|
198
|
+
}
|
|
199
|
+
async waitForClosed() {
|
|
200
|
+
await this._serverClosedPromise;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
204
|
+
0 && (module.exports = {
|
|
205
|
+
MDBBackend,
|
|
206
|
+
runMainBackend,
|
|
207
|
+
runOnPauseBackendLoop
|
|
208
|
+
});
|