patchright-bun-core 1.58.2 → 1.59.0
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/ThirdPartyNotices.txt +126 -650
- package/browsers.json +16 -14
- package/lib/bootstrap.js +77 -0
- package/lib/cli/browserActions.js +308 -0
- package/lib/cli/driver.js +3 -2
- package/lib/cli/installActions.js +171 -0
- package/lib/cli/program.js +47 -411
- package/lib/client/android.js +4 -4
- package/lib/client/api.js +3 -3
- package/lib/client/browser.js +8 -0
- package/lib/client/browserContext.js +18 -37
- package/lib/client/browserType.js +19 -51
- package/lib/client/cdpSession.js +6 -2
- package/lib/client/channelOwner.js +1 -1
- package/lib/client/{webSocket.js → connect.js} +57 -7
- package/lib/client/connection.js +8 -4
- package/lib/client/consoleMessage.js +3 -0
- package/lib/client/debugger.js +57 -0
- package/lib/client/dialog.js +8 -1
- package/lib/client/disposable.js +76 -0
- package/lib/client/electron.js +1 -0
- package/lib/client/elementHandle.js +1 -4
- package/lib/client/events.js +3 -3
- package/lib/client/fetch.js +0 -1
- package/lib/client/frame.js +0 -5
- package/lib/client/harRouter.js +13 -1
- package/lib/client/jsHandle.js +0 -4
- package/lib/client/locator.js +5 -7
- package/lib/client/network.js +14 -11
- package/lib/client/page.js +34 -48
- package/lib/client/platform.js +0 -3
- package/lib/client/screencast.js +88 -0
- package/lib/client/selectors.js +3 -1
- package/lib/client/tracing.js +11 -4
- package/lib/client/video.js +13 -20
- package/lib/generated/bindingsControllerSource.js +1 -1
- package/lib/generated/clockSource.js +1 -1
- package/lib/generated/injectedScriptSource.js +1 -1
- package/lib/generated/pollingRecorderSource.js +1 -1
- package/lib/generated/storageScriptSource.js +1 -1
- package/lib/generated/utilityScriptSource.js +1 -1
- package/lib/mcpBundle.js +0 -6
- package/lib/mcpBundleImpl.js +91 -0
- package/lib/protocol/validator.js +216 -118
- package/lib/protocol/validatorPrimitives.js +1 -1
- package/lib/remote/playwrightConnection.js +10 -8
- package/lib/remote/playwrightPipeServer.js +100 -0
- package/lib/remote/playwrightServer.js +13 -8
- package/lib/remote/playwrightWebSocketServer.js +73 -0
- package/lib/remote/serverTransport.js +96 -0
- package/lib/server/android/android.js +2 -2
- package/lib/server/bidi/bidiBrowser.js +30 -8
- package/lib/server/bidi/bidiChromium.js +18 -5
- package/lib/server/bidi/bidiNetworkManager.js +39 -11
- package/lib/server/bidi/bidiPage.js +31 -15
- package/lib/server/bidi/third_party/firefoxPrefs.js +3 -1
- package/lib/server/browser.js +84 -21
- package/lib/server/browserContext.js +97 -58
- package/lib/server/browserType.js +14 -12
- package/lib/server/chromium/chromium.js +15 -13
- package/lib/server/chromium/crBrowser.js +18 -10
- package/lib/server/chromium/crNetworkManager.js +4 -4
- package/lib/server/chromium/crPage.js +26 -64
- package/lib/server/chromium/crServiceWorker.js +5 -4
- package/lib/server/clock.js +33 -33
- package/lib/server/console.js +5 -1
- package/lib/server/debugController.js +12 -6
- package/lib/server/debugger.js +40 -47
- package/lib/server/deviceDescriptorsSource.json +137 -137
- package/lib/server/dispatchers/browserContextDispatcher.js +27 -30
- package/lib/server/dispatchers/browserDispatcher.js +11 -5
- package/lib/server/dispatchers/browserTypeDispatcher.js +7 -0
- package/lib/server/dispatchers/cdpSessionDispatcher.js +4 -1
- package/lib/server/dispatchers/debuggerDispatcher.js +84 -0
- package/lib/server/dispatchers/dispatcher.js +1 -1
- package/lib/server/dispatchers/disposableDispatcher.js +39 -0
- package/lib/server/dispatchers/electronDispatcher.js +2 -1
- package/lib/server/dispatchers/frameDispatcher.js +3 -3
- package/lib/server/dispatchers/localUtilsDispatcher.js +37 -1
- package/lib/server/dispatchers/networkDispatchers.js +6 -5
- package/lib/server/dispatchers/pageDispatcher.js +101 -38
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +4 -5
- package/lib/server/disposable.js +41 -0
- package/lib/server/dom.js +44 -26
- package/lib/server/download.js +3 -2
- package/lib/server/electron/electron.js +12 -7
- package/lib/server/firefox/ffBrowser.js +9 -19
- package/lib/server/firefox/ffInput.js +21 -5
- package/lib/server/firefox/ffNetworkManager.js +2 -2
- package/lib/server/firefox/ffPage.js +24 -27
- package/lib/server/frames.js +40 -11
- package/lib/server/har/harRecorder.js +2 -2
- package/lib/server/har/harTracer.js +5 -4
- package/lib/server/input.js +49 -4
- package/lib/server/instrumentation.js +5 -0
- package/lib/server/launchApp.js +0 -1
- package/lib/server/localUtils.js +6 -6
- package/lib/server/network.js +9 -8
- package/lib/server/overlay.js +138 -0
- package/lib/server/page.js +111 -51
- package/lib/server/progress.js +6 -0
- package/lib/server/recorder/recorderApp.js +9 -8
- package/lib/server/recorder.js +76 -40
- package/lib/server/registry/index.js +54 -81
- package/lib/server/registry/nativeDeps.js +1 -0
- package/lib/server/screencast.js +90 -143
- package/lib/server/trace/recorder/snapshotter.js +2 -2
- package/lib/server/trace/recorder/tracing.js +87 -36
- package/lib/server/trace/viewer/traceViewer.js +3 -4
- package/lib/server/usKeyboardLayout.js +7 -0
- package/lib/server/utils/comparators.js +1 -1
- package/lib/server/utils/disposable.js +32 -0
- package/lib/server/utils/eventsHelper.js +3 -1
- package/lib/server/utils/fileUtils.js +16 -2
- package/lib/server/utils/happyEyeballs.js +15 -12
- package/lib/server/utils/hostPlatform.js +0 -15
- package/lib/server/utils/httpServer.js +5 -3
- package/lib/server/utils/network.js +2 -1
- package/lib/server/utils/nodePlatform.js +0 -6
- package/lib/server/utils/processLauncher.js +8 -6
- package/lib/server/utils/zipFile.js +2 -2
- package/lib/server/videoRecorder.js +82 -12
- package/lib/server/webkit/wkBrowser.js +1 -6
- package/lib/server/webkit/wkPage.js +27 -25
- package/lib/server/webkit/wkWorkers.js +2 -1
- package/lib/serverRegistry.js +156 -0
- package/lib/tools/backend/browserBackend.js +79 -0
- package/lib/tools/backend/common.js +63 -0
- package/lib/tools/backend/config.js +41 -0
- package/lib/tools/backend/console.js +66 -0
- package/lib/tools/backend/context.js +296 -0
- package/lib/tools/backend/cookies.js +152 -0
- package/lib/tools/backend/devtools.js +69 -0
- package/lib/tools/backend/dialogs.js +59 -0
- package/lib/tools/backend/evaluate.js +64 -0
- package/lib/tools/backend/files.js +60 -0
- package/lib/tools/backend/form.js +64 -0
- package/lib/tools/backend/keyboard.js +155 -0
- package/lib/tools/backend/logFile.js +95 -0
- package/lib/tools/backend/mouse.js +168 -0
- package/lib/tools/backend/navigate.js +106 -0
- package/lib/tools/backend/network.js +135 -0
- package/lib/tools/backend/pdf.js +48 -0
- package/lib/tools/backend/response.js +305 -0
- package/lib/tools/backend/route.js +140 -0
- package/lib/tools/backend/runCode.js +77 -0
- package/lib/tools/backend/screenshot.js +88 -0
- package/lib/tools/backend/sessionLog.js +74 -0
- package/lib/tools/backend/snapshot.js +208 -0
- package/lib/tools/backend/storage.js +68 -0
- package/lib/tools/backend/tab.js +445 -0
- package/lib/tools/backend/tabs.js +67 -0
- package/lib/tools/backend/tool.js +47 -0
- package/lib/tools/backend/tools.js +102 -0
- package/lib/tools/backend/tracing.js +78 -0
- package/lib/tools/backend/utils.js +83 -0
- package/lib/tools/backend/verify.js +151 -0
- package/lib/tools/backend/video.js +98 -0
- package/lib/tools/backend/wait.js +63 -0
- package/lib/tools/backend/webstorage.js +223 -0
- package/lib/tools/cli-client/cli.js +6 -0
- package/lib/tools/cli-client/help.json +399 -0
- package/lib/tools/cli-client/minimist.js +128 -0
- package/lib/tools/cli-client/program.js +350 -0
- package/lib/tools/cli-client/registry.js +176 -0
- package/lib/tools/cli-client/session.js +289 -0
- package/lib/tools/cli-client/skill/SKILL.md +328 -0
- package/lib/tools/cli-client/skill/references/element-attributes.md +23 -0
- package/lib/tools/cli-client/skill/references/playwright-tests.md +39 -0
- package/lib/tools/cli-client/skill/references/request-mocking.md +87 -0
- package/lib/tools/cli-client/skill/references/running-code.md +231 -0
- package/lib/tools/cli-client/skill/references/session-management.md +169 -0
- package/lib/tools/cli-client/skill/references/storage-state.md +275 -0
- package/lib/tools/cli-client/skill/references/test-generation.md +88 -0
- package/lib/tools/cli-client/skill/references/tracing.md +139 -0
- package/lib/tools/cli-client/skill/references/video-recording.md +143 -0
- package/lib/tools/cli-daemon/command.js +73 -0
- package/lib/tools/cli-daemon/commands.js +956 -0
- package/lib/tools/cli-daemon/daemon.js +157 -0
- package/lib/tools/cli-daemon/helpGenerator.js +177 -0
- package/lib/tools/cli-daemon/program.js +129 -0
- package/lib/tools/dashboard/appIcon.png +0 -0
- package/lib/tools/dashboard/dashboardApp.js +284 -0
- package/lib/tools/dashboard/dashboardController.js +296 -0
- package/lib/tools/exports.js +60 -0
- package/lib/tools/mcp/browserFactory.js +233 -0
- package/lib/tools/mcp/cdpRelay.js +352 -0
- package/lib/tools/mcp/cli-stub.js +7 -0
- package/lib/tools/mcp/config.d.js +16 -0
- package/lib/tools/mcp/config.js +446 -0
- package/lib/tools/mcp/configIni.js +189 -0
- package/lib/tools/mcp/extensionContextFactory.js +55 -0
- package/lib/tools/mcp/index.js +62 -0
- package/lib/tools/mcp/log.js +35 -0
- package/lib/tools/mcp/program.js +107 -0
- package/lib/tools/mcp/protocol.js +28 -0
- package/lib/tools/mcp/watchdog.js +44 -0
- package/lib/tools/trace/SKILL.md +171 -0
- package/lib/{server/trace/viewer/traceParser.js → tools/trace/installSkill.js} +15 -39
- package/lib/tools/trace/traceActions.js +142 -0
- package/lib/tools/trace/traceAttachments.js +69 -0
- package/lib/tools/trace/traceCli.js +87 -0
- package/lib/tools/trace/traceConsole.js +97 -0
- package/lib/tools/trace/traceErrors.js +55 -0
- package/lib/tools/trace/traceOpen.js +69 -0
- package/lib/tools/trace/traceParser.js +96 -0
- package/lib/tools/trace/traceRequests.js +182 -0
- package/lib/tools/trace/traceScreenshot.js +68 -0
- package/lib/tools/trace/traceSnapshot.js +149 -0
- package/lib/tools/trace/traceUtils.js +153 -0
- package/lib/tools/utils/connect.js +32 -0
- package/lib/tools/utils/mcp/http.js +152 -0
- package/lib/tools/utils/mcp/server.js +230 -0
- package/lib/tools/utils/mcp/tool.js +47 -0
- package/lib/tools/utils/socketConnection.js +108 -0
- package/lib/utils/isomorphic/formatUtils.js +64 -0
- package/lib/utils/isomorphic/jsonSchema.js +89 -0
- package/lib/utils/isomorphic/mimeType.js +7 -2
- package/lib/utils/isomorphic/protocolFormatter.js +2 -2
- package/lib/utils/isomorphic/protocolMetainfo.js +127 -106
- package/lib/utils/isomorphic/stringUtils.js +3 -3
- package/lib/utils/isomorphic/timeoutRunner.js +3 -3
- package/lib/utils/isomorphic/trace/snapshotRenderer.js +35 -42
- package/lib/utils/isomorphic/trace/traceLoader.js +15 -14
- package/lib/utils/isomorphic/trace/traceModel.js +3 -2
- package/lib/utils/isomorphic/trace/traceModernizer.js +1 -0
- package/lib/utils/isomorphic/urlMatch.js +54 -1
- package/lib/utils/isomorphic/utilityScriptSerializers.js +11 -0
- package/lib/utils.js +6 -2
- package/lib/utilsBundle.js +3 -21
- package/lib/utilsBundleImpl/index.js +132 -133
- package/lib/vite/dashboard/assets/index-BAOybkp8.js +50 -0
- package/lib/vite/dashboard/assets/index-CZAYOG76.css +1 -0
- package/lib/vite/dashboard/index.html +28 -0
- package/lib/vite/htmlReport/index.html +2 -70
- package/lib/vite/htmlReport/report.css +1 -0
- package/lib/vite/htmlReport/report.js +72 -0
- package/lib/vite/recorder/assets/{codeMirrorModule-DadYNm1I.js → codeMirrorModule-C8KMvO9L.js} +20 -20
- package/lib/vite/recorder/assets/index-CqAYX1I3.js +193 -0
- package/lib/vite/recorder/index.html +1 -1
- package/lib/vite/traceViewer/assets/{codeMirrorModule-a5XoALAZ.js → codeMirrorModule-DS0FLvoc.js} +20 -20
- package/lib/vite/traceViewer/assets/defaultSettingsView-GTWI-W_B.js +262 -0
- package/lib/vite/traceViewer/defaultSettingsView.B4dS75f0.css +1 -0
- package/lib/vite/traceViewer/{index.BVu7tZDe.css → index.CzXZzn5A.css} +1 -1
- package/lib/vite/traceViewer/{index.BDwrLSGN.js → index.Dtstcb7U.js} +1 -1
- package/lib/vite/traceViewer/index.html +4 -4
- package/lib/vite/traceViewer/sw.bundle.js +4 -4
- package/lib/vite/traceViewer/uiMode.Vipi55dB.js +6 -0
- package/lib/vite/traceViewer/uiMode.html +3 -3
- package/lib/zipBundleImpl.js +2 -2
- package/lib/zodBundle.js +39 -0
- package/lib/zodBundleImpl.js +40 -0
- package/package.json +6 -1
- package/types/protocol.d.ts +947 -51
- package/types/types.d.ts +854 -74
- package/lib/client/pageAgent.js +0 -64
- package/lib/mcpBundleImpl/index.js +0 -147
- package/lib/server/agent/actionRunner.js +0 -335
- package/lib/server/agent/actions.js +0 -128
- package/lib/server/agent/codegen.js +0 -111
- package/lib/server/agent/context.js +0 -150
- package/lib/server/agent/expectTools.js +0 -156
- package/lib/server/agent/pageAgent.js +0 -204
- package/lib/server/agent/performTools.js +0 -262
- package/lib/server/agent/tool.js +0 -109
- package/lib/server/dispatchers/pageAgentDispatcher.js +0 -96
- package/lib/vite/recorder/assets/index-BhTWtUlo.js +0 -193
- package/lib/vite/traceViewer/assets/defaultSettingsView-CJSZINFr.js +0 -266
- package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +0 -1
- package/lib/vite/traceViewer/uiMode.CQJ9SCIQ.js +0 -5
- /package/lib/{server/utils → utils/isomorphic}/imageUtils.js +0 -0
- /package/lib/utils/isomorphic/{traceUtils.js → trace/traceUtils.js} +0 -0
|
@@ -0,0 +1,157 @@
|
|
|
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 daemon_exports = {};
|
|
30
|
+
__export(daemon_exports, {
|
|
31
|
+
startCliDaemonServer: () => startCliDaemonServer
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(daemon_exports);
|
|
34
|
+
var import_fs = __toESM(require("fs"));
|
|
35
|
+
var import_net = __toESM(require("net"));
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_network = require("../../server/utils/network");
|
|
38
|
+
var import_fileUtils = require("../../server/utils/fileUtils");
|
|
39
|
+
var import_processLauncher = require("../../server/utils/processLauncher");
|
|
40
|
+
var import_browserBackend = require("../backend/browserBackend");
|
|
41
|
+
var import_tools = require("../backend/tools");
|
|
42
|
+
var import_command = require("./command");
|
|
43
|
+
var import_commands = require("./commands");
|
|
44
|
+
var import_socketConnection = require("../utils/socketConnection");
|
|
45
|
+
var import_registry = require("../cli-client/registry");
|
|
46
|
+
async function socketExists(socketPath) {
|
|
47
|
+
try {
|
|
48
|
+
const stat = await import_fs.default.promises.stat(socketPath);
|
|
49
|
+
if (stat?.isSocket())
|
|
50
|
+
return true;
|
|
51
|
+
} catch (e) {
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
async function startCliDaemonServer(sessionName, browserContext, browserInfo, contextConfig = {}, clientInfo = (0, import_registry.createClientInfo)(), options) {
|
|
56
|
+
const sessionConfig = createSessionConfig(clientInfo, sessionName, browserInfo, options);
|
|
57
|
+
const { socketPath } = sessionConfig;
|
|
58
|
+
if (process.platform !== "win32" && await socketExists(socketPath)) {
|
|
59
|
+
try {
|
|
60
|
+
await import_fs.default.promises.unlink(socketPath);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const backend = new import_browserBackend.BrowserBackend(contextConfig, browserContext, import_tools.browserTools);
|
|
66
|
+
await backend.initialize({ cwd: process.cwd() });
|
|
67
|
+
if (browserContext.isClosed())
|
|
68
|
+
throw new Error("Browser context was closed before the daemon could start");
|
|
69
|
+
const server = import_net.default.createServer((socket) => {
|
|
70
|
+
const connection = new import_socketConnection.SocketConnection(socket);
|
|
71
|
+
connection.onmessage = async (message) => {
|
|
72
|
+
const { id, method, params } = message;
|
|
73
|
+
try {
|
|
74
|
+
if (method === "stop") {
|
|
75
|
+
await deleteSessionFile(clientInfo, sessionConfig);
|
|
76
|
+
const sendAck = async () => connection.send({ id, result: "ok" }).catch(() => {
|
|
77
|
+
});
|
|
78
|
+
if (options?.exitOnClose)
|
|
79
|
+
(0, import_processLauncher.gracefullyProcessExitDoNotHang)(0, () => sendAck());
|
|
80
|
+
else
|
|
81
|
+
await sendAck();
|
|
82
|
+
} else if (method === "run") {
|
|
83
|
+
const { toolName, toolParams } = parseCliCommand(params.args);
|
|
84
|
+
if (params.cwd)
|
|
85
|
+
toolParams._meta = { cwd: params.cwd };
|
|
86
|
+
const response = await backend.callTool(toolName, toolParams);
|
|
87
|
+
await connection.send({ id, result: formatResult(response) });
|
|
88
|
+
} else {
|
|
89
|
+
throw new Error(`Unknown method: ${method}`);
|
|
90
|
+
}
|
|
91
|
+
} catch (e) {
|
|
92
|
+
const error = process.env.PWDEBUGIMPL ? e.stack || e.message : e.message;
|
|
93
|
+
connection.send({ id, error }).catch(() => {
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
(0, import_network.decorateServer)(server);
|
|
99
|
+
browserContext.on("close", () => Promise.resolve().then(async () => {
|
|
100
|
+
await deleteSessionFile(clientInfo, sessionConfig);
|
|
101
|
+
if (options?.exitOnClose)
|
|
102
|
+
(0, import_processLauncher.gracefullyProcessExitDoNotHang)(0);
|
|
103
|
+
}));
|
|
104
|
+
await new Promise((resolve, reject) => {
|
|
105
|
+
server.on("error", reject);
|
|
106
|
+
server.listen(socketPath, () => resolve());
|
|
107
|
+
});
|
|
108
|
+
await saveSessionFile(clientInfo, sessionConfig);
|
|
109
|
+
return socketPath;
|
|
110
|
+
}
|
|
111
|
+
async function saveSessionFile(clientInfo, sessionConfig) {
|
|
112
|
+
await import_fs.default.promises.mkdir(clientInfo.daemonProfilesDir, { recursive: true });
|
|
113
|
+
const sessionFile = import_path.default.join(clientInfo.daemonProfilesDir, `${sessionConfig.name}.session`);
|
|
114
|
+
await import_fs.default.promises.writeFile(sessionFile, JSON.stringify(sessionConfig, null, 2));
|
|
115
|
+
}
|
|
116
|
+
async function deleteSessionFile(clientInfo, sessionConfig) {
|
|
117
|
+
await import_fs.default.promises.unlink(sessionConfig.socketPath).catch(() => {
|
|
118
|
+
});
|
|
119
|
+
if (!sessionConfig.cli.persistent) {
|
|
120
|
+
const sessionFile = import_path.default.join(clientInfo.daemonProfilesDir, `${sessionConfig.name}.session`);
|
|
121
|
+
await import_fs.default.promises.rm(sessionFile).catch(() => {
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function formatResult(result) {
|
|
126
|
+
const isError = result.isError;
|
|
127
|
+
const text = result.content[0].type === "text" ? result.content[0].text : void 0;
|
|
128
|
+
return { isError, text };
|
|
129
|
+
}
|
|
130
|
+
function parseCliCommand(args) {
|
|
131
|
+
const command = import_commands.commands[args._[0]];
|
|
132
|
+
if (!command)
|
|
133
|
+
throw new Error("Command is required");
|
|
134
|
+
return (0, import_command.parseCommand)(command, args);
|
|
135
|
+
}
|
|
136
|
+
function daemonSocketPath(clientInfo, sessionName) {
|
|
137
|
+
return (0, import_fileUtils.makeSocketPath)("cli", `${clientInfo.workspaceDirHash}-${sessionName}`);
|
|
138
|
+
}
|
|
139
|
+
function createSessionConfig(clientInfo, sessionName, browserInfo, options = {}) {
|
|
140
|
+
return {
|
|
141
|
+
name: sessionName,
|
|
142
|
+
version: clientInfo.version,
|
|
143
|
+
timestamp: Date.now(),
|
|
144
|
+
socketPath: daemonSocketPath(clientInfo, sessionName),
|
|
145
|
+
workspaceDir: clientInfo.workspaceDir,
|
|
146
|
+
cli: { persistent: options.persistent },
|
|
147
|
+
browser: {
|
|
148
|
+
browserName: browserInfo.browserName,
|
|
149
|
+
launchOptions: browserInfo.launchOptions,
|
|
150
|
+
userDataDir: browserInfo.userDataDir
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
+
0 && (module.exports = {
|
|
156
|
+
startCliDaemonServer
|
|
157
|
+
});
|
|
@@ -0,0 +1,177 @@
|
|
|
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 helpGenerator_exports = {};
|
|
20
|
+
__export(helpGenerator_exports, {
|
|
21
|
+
generateHelp: () => generateHelp,
|
|
22
|
+
generateHelpJSON: () => generateHelpJSON,
|
|
23
|
+
generateReadme: () => generateReadme
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(helpGenerator_exports);
|
|
26
|
+
var import_zodBundle = require("../../zodBundle");
|
|
27
|
+
var import_commands = require("./commands");
|
|
28
|
+
function commandArgs(command) {
|
|
29
|
+
const args = [];
|
|
30
|
+
const shape = command.args ? command.args.shape : {};
|
|
31
|
+
for (const [name, schema] of Object.entries(shape)) {
|
|
32
|
+
const zodSchema = schema;
|
|
33
|
+
const description = zodSchema.description ?? "";
|
|
34
|
+
args.push({ name, description, optional: zodSchema.safeParse(void 0).success });
|
|
35
|
+
}
|
|
36
|
+
return args;
|
|
37
|
+
}
|
|
38
|
+
function commandArgsText(args) {
|
|
39
|
+
return args.map((a) => a.optional ? `[${a.name}]` : `<${a.name}>`).join(" ");
|
|
40
|
+
}
|
|
41
|
+
function generateCommandHelp(command) {
|
|
42
|
+
const args = commandArgs(command);
|
|
43
|
+
const lines = [
|
|
44
|
+
`playwright-cli ${command.name} ${commandArgsText(args)}`,
|
|
45
|
+
"",
|
|
46
|
+
command.description,
|
|
47
|
+
""
|
|
48
|
+
];
|
|
49
|
+
if (args.length) {
|
|
50
|
+
lines.push("Arguments:");
|
|
51
|
+
lines.push(...args.map((a) => formatWithGap(` ${a.optional ? `[${a.name}]` : `<${a.name}>`}`, a.description.toLowerCase())));
|
|
52
|
+
}
|
|
53
|
+
if (command.options) {
|
|
54
|
+
lines.push("Options:");
|
|
55
|
+
const optionsShape = command.options.shape;
|
|
56
|
+
for (const [name, schema] of Object.entries(optionsShape)) {
|
|
57
|
+
const zodSchema = schema;
|
|
58
|
+
const description = (zodSchema.description ?? "").toLowerCase();
|
|
59
|
+
lines.push(formatWithGap(` --${name}`, description));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return lines.join("\n");
|
|
63
|
+
}
|
|
64
|
+
const categories = [
|
|
65
|
+
{ name: "core", title: "Core" },
|
|
66
|
+
{ name: "navigation", title: "Navigation" },
|
|
67
|
+
{ name: "keyboard", title: "Keyboard" },
|
|
68
|
+
{ name: "mouse", title: "Mouse" },
|
|
69
|
+
{ name: "export", title: "Save as" },
|
|
70
|
+
{ name: "tabs", title: "Tabs" },
|
|
71
|
+
{ name: "storage", title: "Storage" },
|
|
72
|
+
{ name: "network", title: "Network" },
|
|
73
|
+
{ name: "devtools", title: "DevTools" },
|
|
74
|
+
{ name: "install", title: "Install" },
|
|
75
|
+
{ name: "config", title: "Configuration" },
|
|
76
|
+
{ name: "browsers", title: "Browser sessions" }
|
|
77
|
+
];
|
|
78
|
+
function generateHelp() {
|
|
79
|
+
const lines = [];
|
|
80
|
+
lines.push("Usage: playwright-cli <command> [args] [options]");
|
|
81
|
+
lines.push("Usage: playwright-cli -s=<session> <command> [args] [options]");
|
|
82
|
+
const commandsByCategory = /* @__PURE__ */ new Map();
|
|
83
|
+
for (const c of categories)
|
|
84
|
+
commandsByCategory.set(c.name, []);
|
|
85
|
+
for (const command of Object.values(import_commands.commands)) {
|
|
86
|
+
if (command.hidden)
|
|
87
|
+
continue;
|
|
88
|
+
commandsByCategory.get(command.category).push(command);
|
|
89
|
+
}
|
|
90
|
+
for (const c of categories) {
|
|
91
|
+
const cc = commandsByCategory.get(c.name);
|
|
92
|
+
if (!cc.length)
|
|
93
|
+
continue;
|
|
94
|
+
lines.push(`
|
|
95
|
+
${c.title}:`);
|
|
96
|
+
for (const command of cc)
|
|
97
|
+
lines.push(generateHelpEntry(command));
|
|
98
|
+
}
|
|
99
|
+
lines.push("\nGlobal options:");
|
|
100
|
+
lines.push(formatWithGap(" --help [command]", "print help"));
|
|
101
|
+
lines.push(formatWithGap(" --version", "print version"));
|
|
102
|
+
return lines.join("\n");
|
|
103
|
+
}
|
|
104
|
+
function generateReadme() {
|
|
105
|
+
const lines = [];
|
|
106
|
+
lines.push("\n## Commands");
|
|
107
|
+
const commandsByCategory = /* @__PURE__ */ new Map();
|
|
108
|
+
for (const c of categories)
|
|
109
|
+
commandsByCategory.set(c.name, []);
|
|
110
|
+
for (const command of Object.values(import_commands.commands))
|
|
111
|
+
commandsByCategory.get(command.category).push(command);
|
|
112
|
+
for (const c of categories) {
|
|
113
|
+
const cc = commandsByCategory.get(c.name);
|
|
114
|
+
if (!cc.length)
|
|
115
|
+
continue;
|
|
116
|
+
lines.push(`
|
|
117
|
+
### ${c.title}
|
|
118
|
+
`);
|
|
119
|
+
lines.push("```bash");
|
|
120
|
+
for (const command of cc)
|
|
121
|
+
lines.push(generateReadmeEntry(command));
|
|
122
|
+
lines.push("```");
|
|
123
|
+
}
|
|
124
|
+
return lines.join("\n");
|
|
125
|
+
}
|
|
126
|
+
function generateHelpEntry(command) {
|
|
127
|
+
const args = commandArgs(command);
|
|
128
|
+
const prefix = ` ${command.name} ${commandArgsText(args)}`;
|
|
129
|
+
const suffix = command.description.toLowerCase();
|
|
130
|
+
return formatWithGap(prefix, suffix);
|
|
131
|
+
}
|
|
132
|
+
function generateReadmeEntry(command) {
|
|
133
|
+
const args = commandArgs(command);
|
|
134
|
+
const prefix = `playwright-cli ${command.name} ${commandArgsText(args)}`;
|
|
135
|
+
const suffix = "# " + command.description.toLowerCase();
|
|
136
|
+
return formatWithGap(prefix, suffix, 40);
|
|
137
|
+
}
|
|
138
|
+
function unwrapZodType(schema) {
|
|
139
|
+
if ("unwrap" in schema && typeof schema.unwrap === "function")
|
|
140
|
+
return unwrapZodType(schema.unwrap());
|
|
141
|
+
return schema;
|
|
142
|
+
}
|
|
143
|
+
function isBooleanSchema(schema) {
|
|
144
|
+
return unwrapZodType(schema) instanceof import_zodBundle.z.ZodBoolean;
|
|
145
|
+
}
|
|
146
|
+
function generateHelpJSON() {
|
|
147
|
+
const booleanOptions = /* @__PURE__ */ new Set();
|
|
148
|
+
const commandEntries = {};
|
|
149
|
+
for (const [name, command] of Object.entries(import_commands.commands)) {
|
|
150
|
+
const flags = {};
|
|
151
|
+
if (command.options) {
|
|
152
|
+
const optionsShape = command.options.shape;
|
|
153
|
+
for (const [flagName, schema] of Object.entries(optionsShape)) {
|
|
154
|
+
const isBoolean = isBooleanSchema(schema);
|
|
155
|
+
flags[flagName] = isBoolean ? "boolean" : "string";
|
|
156
|
+
if (isBoolean)
|
|
157
|
+
booleanOptions.add(flagName);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
commandEntries[name] = { help: generateCommandHelp(command), flags };
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
global: generateHelp(),
|
|
164
|
+
commands: commandEntries,
|
|
165
|
+
booleanOptions: [...booleanOptions]
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function formatWithGap(prefix, text, threshold = 30) {
|
|
169
|
+
const indent = Math.max(1, threshold - prefix.length);
|
|
170
|
+
return prefix + " ".repeat(indent) + text;
|
|
171
|
+
}
|
|
172
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
173
|
+
0 && (module.exports = {
|
|
174
|
+
generateHelp,
|
|
175
|
+
generateHelpJSON,
|
|
176
|
+
generateReadme
|
|
177
|
+
});
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var import_fs = __toESM(require("fs"));
|
|
25
|
+
var import_os = __toESM(require("os"));
|
|
26
|
+
var import_path = __toESM(require("path"));
|
|
27
|
+
var import_daemon = require("./daemon");
|
|
28
|
+
var import_watchdog = require("../mcp/watchdog");
|
|
29
|
+
var import_browserFactory = require("../mcp/browserFactory");
|
|
30
|
+
var configUtils = __toESM(require("../mcp/config"));
|
|
31
|
+
var import_registry = require("../cli-client/registry");
|
|
32
|
+
var import_utilsBundle = require("../../utilsBundle");
|
|
33
|
+
var import_registry2 = require("../../server/registry/index");
|
|
34
|
+
import_utilsBundle.program.argument("[session-name]", "name of the session to create or connect to", "default").option("--headed", "run in headed mode (non-headless)").option("--extension", "run with the extension").option("--browser <name>", "browser to use (chromium, chrome, firefox, webkit)").option("--persistent", "use a persistent browser context").option("--profile <path>", "path to the user data dir").option("--config <path>", "path to the config file; by default uses .playwright/cli.config.json in the project directory and ~/.playwright/cli.config.json as global config").option("--endpoint <endpoint>", "attach to a running Playwright browser endpoint").option("--init-workspace", "initialize workspace").option("--init-skills <value>", 'install skills for the given agent type ("claude" or "agents")').action(async (sessionName, options) => {
|
|
35
|
+
if (options.initWorkspace) {
|
|
36
|
+
await initWorkspace(options.initSkills);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
(0, import_watchdog.setupExitWatchdog)();
|
|
40
|
+
const clientInfo = (0, import_registry.createClientInfo)();
|
|
41
|
+
const mcpConfig = await configUtils.resolveCLIConfigForCLI(clientInfo.daemonProfilesDir, sessionName, options);
|
|
42
|
+
const clientInfoEx = {
|
|
43
|
+
cwd: process.cwd(),
|
|
44
|
+
sessionName,
|
|
45
|
+
workspaceDir: clientInfo.workspaceDir
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
const { browser, browserInfo } = await (0, import_browserFactory.createBrowserWithInfo)(mcpConfig, clientInfoEx);
|
|
49
|
+
const browserContext = mcpConfig.browser.isolated ? await browser.newContext(mcpConfig.browser.contextOptions) : browser.contexts()[0];
|
|
50
|
+
if (!browserContext)
|
|
51
|
+
throw new Error("Error: unable to connect to a browser that does not have any contexts");
|
|
52
|
+
const persistent = options.persistent || options.profile || mcpConfig.browser.userDataDir ? true : void 0;
|
|
53
|
+
const socketPath = await (0, import_daemon.startCliDaemonServer)(sessionName, browserContext, browserInfo, mcpConfig, clientInfo, { persistent, exitOnClose: true });
|
|
54
|
+
console.log(`### Success
|
|
55
|
+
Daemon listening on ${socketPath}`);
|
|
56
|
+
console.log("<EOF>");
|
|
57
|
+
} catch (error) {
|
|
58
|
+
const message = process.env.PWDEBUGIMPL ? error.stack || error.message : error.message;
|
|
59
|
+
console.log(`### Error
|
|
60
|
+
${message}`);
|
|
61
|
+
console.log("<EOF>");
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
void import_utilsBundle.program.parseAsync();
|
|
65
|
+
function defaultConfigFile() {
|
|
66
|
+
return import_path.default.resolve(".playwright", "cli.config.json");
|
|
67
|
+
}
|
|
68
|
+
function globalConfigFile() {
|
|
69
|
+
return import_path.default.join(process.env["PWTEST_CLI_GLOBAL_CONFIG"] ?? import_os.default.homedir(), ".playwright", "cli.config.json");
|
|
70
|
+
}
|
|
71
|
+
async function initWorkspace(initSkills) {
|
|
72
|
+
const cwd = process.cwd();
|
|
73
|
+
const playwrightDir = import_path.default.join(cwd, ".playwright");
|
|
74
|
+
await import_fs.default.promises.mkdir(playwrightDir, { recursive: true });
|
|
75
|
+
console.log(`\u2705 Workspace initialized at \`${cwd}\`.`);
|
|
76
|
+
if (initSkills) {
|
|
77
|
+
const skillSourceDir = import_path.default.join(__dirname, "../cli-client/skill");
|
|
78
|
+
const target = initSkills === "agents" ? "agents" : "claude";
|
|
79
|
+
const skillDestDir = import_path.default.join(cwd, `.${target}`, "skills", "playwright-cli");
|
|
80
|
+
if (!import_fs.default.existsSync(skillSourceDir)) {
|
|
81
|
+
console.error("\u274C Skills source directory not found:", skillSourceDir);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
await import_fs.default.promises.cp(skillSourceDir, skillDestDir, { recursive: true });
|
|
85
|
+
console.log(`\u2705 Skills installed to \`${import_path.default.relative(cwd, skillDestDir)}\`.`);
|
|
86
|
+
}
|
|
87
|
+
await ensureConfiguredBrowserInstalled();
|
|
88
|
+
}
|
|
89
|
+
async function ensureConfiguredBrowserInstalled() {
|
|
90
|
+
if (import_fs.default.existsSync(defaultConfigFile()) || import_fs.default.existsSync(globalConfigFile())) {
|
|
91
|
+
const clientInfo = (0, import_registry.createClientInfo)();
|
|
92
|
+
const config = await configUtils.resolveCLIConfigForCLI(clientInfo.daemonProfilesDir, "default", {});
|
|
93
|
+
const browserName = config.browser.browserName;
|
|
94
|
+
const channel = config.browser.launchOptions.channel;
|
|
95
|
+
if (!channel || channel.startsWith("chromium")) {
|
|
96
|
+
const executable = import_registry2.registry.findExecutable(channel ?? browserName);
|
|
97
|
+
if (executable && !import_fs.default.existsSync(executable.executablePath()))
|
|
98
|
+
await import_registry2.registry.install([executable]);
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
const channel = await findOrInstallDefaultBrowser();
|
|
102
|
+
if (channel !== "chrome")
|
|
103
|
+
await createDefaultConfig(channel);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function findOrInstallDefaultBrowser() {
|
|
107
|
+
const channels = ["chrome", "msedge"];
|
|
108
|
+
for (const channel of channels) {
|
|
109
|
+
const executable = import_registry2.registry.findExecutable(channel);
|
|
110
|
+
if (!executable?.executablePath())
|
|
111
|
+
continue;
|
|
112
|
+
console.log(`\u2705 Found ${channel}, will use it as the default browser.`);
|
|
113
|
+
return channel;
|
|
114
|
+
}
|
|
115
|
+
const chromiumExecutable = import_registry2.registry.findExecutable("chromium");
|
|
116
|
+
if (!import_fs.default.existsSync(chromiumExecutable?.executablePath()))
|
|
117
|
+
await import_registry2.registry.install([chromiumExecutable]);
|
|
118
|
+
return "chromium";
|
|
119
|
+
}
|
|
120
|
+
async function createDefaultConfig(channel) {
|
|
121
|
+
const config = {
|
|
122
|
+
browser: {
|
|
123
|
+
browserName: "chromium",
|
|
124
|
+
launchOptions: { channel }
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
await import_fs.default.promises.writeFile(defaultConfigFile(), JSON.stringify(config, null, 2));
|
|
128
|
+
console.log(`\u2705 Created default config for ${channel} at ${import_path.default.relative(process.cwd(), defaultConfigFile())}.`);
|
|
129
|
+
}
|
|
Binary file
|