@pedropaulovc/playwright 1.59.0-alpha-1769214875000
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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +170 -0
- package/ThirdPartyNotices.txt +5042 -0
- package/cli.js +19 -0
- package/index.d.ts +17 -0
- package/index.js +17 -0
- package/index.mjs +18 -0
- package/jsx-runtime.js +42 -0
- package/jsx-runtime.mjs +21 -0
- package/lib/agents/agentParser.js +89 -0
- package/lib/agents/copilot-setup-steps.yml +34 -0
- package/lib/agents/generateAgents.js +348 -0
- package/lib/agents/playwright-test-coverage.prompt.md +31 -0
- package/lib/agents/playwright-test-generate.prompt.md +8 -0
- package/lib/agents/playwright-test-generator.agent.md +88 -0
- package/lib/agents/playwright-test-heal.prompt.md +6 -0
- package/lib/agents/playwright-test-healer.agent.md +55 -0
- package/lib/agents/playwright-test-plan.prompt.md +9 -0
- package/lib/agents/playwright-test-planner.agent.md +73 -0
- package/lib/common/config.js +281 -0
- package/lib/common/configLoader.js +344 -0
- package/lib/common/esmLoaderHost.js +104 -0
- package/lib/common/expectBundle.js +28 -0
- package/lib/common/expectBundleImpl.js +407 -0
- package/lib/common/fixtures.js +302 -0
- package/lib/common/globals.js +58 -0
- package/lib/common/ipc.js +60 -0
- package/lib/common/poolBuilder.js +85 -0
- package/lib/common/process.js +132 -0
- package/lib/common/suiteUtils.js +140 -0
- package/lib/common/test.js +321 -0
- package/lib/common/testLoader.js +101 -0
- package/lib/common/testType.js +298 -0
- package/lib/common/validators.js +68 -0
- package/lib/fsWatcher.js +67 -0
- package/lib/index.js +726 -0
- package/lib/internalsForTest.js +42 -0
- package/lib/isomorphic/events.js +77 -0
- package/lib/isomorphic/folders.js +30 -0
- package/lib/isomorphic/stringInternPool.js +69 -0
- package/lib/isomorphic/teleReceiver.js +520 -0
- package/lib/isomorphic/teleSuiteUpdater.js +157 -0
- package/lib/isomorphic/testServerConnection.js +225 -0
- package/lib/isomorphic/testServerInterface.js +16 -0
- package/lib/isomorphic/testTree.js +329 -0
- package/lib/isomorphic/types.d.js +16 -0
- package/lib/loader/loaderMain.js +59 -0
- package/lib/matchers/expect.js +311 -0
- package/lib/matchers/matcherHint.js +44 -0
- package/lib/matchers/matchers.js +383 -0
- package/lib/matchers/toBeTruthy.js +75 -0
- package/lib/matchers/toEqual.js +100 -0
- package/lib/matchers/toHaveURL.js +101 -0
- package/lib/matchers/toMatchAriaSnapshot.js +159 -0
- package/lib/matchers/toMatchSnapshot.js +342 -0
- package/lib/matchers/toMatchText.js +99 -0
- package/lib/mcp/browser/browserContextFactory.js +329 -0
- package/lib/mcp/browser/browserServerBackend.js +89 -0
- package/lib/mcp/browser/config.js +421 -0
- package/lib/mcp/browser/context.js +244 -0
- package/lib/mcp/browser/response.js +284 -0
- package/lib/mcp/browser/sessionLog.js +75 -0
- package/lib/mcp/browser/tab.js +351 -0
- package/lib/mcp/browser/tools/common.js +63 -0
- package/lib/mcp/browser/tools/console.js +61 -0
- package/lib/mcp/browser/tools/dialogs.js +59 -0
- package/lib/mcp/browser/tools/evaluate.js +61 -0
- package/lib/mcp/browser/tools/files.js +58 -0
- package/lib/mcp/browser/tools/form.js +63 -0
- package/lib/mcp/browser/tools/install.js +72 -0
- package/lib/mcp/browser/tools/keyboard.js +151 -0
- package/lib/mcp/browser/tools/mouse.js +159 -0
- package/lib/mcp/browser/tools/navigate.js +136 -0
- package/lib/mcp/browser/tools/network.js +78 -0
- package/lib/mcp/browser/tools/pdf.js +49 -0
- package/lib/mcp/browser/tools/runCode.js +76 -0
- package/lib/mcp/browser/tools/screenshot.js +87 -0
- package/lib/mcp/browser/tools/snapshot.js +207 -0
- package/lib/mcp/browser/tools/tabs.js +67 -0
- package/lib/mcp/browser/tools/tool.js +47 -0
- package/lib/mcp/browser/tools/tracing.js +74 -0
- package/lib/mcp/browser/tools/utils.js +94 -0
- package/lib/mcp/browser/tools/verify.js +143 -0
- package/lib/mcp/browser/tools/wait.js +63 -0
- package/lib/mcp/browser/tools.js +82 -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 +76 -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 +109 -0
- package/lib/mcp/sdk/exports.js +28 -0
- package/lib/mcp/sdk/http.js +152 -0
- package/lib/mcp/sdk/inProcessTransport.js +71 -0
- package/lib/mcp/sdk/server.js +223 -0
- package/lib/mcp/sdk/tool.js +47 -0
- package/lib/mcp/terminal/SKILL.md +158 -0
- package/lib/mcp/terminal/cli.js +7 -0
- package/lib/mcp/terminal/command.js +56 -0
- package/lib/mcp/terminal/commands.js +519 -0
- package/lib/mcp/terminal/daemon.js +131 -0
- package/lib/mcp/terminal/help.json +47 -0
- package/lib/mcp/terminal/helpGenerator.js +115 -0
- package/lib/mcp/terminal/program.js +365 -0
- package/lib/mcp/terminal/socketConnection.js +80 -0
- package/lib/mcp/test/browserBackend.js +98 -0
- package/lib/mcp/test/generatorTools.js +122 -0
- package/lib/mcp/test/plannerTools.js +145 -0
- package/lib/mcp/test/seed.js +82 -0
- package/lib/mcp/test/streams.js +44 -0
- package/lib/mcp/test/testBackend.js +99 -0
- package/lib/mcp/test/testContext.js +285 -0
- package/lib/mcp/test/testTool.js +30 -0
- package/lib/mcp/test/testTools.js +108 -0
- package/lib/plugins/gitCommitInfoPlugin.js +198 -0
- package/lib/plugins/index.js +28 -0
- package/lib/plugins/webServerPlugin.js +237 -0
- package/lib/program.js +418 -0
- package/lib/reporters/base.js +638 -0
- package/lib/reporters/blob.js +138 -0
- package/lib/reporters/dot.js +99 -0
- package/lib/reporters/empty.js +32 -0
- package/lib/reporters/github.js +128 -0
- package/lib/reporters/html.js +633 -0
- package/lib/reporters/internalReporter.js +138 -0
- package/lib/reporters/json.js +254 -0
- package/lib/reporters/junit.js +232 -0
- package/lib/reporters/line.js +131 -0
- package/lib/reporters/list.js +253 -0
- package/lib/reporters/listModeReporter.js +69 -0
- package/lib/reporters/markdown.js +144 -0
- package/lib/reporters/merge.js +558 -0
- package/lib/reporters/multiplexer.js +112 -0
- package/lib/reporters/reporterV2.js +102 -0
- package/lib/reporters/teleEmitter.js +317 -0
- package/lib/reporters/versions/blobV1.js +16 -0
- package/lib/runner/dispatcher.js +530 -0
- package/lib/runner/failureTracker.js +72 -0
- package/lib/runner/lastRun.js +77 -0
- package/lib/runner/loadUtils.js +334 -0
- package/lib/runner/loaderHost.js +89 -0
- package/lib/runner/processHost.js +180 -0
- package/lib/runner/projectUtils.js +241 -0
- package/lib/runner/rebase.js +189 -0
- package/lib/runner/reporters.js +138 -0
- package/lib/runner/sigIntWatcher.js +96 -0
- package/lib/runner/storage.js +91 -0
- package/lib/runner/taskRunner.js +127 -0
- package/lib/runner/tasks.js +410 -0
- package/lib/runner/testGroups.js +125 -0
- package/lib/runner/testRunner.js +398 -0
- package/lib/runner/testServer.js +269 -0
- package/lib/runner/uiModeReporter.js +30 -0
- package/lib/runner/vcs.js +72 -0
- package/lib/runner/watchMode.js +396 -0
- package/lib/runner/workerHost.js +104 -0
- package/lib/third_party/pirates.js +62 -0
- package/lib/third_party/tsconfig-loader.js +103 -0
- package/lib/transform/babelBundle.js +46 -0
- package/lib/transform/babelBundleImpl.js +461 -0
- package/lib/transform/compilationCache.js +274 -0
- package/lib/transform/esmLoader.js +103 -0
- package/lib/transform/md.js +221 -0
- package/lib/transform/portTransport.js +67 -0
- package/lib/transform/transform.js +303 -0
- package/lib/util.js +400 -0
- package/lib/utilsBundle.js +50 -0
- package/lib/utilsBundleImpl.js +103 -0
- package/lib/worker/fixtureRunner.js +262 -0
- package/lib/worker/testInfo.js +536 -0
- package/lib/worker/testTracing.js +345 -0
- package/lib/worker/timeoutManager.js +174 -0
- package/lib/worker/util.js +31 -0
- package/lib/worker/workerMain.js +530 -0
- package/package.json +73 -0
- package/test.d.ts +18 -0
- package/test.js +24 -0
- package/test.mjs +34 -0
- package/types/test.d.ts +10287 -0
- package/types/testReporter.d.ts +822 -0
|
@@ -0,0 +1,131 @@
|
|
|
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
|
+
startMcpDaemonServer: () => startMcpDaemonServer
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(daemon_exports);
|
|
34
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
35
|
+
var import_net = __toESM(require("net"));
|
|
36
|
+
var import_os = __toESM(require("os"));
|
|
37
|
+
var import_path = __toESM(require("path"));
|
|
38
|
+
var import_url = __toESM(require("url"));
|
|
39
|
+
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
40
|
+
var import_utils = require("playwright-core/lib/utils");
|
|
41
|
+
var import_socketConnection = require("./socketConnection");
|
|
42
|
+
var import_commands = require("./commands");
|
|
43
|
+
var import_command = require("./command");
|
|
44
|
+
const daemonDebug = (0, import_utilsBundle.debug)("pw:daemon");
|
|
45
|
+
async function socketExists(socketPath) {
|
|
46
|
+
try {
|
|
47
|
+
const stat = await import_promises.default.stat(socketPath);
|
|
48
|
+
if (stat?.isSocket())
|
|
49
|
+
return true;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
async function startMcpDaemonServer(socketPath, serverBackendFactory) {
|
|
55
|
+
if (import_os.default.platform() !== "win32" && await socketExists(socketPath)) {
|
|
56
|
+
daemonDebug(`Socket already exists, removing: ${socketPath}`);
|
|
57
|
+
try {
|
|
58
|
+
await import_promises.default.unlink(socketPath);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
daemonDebug(`Failed to remove existing socket: ${error}`);
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const backend = serverBackendFactory.create();
|
|
65
|
+
const cwd = import_url.default.pathToFileURL(process.cwd()).href;
|
|
66
|
+
await backend.initialize?.({
|
|
67
|
+
name: "playwright-cli",
|
|
68
|
+
version: "1.0.0",
|
|
69
|
+
roots: [{
|
|
70
|
+
uri: cwd,
|
|
71
|
+
name: "cwd"
|
|
72
|
+
}],
|
|
73
|
+
timestamp: Date.now()
|
|
74
|
+
});
|
|
75
|
+
await import_promises.default.mkdir(import_path.default.dirname(socketPath), { recursive: true });
|
|
76
|
+
const server = import_net.default.createServer((socket) => {
|
|
77
|
+
daemonDebug("new client connection");
|
|
78
|
+
const connection = new import_socketConnection.SocketConnection(socket);
|
|
79
|
+
connection.onclose = () => {
|
|
80
|
+
daemonDebug("client disconnected");
|
|
81
|
+
};
|
|
82
|
+
connection.onmessage = async (message) => {
|
|
83
|
+
const { id, method, params } = message;
|
|
84
|
+
try {
|
|
85
|
+
daemonDebug("received command", method);
|
|
86
|
+
if (method === "stop") {
|
|
87
|
+
daemonDebug("stop command received, shutting down");
|
|
88
|
+
await connection.send({ id, result: "ok" });
|
|
89
|
+
server.close();
|
|
90
|
+
(0, import_utils.gracefullyProcessExitDoNotHang)(0);
|
|
91
|
+
} else if (method === "run") {
|
|
92
|
+
const { toolName, toolParams } = parseCliCommand(params.args);
|
|
93
|
+
const response = await backend.callTool(toolName, toolParams, () => {
|
|
94
|
+
});
|
|
95
|
+
await connection.send({ id, result: formatResult(response) });
|
|
96
|
+
} else {
|
|
97
|
+
throw new Error(`Unknown method: ${method}`);
|
|
98
|
+
}
|
|
99
|
+
} catch (e) {
|
|
100
|
+
daemonDebug("command failed", e);
|
|
101
|
+
await connection.send({ id, error: e.message });
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
server.on("error", (error) => {
|
|
107
|
+
daemonDebug(`server error: ${error.message}`);
|
|
108
|
+
reject(error);
|
|
109
|
+
});
|
|
110
|
+
server.listen(socketPath, () => {
|
|
111
|
+
daemonDebug(`daemon server listening on ${socketPath}`);
|
|
112
|
+
resolve(socketPath);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function formatResult(result) {
|
|
117
|
+
const isError = result.isError;
|
|
118
|
+
const text = result.content[0].type === "text" ? result.content[0].text : void 0;
|
|
119
|
+
const sections = result.content[0]._meta?.sections;
|
|
120
|
+
return { isError, text, sections };
|
|
121
|
+
}
|
|
122
|
+
function parseCliCommand(args) {
|
|
123
|
+
const command = import_commands.commands[args._[0]];
|
|
124
|
+
if (!command)
|
|
125
|
+
throw new Error("Command is required");
|
|
126
|
+
return (0, import_command.parseCommand)(command, args);
|
|
127
|
+
}
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
startMcpDaemonServer
|
|
131
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"global": "Usage: playwright-cli <command> [args] [options]\n\nCore:\n open <url> open url\n close close the page\n type <text> type text into editable element\n click <ref> [button] perform click on a web page\n dblclick <ref> [button] perform double click on a web page\n fill <ref> <text> fill text into editable element\n drag <startRef> <endRef> perform drag and drop between two elements\n hover <ref> hover over element on page\n select <ref> <val> select an option in a dropdown\n upload <file> upload one or multiple files\n check <ref> check a checkbox or radio button\n uncheck <ref> uncheck a checkbox or radio button\n snapshot capture page snapshot to obtain element ref\n eval <func> [ref] evaluate javascript expression on page or element\n dialog-accept [prompt] accept a dialog\n dialog-dismiss dismiss a dialog\n resize <w> <h> resize the browser window\n\nNavigation:\n go-back go back to the previous page\n go-forward go forward to the next page\n reload reload the current page\n\nKeyboard:\n press <key> press a key on the keyboard, `a`, `arrowleft`\n keydown <key> press a key down on the keyboard\n keyup <key> press a key up on the keyboard\n\nMouse:\n mousemove <x> <y> move mouse to a given position\n mousedown [button] press mouse down\n mouseup [button] press mouse up\n mousewheel <dx> <dy> scroll mouse wheel\n\nSave as:\n screenshot [ref] screenshot of the current page or element\n pdf save page as pdf\n\nTabs:\n tab-list list all tabs\n tab-new [url] create a new tab\n tab-close [index] close a browser tab\n tab-select <index> select a browser tab\n\nDevTools:\n console [min-level] list console messages\n network list all network requests since loading the page\n run-code <code> run playwright code snippet\n tracing-start start trace recording\n tracing-stop stop trace recording\n\nSessions:\n session-list list all sessions\n session-stop [name] stop session\n session-stop-all stop all sessions\n session-delete [name] delete session data",
|
|
3
|
+
"commands": {
|
|
4
|
+
"open": "playwright-cli open <url>\n\nOpen URL\n\nArguments:\n <url> the url to navigate to\nOptions:\n --headed run browser in headed mode",
|
|
5
|
+
"close": "playwright-cli close \n\nClose the page\n",
|
|
6
|
+
"type": "playwright-cli type <text>\n\nType text into editable element\n\nArguments:\n <text> text to type into the element\nOptions:\n --submit whether to submit entered text (press enter after)",
|
|
7
|
+
"click": "playwright-cli click <ref> [button]\n\nPerform click on a web page\n\nArguments:\n <ref> exact target element reference from the page snapshot\n [button] button to click, defaults to left\nOptions:\n --modifiers modifier keys to press",
|
|
8
|
+
"dblclick": "playwright-cli dblclick <ref> [button]\n\nPerform double click on a web page\n\nArguments:\n <ref> exact target element reference from the page snapshot\n [button] button to click, defaults to left\nOptions:\n --modifiers modifier keys to press",
|
|
9
|
+
"fill": "playwright-cli fill <ref> <text>\n\nFill text into editable element\n\nArguments:\n <ref> exact target element reference from the page snapshot\n <text> text to fill into the element\nOptions:\n --submit whether to submit entered text (press enter after)",
|
|
10
|
+
"drag": "playwright-cli drag <startRef> <endRef>\n\nPerform drag and drop between two elements\n\nArguments:\n <startRef> exact source element reference from the page snapshot\n <endRef> exact target element reference from the page snapshot\nOptions:\n --headed run browser in headed mode",
|
|
11
|
+
"hover": "playwright-cli hover <ref>\n\nHover over element on page\n\nArguments:\n <ref> exact target element reference from the page snapshot",
|
|
12
|
+
"select": "playwright-cli select <ref> <val>\n\nSelect an option in a dropdown\n\nArguments:\n <ref> exact target element reference from the page snapshot\n <val> value to select in the dropdown",
|
|
13
|
+
"upload": "playwright-cli upload <file>\n\nUpload one or multiple files\n\nArguments:\n <file> the absolute paths to the files to upload",
|
|
14
|
+
"check": "playwright-cli check <ref>\n\nCheck a checkbox or radio button\n\nArguments:\n <ref> exact target element reference from the page snapshot",
|
|
15
|
+
"uncheck": "playwright-cli uncheck <ref>\n\nUncheck a checkbox or radio button\n\nArguments:\n <ref> exact target element reference from the page snapshot",
|
|
16
|
+
"snapshot": "playwright-cli snapshot \n\nCapture page snapshot to obtain element ref\n\nOptions:\n --filename save snapshot to markdown file instead of returning it in the response.",
|
|
17
|
+
"eval": "playwright-cli eval <func> [ref]\n\nEvaluate JavaScript expression on page or element\n\nArguments:\n <func> () => { /* code */ } or (element) => { /* code */ } when element is provided\n [ref] exact target element reference from the page snapshot",
|
|
18
|
+
"console": "playwright-cli console [min-level]\n\nList console messages\n\nArguments:\n [min-level] level of the console messages to return. each level includes the messages of more severe levels. defaults to \"info\".\nOptions:\n --clear whether to clear the console list",
|
|
19
|
+
"dialog-accept": "playwright-cli dialog-accept [prompt]\n\nAccept a dialog\n\nArguments:\n [prompt] the text of the prompt in case of a prompt dialog.",
|
|
20
|
+
"dialog-dismiss": "playwright-cli dialog-dismiss \n\nDismiss a dialog\n",
|
|
21
|
+
"resize": "playwright-cli resize <w> <h>\n\nResize the browser window\n\nArguments:\n <w> width of the browser window\n <h> height of the browser window",
|
|
22
|
+
"go-back": "playwright-cli go-back \n\nGo back to the previous page\n",
|
|
23
|
+
"go-forward": "playwright-cli go-forward \n\nGo forward to the next page\n",
|
|
24
|
+
"reload": "playwright-cli reload \n\nReload the current page\n",
|
|
25
|
+
"press": "playwright-cli press <key>\n\nPress a key on the keyboard, `a`, `ArrowLeft`\n\nArguments:\n <key> name of the key to press or a character to generate, such as `arrowleft` or `a`",
|
|
26
|
+
"keydown": "playwright-cli keydown <key>\n\nPress a key down on the keyboard\n\nArguments:\n <key> name of the key to press or a character to generate, such as `arrowleft` or `a`",
|
|
27
|
+
"keyup": "playwright-cli keyup <key>\n\nPress a key up on the keyboard\n\nArguments:\n <key> name of the key to press or a character to generate, such as `arrowleft` or `a`",
|
|
28
|
+
"mousemove": "playwright-cli mousemove <x> <y>\n\nMove mouse to a given position\n\nArguments:\n <x> x coordinate\n <y> y coordinate",
|
|
29
|
+
"mousedown": "playwright-cli mousedown [button]\n\nPress mouse down\n\nArguments:\n [button] button to press, defaults to left",
|
|
30
|
+
"mouseup": "playwright-cli mouseup [button]\n\nPress mouse up\n\nArguments:\n [button] button to press, defaults to left",
|
|
31
|
+
"mousewheel": "playwright-cli mousewheel <dx> <dy>\n\nScroll mouse wheel\n\nArguments:\n <dx> y delta\n <dy> x delta",
|
|
32
|
+
"screenshot": "playwright-cli screenshot [ref]\n\nscreenshot of the current page or element\n\nArguments:\n [ref] exact target element reference from the page snapshot.\nOptions:\n --filename file name to save the screenshot to. defaults to `page-{timestamp}.{png|jpeg}` if not specified.\n --full-page when true, takes a screenshot of the full scrollable page, instead of the currently visible viewport.",
|
|
33
|
+
"pdf": "playwright-cli pdf \n\nSave page as PDF\n\nOptions:\n --filename file name to save the pdf to. defaults to `page-{timestamp}.pdf` if not specified.",
|
|
34
|
+
"tab-list": "playwright-cli tab-list \n\nList all tabs\n",
|
|
35
|
+
"tab-new": "playwright-cli tab-new [url]\n\nCreate a new tab\n\nArguments:\n [url] the url to navigate to in the new tab. if omitted, the new tab will be blank.",
|
|
36
|
+
"tab-close": "playwright-cli tab-close [index]\n\nClose a browser tab\n\nArguments:\n [index] tab index. if omitted, current tab is closed.",
|
|
37
|
+
"tab-select": "playwright-cli tab-select <index>\n\nSelect a browser tab\n\nArguments:\n <index> tab index",
|
|
38
|
+
"network": "playwright-cli network \n\nList all network requests since loading the page\n\nOptions:\n --static whether to include successful static resources like images, fonts, scripts, etc. defaults to false.\n --clear whether to clear the network list",
|
|
39
|
+
"run-code": "playwright-cli run-code <code>\n\nRun Playwright code snippet\n\nArguments:\n <code> a javascript function containing playwright code to execute. it will be invoked with a single argument, page, which you can use for any page interaction.",
|
|
40
|
+
"tracing-start": "playwright-cli tracing-start \n\nStart trace recording\n",
|
|
41
|
+
"tracing-stop": "playwright-cli tracing-stop \n\nStop trace recording\n",
|
|
42
|
+
"session-list": "playwright-cli session-list \n\nList all sessions\n",
|
|
43
|
+
"session-stop": "playwright-cli session-stop [name]\n\nStop session\n\nArguments:\n [name] name of the session to stop. if omitted, current session is stopped.",
|
|
44
|
+
"session-stop-all": "playwright-cli session-stop-all \n\nStop all sessions\n",
|
|
45
|
+
"session-delete": "playwright-cli session-delete [name]\n\nDelete session data\n\nArguments:\n [name] name of the session to delete. if omitted, current session is deleted."
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
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_path = __toESM(require("path"));
|
|
26
|
+
var import_commands = require("./commands");
|
|
27
|
+
function commandArgs(command) {
|
|
28
|
+
const args = [];
|
|
29
|
+
const shape = command.args ? command.args.shape : {};
|
|
30
|
+
for (const [name, schema] of Object.entries(shape)) {
|
|
31
|
+
const zodSchema = schema;
|
|
32
|
+
const description = zodSchema.description ?? "";
|
|
33
|
+
args.push({ name, description, optional: zodSchema.safeParse(void 0).success });
|
|
34
|
+
}
|
|
35
|
+
return args;
|
|
36
|
+
}
|
|
37
|
+
function commandArgsText(args) {
|
|
38
|
+
return args.map((a) => a.optional ? `[${a.name}]` : `<${a.name}>`).join(" ");
|
|
39
|
+
}
|
|
40
|
+
function generateCommandHelp(command) {
|
|
41
|
+
const args = commandArgs(command);
|
|
42
|
+
const lines = [
|
|
43
|
+
`playwright-cli ${command.name} ${commandArgsText(args)}`,
|
|
44
|
+
"",
|
|
45
|
+
command.description,
|
|
46
|
+
""
|
|
47
|
+
];
|
|
48
|
+
if (args.length) {
|
|
49
|
+
lines.push("Arguments:");
|
|
50
|
+
lines.push(...args.map((a) => formatWithGap(` ${a.optional ? `[${a.name}]` : `<${a.name}>`}`, a.description.toLowerCase())));
|
|
51
|
+
}
|
|
52
|
+
if (command.options) {
|
|
53
|
+
lines.push("Options:");
|
|
54
|
+
const optionsShape = command.options.shape;
|
|
55
|
+
for (const [name, schema] of Object.entries(optionsShape)) {
|
|
56
|
+
const zodSchema = schema;
|
|
57
|
+
const description = (zodSchema.description ?? "").toLowerCase();
|
|
58
|
+
lines.push(formatWithGap(` --${name}`, description));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return lines.join("\n");
|
|
62
|
+
}
|
|
63
|
+
const categories = [
|
|
64
|
+
{ name: "core", title: "Core" },
|
|
65
|
+
{ name: "navigation", title: "Navigation" },
|
|
66
|
+
{ name: "keyboard", title: "Keyboard" },
|
|
67
|
+
{ name: "mouse", title: "Mouse" },
|
|
68
|
+
{ name: "export", title: "Save as" },
|
|
69
|
+
{ name: "tabs", title: "Tabs" },
|
|
70
|
+
{ name: "storage", title: "Storage" },
|
|
71
|
+
{ name: "devtools", title: "DevTools" },
|
|
72
|
+
{ name: "session", title: "Sessions" }
|
|
73
|
+
];
|
|
74
|
+
function generateHelp() {
|
|
75
|
+
const lines = [];
|
|
76
|
+
lines.push("Usage: playwright-cli <command> [args] [options]");
|
|
77
|
+
const commandsByCategory = /* @__PURE__ */ new Map();
|
|
78
|
+
for (const c of categories)
|
|
79
|
+
commandsByCategory.set(c.name, []);
|
|
80
|
+
for (const command of Object.values(import_commands.commands))
|
|
81
|
+
commandsByCategory.get(command.category).push(command);
|
|
82
|
+
for (const c of categories) {
|
|
83
|
+
const cc = commandsByCategory.get(c.name);
|
|
84
|
+
if (!cc.length)
|
|
85
|
+
continue;
|
|
86
|
+
lines.push(`
|
|
87
|
+
${c.title}:`);
|
|
88
|
+
for (const command of cc)
|
|
89
|
+
lines.push(generateHelpEntry(command));
|
|
90
|
+
}
|
|
91
|
+
return lines.join("\n");
|
|
92
|
+
}
|
|
93
|
+
function generateHelpEntry(command) {
|
|
94
|
+
const args = commandArgs(command);
|
|
95
|
+
const prefix = ` ${command.name} ${commandArgsText(args)}`;
|
|
96
|
+
const suffix = command.description.toLowerCase();
|
|
97
|
+
return formatWithGap(prefix, suffix);
|
|
98
|
+
}
|
|
99
|
+
async function main() {
|
|
100
|
+
const help = {
|
|
101
|
+
global: generateHelp(),
|
|
102
|
+
commands: Object.fromEntries(
|
|
103
|
+
Object.entries(import_commands.commands).map(([name, command]) => [name, generateCommandHelp(command)])
|
|
104
|
+
)
|
|
105
|
+
};
|
|
106
|
+
const fileName = import_path.default.resolve(__dirname, "help.json").replace("lib", "src");
|
|
107
|
+
console.log("Writing ", import_path.default.relative(process.cwd(), fileName));
|
|
108
|
+
await import_fs.default.promises.writeFile(fileName, JSON.stringify(help, null, 2));
|
|
109
|
+
console.log(help.global);
|
|
110
|
+
}
|
|
111
|
+
function formatWithGap(prefix, text) {
|
|
112
|
+
const indent = Math.max(1, 30 - prefix.length);
|
|
113
|
+
return prefix + " ".repeat(indent) + text;
|
|
114
|
+
}
|
|
115
|
+
void main();
|
|
@@ -0,0 +1,365 @@
|
|
|
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 program_exports = {};
|
|
30
|
+
__export(program_exports, {
|
|
31
|
+
printResponse: () => printResponse,
|
|
32
|
+
program: () => program
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(program_exports);
|
|
35
|
+
var import_child_process = require("child_process");
|
|
36
|
+
var import_crypto = __toESM(require("crypto"));
|
|
37
|
+
var import_fs = __toESM(require("fs"));
|
|
38
|
+
var import_net = __toESM(require("net"));
|
|
39
|
+
var import_os = __toESM(require("os"));
|
|
40
|
+
var import_path = __toESM(require("path"));
|
|
41
|
+
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
42
|
+
var import_socketConnection = require("./socketConnection");
|
|
43
|
+
const debugCli = (0, import_utilsBundle.debug)("pw:cli");
|
|
44
|
+
class Session {
|
|
45
|
+
constructor(name, connection) {
|
|
46
|
+
this._nextMessageId = 1;
|
|
47
|
+
this._callbacks = /* @__PURE__ */ new Map();
|
|
48
|
+
this.name = name;
|
|
49
|
+
this._connection = connection;
|
|
50
|
+
this._connection.onmessage = (message) => this._onMessage(message);
|
|
51
|
+
this._connection.onclose = () => this.close();
|
|
52
|
+
}
|
|
53
|
+
async run(args) {
|
|
54
|
+
return await this._send("run", { args });
|
|
55
|
+
}
|
|
56
|
+
async stop() {
|
|
57
|
+
await this._send("stop");
|
|
58
|
+
this.close();
|
|
59
|
+
}
|
|
60
|
+
async _send(method, params = {}) {
|
|
61
|
+
const messageId = this._nextMessageId++;
|
|
62
|
+
const message = {
|
|
63
|
+
id: messageId,
|
|
64
|
+
method,
|
|
65
|
+
params
|
|
66
|
+
};
|
|
67
|
+
await this._connection.send(message);
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
this._callbacks.set(messageId, { resolve, reject });
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
close() {
|
|
73
|
+
for (const callback of this._callbacks.values())
|
|
74
|
+
callback.reject(new Error("Session closed"));
|
|
75
|
+
this._callbacks.clear();
|
|
76
|
+
this._connection.close();
|
|
77
|
+
}
|
|
78
|
+
_onMessage(object) {
|
|
79
|
+
if (object.id && this._callbacks.has(object.id)) {
|
|
80
|
+
const callback = this._callbacks.get(object.id);
|
|
81
|
+
this._callbacks.delete(object.id);
|
|
82
|
+
if (object.error)
|
|
83
|
+
callback.reject(new Error(object.error));
|
|
84
|
+
else
|
|
85
|
+
callback.resolve(object.result);
|
|
86
|
+
} else if (object.id) {
|
|
87
|
+
throw new Error(`Unexpected message id: ${object.id}`);
|
|
88
|
+
} else {
|
|
89
|
+
throw new Error(`Unexpected message without id: ${JSON.stringify(object)}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
class SessionManager {
|
|
94
|
+
async list() {
|
|
95
|
+
const dir = daemonSocketDir;
|
|
96
|
+
try {
|
|
97
|
+
const files = await import_fs.default.promises.readdir(dir);
|
|
98
|
+
const sessions = [];
|
|
99
|
+
for (const file of files) {
|
|
100
|
+
if (file.endsWith("-user-data")) {
|
|
101
|
+
const sessionName = file.slice(0, -"-user-data".length);
|
|
102
|
+
const live = await this._canConnect(sessionName);
|
|
103
|
+
sessions.push({ name: sessionName, live });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return sessions;
|
|
107
|
+
} catch {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async run(args) {
|
|
112
|
+
const sessionName = this._resolveSessionName(args.session);
|
|
113
|
+
const session = await this._connect(sessionName);
|
|
114
|
+
const result = await session.run(args);
|
|
115
|
+
await printResponse(result);
|
|
116
|
+
session.close();
|
|
117
|
+
}
|
|
118
|
+
async stop(sessionName) {
|
|
119
|
+
sessionName = this._resolveSessionName(sessionName);
|
|
120
|
+
if (!await this._canConnect(sessionName)) {
|
|
121
|
+
console.log(`Session '${sessionName}' is not running.`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const session = await this._connect(sessionName);
|
|
125
|
+
await session.stop();
|
|
126
|
+
console.log(`Session '${sessionName}' stopped.`);
|
|
127
|
+
}
|
|
128
|
+
async delete(sessionName) {
|
|
129
|
+
sessionName = this._resolveSessionName(sessionName);
|
|
130
|
+
if (await this._canConnect(sessionName)) {
|
|
131
|
+
const session = await this._connect(sessionName);
|
|
132
|
+
await session.stop();
|
|
133
|
+
}
|
|
134
|
+
const userDataDir = import_path.default.resolve(daemonSocketDir, `${sessionName}-user-data`);
|
|
135
|
+
try {
|
|
136
|
+
await import_fs.default.promises.rm(userDataDir, { recursive: true });
|
|
137
|
+
console.log(`Deleted user data for session '${sessionName}'.`);
|
|
138
|
+
} catch (e) {
|
|
139
|
+
if (e.code === "ENOENT")
|
|
140
|
+
console.log(`No user data found for session '${sessionName}'.`);
|
|
141
|
+
else
|
|
142
|
+
throw e;
|
|
143
|
+
}
|
|
144
|
+
if (import_os.default.platform() !== "win32") {
|
|
145
|
+
const socketPath = this._daemonSocketPath(sessionName);
|
|
146
|
+
await import_fs.default.promises.unlink(socketPath).catch(() => {
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async _connect(sessionName) {
|
|
151
|
+
const socketPath = process.env.PLAYWRIGHT_DAEMON_SOCKET_PATH || this._daemonSocketPath(sessionName);
|
|
152
|
+
debugCli(`Connecting to daemon at ${socketPath}`);
|
|
153
|
+
const socketExists = await import_fs.default.promises.stat(socketPath).then((stat) => stat?.isSocket() ?? false).catch(() => false);
|
|
154
|
+
if (socketExists) {
|
|
155
|
+
debugCli(`Socket file exists, attempting to connect...`);
|
|
156
|
+
try {
|
|
157
|
+
return await this._connectToSocket(sessionName, socketPath);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
if (import_os.default.platform() !== "win32")
|
|
160
|
+
await import_fs.default.promises.unlink(socketPath).catch(() => {
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (process.env.PLAYWRIGHT_DAEMON_SOCKET_PATH)
|
|
165
|
+
throw new Error(`Socket path ${socketPath} does not exist`);
|
|
166
|
+
const userDataDir = import_path.default.resolve(daemonSocketDir, `${sessionName}-user-data`);
|
|
167
|
+
const child = spawnDaemon(socketPath, userDataDir, {
|
|
168
|
+
detached: true,
|
|
169
|
+
stdio: "ignore",
|
|
170
|
+
cwd: process.cwd()
|
|
171
|
+
// Will be used as root.
|
|
172
|
+
});
|
|
173
|
+
child.unref();
|
|
174
|
+
const maxRetries = 50;
|
|
175
|
+
const retryDelay = 100;
|
|
176
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
177
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
178
|
+
try {
|
|
179
|
+
return await this._connectToSocket(sessionName, socketPath);
|
|
180
|
+
} catch (e) {
|
|
181
|
+
if (e.code !== "ENOENT")
|
|
182
|
+
throw e;
|
|
183
|
+
debugCli(`Retrying to connect to daemon at ${socketPath} (${i + 1}/${maxRetries})`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
throw new Error(`Failed to connect to daemon at ${socketPath} after ${maxRetries * retryDelay}ms`);
|
|
187
|
+
}
|
|
188
|
+
async _connectToSocket(sessionName, socketPath) {
|
|
189
|
+
const socket = await new Promise((resolve, reject) => {
|
|
190
|
+
const socket2 = import_net.default.createConnection(socketPath, () => {
|
|
191
|
+
debugCli(`Connected to daemon at ${socketPath}`);
|
|
192
|
+
resolve(socket2);
|
|
193
|
+
});
|
|
194
|
+
socket2.on("error", reject);
|
|
195
|
+
});
|
|
196
|
+
return new Session(sessionName, new import_socketConnection.SocketConnection(socket));
|
|
197
|
+
}
|
|
198
|
+
async _canConnect(sessionName) {
|
|
199
|
+
const socketPath = this._daemonSocketPath(sessionName);
|
|
200
|
+
return new Promise((resolve) => {
|
|
201
|
+
const socket = import_net.default.createConnection(socketPath, () => {
|
|
202
|
+
socket.destroy();
|
|
203
|
+
resolve(true);
|
|
204
|
+
});
|
|
205
|
+
socket.on("error", () => {
|
|
206
|
+
resolve(false);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
_resolveSessionName(sessionName) {
|
|
211
|
+
if (sessionName)
|
|
212
|
+
return sessionName;
|
|
213
|
+
if (process.env.PLAYWRIGHT_CLI_SESSION)
|
|
214
|
+
return process.env.PLAYWRIGHT_CLI_SESSION;
|
|
215
|
+
return "default";
|
|
216
|
+
}
|
|
217
|
+
_daemonSocketPath(sessionName) {
|
|
218
|
+
const socketName = `${sessionName}.sock`;
|
|
219
|
+
if (import_os.default.platform() === "win32")
|
|
220
|
+
return `\\\\.\\pipe\\${socketDirHash}-${socketName}`;
|
|
221
|
+
return import_path.default.join(daemonSocketDir, socketName);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async function handleSessionCommand(sessionManager, args) {
|
|
225
|
+
const subcommand = args._[0].split("-").slice(1).join("-");
|
|
226
|
+
if (subcommand === "list") {
|
|
227
|
+
const sessions = await sessionManager.list();
|
|
228
|
+
console.log("Sessions:");
|
|
229
|
+
for (const session of sessions) {
|
|
230
|
+
const liveMarker = session.live ? " (live)" : "";
|
|
231
|
+
console.log(` ${session.name}${liveMarker}`);
|
|
232
|
+
}
|
|
233
|
+
if (sessions.length === 0)
|
|
234
|
+
console.log(" (no sessions)");
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (subcommand === "stop") {
|
|
238
|
+
await sessionManager.stop(args._[1]);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (subcommand === "stop-all") {
|
|
242
|
+
const sessions = await sessionManager.list();
|
|
243
|
+
for (const session of sessions)
|
|
244
|
+
await sessionManager.stop(session.name);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (subcommand === "delete") {
|
|
248
|
+
await sessionManager.delete(args._[1]);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
console.error(`Unknown session subcommand: ${subcommand}`);
|
|
252
|
+
process.exit(1);
|
|
253
|
+
}
|
|
254
|
+
const socketDirHash = (() => {
|
|
255
|
+
const hash = import_crypto.default.createHash("sha1");
|
|
256
|
+
hash.update(require.resolve("../../../package.json"));
|
|
257
|
+
return hash.digest("hex");
|
|
258
|
+
})();
|
|
259
|
+
const daemonSocketDir = (() => {
|
|
260
|
+
let localCacheDir;
|
|
261
|
+
if (process.platform === "linux")
|
|
262
|
+
localCacheDir = process.env.XDG_CACHE_HOME || import_path.default.join(import_os.default.homedir(), ".cache");
|
|
263
|
+
if (process.platform === "darwin")
|
|
264
|
+
localCacheDir = import_path.default.join(import_os.default.homedir(), "Library", "Caches");
|
|
265
|
+
if (process.platform === "win32")
|
|
266
|
+
localCacheDir = process.env.LOCALAPPDATA || import_path.default.join(import_os.default.homedir(), "AppData", "Local");
|
|
267
|
+
if (!localCacheDir)
|
|
268
|
+
throw new Error("Unsupported platform: " + process.platform);
|
|
269
|
+
return import_path.default.join(localCacheDir, "ms-playwright", "daemon", "daemon", socketDirHash);
|
|
270
|
+
})();
|
|
271
|
+
function spawnDaemon(socketPath, userDataDir, options) {
|
|
272
|
+
const cliPath = import_path.default.join(__dirname, "../../../cli.js");
|
|
273
|
+
debugCli(`Will launch daemon process: ${cliPath}`);
|
|
274
|
+
return (0, import_child_process.spawn)(process.execPath, [cliPath, "run-mcp-server", `--daemon=${socketPath}`, `--user-data-dir=${userDataDir}`], options);
|
|
275
|
+
}
|
|
276
|
+
async function program(options) {
|
|
277
|
+
const argv = process.argv.slice(2);
|
|
278
|
+
const args = require("minimist")(argv);
|
|
279
|
+
const help = require("./help.json");
|
|
280
|
+
const commandName = args._[0];
|
|
281
|
+
if (args.version || args.v) {
|
|
282
|
+
console.log(options.version);
|
|
283
|
+
process.exit(0);
|
|
284
|
+
}
|
|
285
|
+
const command = help.commands[commandName];
|
|
286
|
+
if (args.help || args.h) {
|
|
287
|
+
if (command) {
|
|
288
|
+
console.log(command);
|
|
289
|
+
} else {
|
|
290
|
+
console.log("playwright-cli - run playwright mcp commands from terminal\n");
|
|
291
|
+
console.log(help.global);
|
|
292
|
+
}
|
|
293
|
+
process.exit(0);
|
|
294
|
+
}
|
|
295
|
+
if (!command) {
|
|
296
|
+
console.error(`Unknown command: ${commandName}
|
|
297
|
+
`);
|
|
298
|
+
console.log(help.global);
|
|
299
|
+
process.exit(1);
|
|
300
|
+
}
|
|
301
|
+
const sessionManager = new SessionManager();
|
|
302
|
+
if (commandName.startsWith("session")) {
|
|
303
|
+
await handleSessionCommand(sessionManager, args);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
await sessionManager.run(args);
|
|
307
|
+
}
|
|
308
|
+
async function printResponse(response) {
|
|
309
|
+
const { sections } = response;
|
|
310
|
+
if (!sections) {
|
|
311
|
+
console.log("### Error\n" + response.text);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const text = [];
|
|
315
|
+
for (const section of sections) {
|
|
316
|
+
text.push(`### ${section.title}`);
|
|
317
|
+
for (const result of section.content) {
|
|
318
|
+
if (!result.file) {
|
|
319
|
+
if (result.text !== void 0)
|
|
320
|
+
text.push(result.text);
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
const generatedFileName = await outputFile(dateAsFileName(result.file.prefix, result.file.ext), { origin: "code" });
|
|
324
|
+
const fileName = result.file.suggestedFilename ? await outputFile(result.file.suggestedFilename, { origin: "llm" }) : generatedFileName;
|
|
325
|
+
text.push(`- [${result.title}](${import_path.default.relative(process.cwd(), fileName)})`);
|
|
326
|
+
if (result.data)
|
|
327
|
+
await import_fs.default.promises.writeFile(fileName, result.data);
|
|
328
|
+
else if (result.isBase64)
|
|
329
|
+
await import_fs.default.promises.writeFile(fileName, Buffer.from(result.text, "base64"));
|
|
330
|
+
else
|
|
331
|
+
await import_fs.default.promises.writeFile(fileName, result.text);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
console.log(text.join("\n"));
|
|
335
|
+
}
|
|
336
|
+
function dateAsFileName(prefix, extension) {
|
|
337
|
+
const date = /* @__PURE__ */ new Date();
|
|
338
|
+
return `${prefix}-${date.toISOString().replace(/[:.]/g, "-")}.${extension}`;
|
|
339
|
+
}
|
|
340
|
+
const outputDir = import_path.default.join(process.cwd(), ".playwright-cli");
|
|
341
|
+
async function outputFile(fileName, options) {
|
|
342
|
+
await import_fs.default.promises.mkdir(outputDir, { recursive: true });
|
|
343
|
+
if (options.origin === "code")
|
|
344
|
+
return import_path.default.resolve(outputDir, fileName);
|
|
345
|
+
if (options.origin === "llm") {
|
|
346
|
+
fileName = fileName.split("\\").join("/");
|
|
347
|
+
const resolvedFile = import_path.default.resolve(outputDir, fileName);
|
|
348
|
+
if (!resolvedFile.startsWith(import_path.default.resolve(outputDir) + import_path.default.sep))
|
|
349
|
+
throw new Error(`Resolved file path ${resolvedFile} is outside of the output directory ${outputDir}. Use relative file names to stay within the output directory.`);
|
|
350
|
+
return resolvedFile;
|
|
351
|
+
}
|
|
352
|
+
return import_path.default.join(outputDir, sanitizeForFilePath(fileName));
|
|
353
|
+
}
|
|
354
|
+
function sanitizeForFilePath(s) {
|
|
355
|
+
const sanitize = (s2) => s2.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, "-");
|
|
356
|
+
const separator = s.lastIndexOf(".");
|
|
357
|
+
if (separator === -1)
|
|
358
|
+
return sanitize(s);
|
|
359
|
+
return sanitize(s.substring(0, separator)) + "." + sanitize(s.substring(separator + 1));
|
|
360
|
+
}
|
|
361
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
362
|
+
0 && (module.exports = {
|
|
363
|
+
printResponse,
|
|
364
|
+
program
|
|
365
|
+
});
|