@cotestdev/mcp_playwright 0.0.57 → 0.0.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/mcp/browser/config.js +3 -3
- package/lib/mcp/browser/tools/devtools.js +42 -0
- package/lib/mcp/browser/tools.js +2 -0
- package/lib/mcp/extension/extensionContextFactory.js +2 -3
- package/lib/mcp/program.js +3 -4
- package/lib/mcp/sdk/tool.js +1 -1
- package/lib/mcp/terminal/cli.js +1 -23
- package/lib/mcp/terminal/commands.js +30 -2
- package/lib/mcp/terminal/devtoolsApp.js +248 -0
- package/lib/mcp/terminal/program.js +87 -435
- package/lib/mcp/terminal/registry.js +146 -0
- package/lib/mcp/terminal/session.js +309 -0
- package/package.json +1 -1
- package/lib/index.d.ts +0 -23
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -24
- package/lib/index.js.map +0 -1
|
@@ -169,8 +169,8 @@ function configFromCLIOptions(cliOptions) {
|
|
|
169
169
|
executablePath: cliOptions.executablePath,
|
|
170
170
|
headless: cliOptions.headless
|
|
171
171
|
};
|
|
172
|
-
if (cliOptions.
|
|
173
|
-
launchOptions.chromiumSandbox = cliOptions.
|
|
172
|
+
if (cliOptions.chromiumSandbox !== void 0)
|
|
173
|
+
launchOptions.chromiumSandbox = cliOptions.chromiumSandbox;
|
|
174
174
|
if (cliOptions.proxyServer) {
|
|
175
175
|
launchOptions.proxy = {
|
|
176
176
|
server: cliOptions.proxyServer
|
|
@@ -270,7 +270,7 @@ function configFromEnv() {
|
|
|
270
270
|
options.isolated = envToBoolean(process.env.PLAYWRIGHT_MCP_ISOLATED);
|
|
271
271
|
if (process.env.PLAYWRIGHT_MCP_IMAGE_RESPONSES)
|
|
272
272
|
options.imageResponses = enumParser("--image-responses", ["allow", "omit"], process.env.PLAYWRIGHT_MCP_IMAGE_RESPONSES);
|
|
273
|
-
options.
|
|
273
|
+
options.chromiumSandbox = envToBoolean(process.env.PLAYWRIGHT_MCP_CHROMIUM_SANDBOX);
|
|
274
274
|
options.outputDir = envToString(process.env.PLAYWRIGHT_MCP_OUTPUT_DIR);
|
|
275
275
|
options.port = numberParser(process.env.PLAYWRIGHT_MCP_PORT);
|
|
276
276
|
options.proxyBypass = envToString(process.env.PLAYWRIGHT_MCP_PROXY_BYPASS);
|
|
@@ -0,0 +1,42 @@
|
|
|
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 devtools_exports = {};
|
|
20
|
+
__export(devtools_exports, {
|
|
21
|
+
default: () => devtools_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(devtools_exports);
|
|
24
|
+
var import_mcpBundle = require("../../../mcpBundle");
|
|
25
|
+
var import_tool = require("./tool");
|
|
26
|
+
const devtoolsConnect = (0, import_tool.defineTool)({
|
|
27
|
+
capability: "devtools",
|
|
28
|
+
skillOnly: true,
|
|
29
|
+
schema: {
|
|
30
|
+
name: "browser_devtools_start",
|
|
31
|
+
title: "Start browser DevTools",
|
|
32
|
+
description: "Start browser DevTools",
|
|
33
|
+
inputSchema: import_mcpBundle.z.object({}),
|
|
34
|
+
type: "action"
|
|
35
|
+
},
|
|
36
|
+
handle: async (context, params, response) => {
|
|
37
|
+
const browserContext = await context.ensureBrowserContext();
|
|
38
|
+
const { url } = await browserContext._devtoolsStart();
|
|
39
|
+
response.addTextResult("Server is listening on: " + url);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var devtools_default = [devtoolsConnect];
|
package/lib/mcp/browser/tools.js
CHANGED
|
@@ -36,6 +36,7 @@ var import_common = __toESM(require("./tools/common"));
|
|
|
36
36
|
var import_config = __toESM(require("./tools/config"));
|
|
37
37
|
var import_console = __toESM(require("./tools/console"));
|
|
38
38
|
var import_cookies = __toESM(require("./tools/cookies"));
|
|
39
|
+
var import_devtools = __toESM(require("./tools/devtools"));
|
|
39
40
|
var import_dialogs = __toESM(require("./tools/dialogs"));
|
|
40
41
|
var import_evaluate = __toESM(require("./tools/evaluate"));
|
|
41
42
|
var import_files = __toESM(require("./tools/files"));
|
|
@@ -62,6 +63,7 @@ const browserTools = [
|
|
|
62
63
|
...import_config.default,
|
|
63
64
|
...import_console.default,
|
|
64
65
|
...import_cookies.default,
|
|
66
|
+
...import_devtools.default,
|
|
65
67
|
...import_dialogs.default,
|
|
66
68
|
...import_evaluate.default,
|
|
67
69
|
...import_files.default,
|
|
@@ -37,11 +37,10 @@ var import_utils = require("playwright-core/lib/utils");
|
|
|
37
37
|
var import_cdpRelay = require("./cdpRelay");
|
|
38
38
|
const debugLogger = (0, import_utilsBundle.debug)("pw:mcp:relay");
|
|
39
39
|
class ExtensionContextFactory {
|
|
40
|
-
constructor(browserChannel, userDataDir, executablePath
|
|
40
|
+
constructor(browserChannel, userDataDir, executablePath) {
|
|
41
41
|
this._browserChannel = browserChannel;
|
|
42
42
|
this._userDataDir = userDataDir;
|
|
43
43
|
this._executablePath = executablePath;
|
|
44
|
-
this._forceNewTab = forceNewTab;
|
|
45
44
|
}
|
|
46
45
|
async createContext(clientInfo, abortSignal, options) {
|
|
47
46
|
const browser = await this._obtainBrowser(clientInfo, abortSignal, options?.toolName);
|
|
@@ -55,7 +54,7 @@ class ExtensionContextFactory {
|
|
|
55
54
|
}
|
|
56
55
|
async _obtainBrowser(clientInfo, abortSignal, toolName) {
|
|
57
56
|
const relay = await this._startRelay(abortSignal);
|
|
58
|
-
const forceNewTab =
|
|
57
|
+
const forceNewTab = toolName === "browser_navigate";
|
|
59
58
|
await relay.ensureExtensionConnectionForMCPContext(clientInfo, abortSignal, forceNewTab);
|
|
60
59
|
return await playwright.chromium.connectOverCDP(relay.cdpEndpoint(), { isLocal: true });
|
|
61
60
|
}
|
package/lib/mcp/program.js
CHANGED
|
@@ -42,8 +42,8 @@ var import_browserContextFactory = require("./browser/browserContextFactory");
|
|
|
42
42
|
var import_browserServerBackend = require("./browser/browserServerBackend");
|
|
43
43
|
var import_extensionContextFactory = require("./extension/extensionContextFactory");
|
|
44
44
|
function decorateCommand(command, version) {
|
|
45
|
-
command.option("--allowed-hosts <hosts...>", "comma-separated list of hosts this server is allowed to serve from. Defaults to the host the server is bound to. Pass '*' to disable the host check.", import_config.commaSeparatedList).option("--allowed-origins <origins>", "semicolon-separated list of TRUSTED origins to allow the browser to request. Default is to allow all.\nImportant: *does not* serve as a security boundary and *does not* affect redirects. ", import_config.semicolonSeparatedList).option("--allow-unrestricted-file-access", "allow access to files outside of the workspace roots. Also allows unrestricted access to file:// URLs. By default access to file system is restricted to workspace root directories (or cwd if no roots are configured) only, and navigation to file:// URLs is blocked.").option("--blocked-origins <origins>", "semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed.\nImportant: *does not* serve as a security boundary and *does not* affect redirects.", import_config.semicolonSeparatedList).option("--block-service-workers", "block service workers").option("--browser <browser>", "browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge.").option("--caps <caps>", "comma-separated list of additional capabilities to enable, possible values: vision, pdf, devtools.", import_config.commaSeparatedList).option("--cdp-endpoint <endpoint>", "CDP endpoint to connect to.").option("--cdp-header <headers...>", "CDP headers to send with the connect request, multiple can be specified.", import_config.headerParser).option("--cdp-timeout <timeout>", "timeout in milliseconds for connecting to CDP endpoint, defaults to 30000ms", import_config.numberParser).option("--codegen <lang>", 'specify the language to use for code generation, possible values: "typescript", "none". Default is "typescript".', import_config.enumParser.bind(null, "--codegen", ["none", "typescript"])).option("--config <path>", "path to the configuration file.").option("--console-level <level>", 'level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels.', import_config.enumParser.bind(null, "--console-level", ["error", "warning", "info", "debug"])).option("--device <device>", 'device to emulate, for example: "iPhone 15"').option("--executable-path <path>", "path to the browser executable.").option("--extension", 'Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed.').option("--grant-permissions <permissions...>", 'List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write".', import_config.commaSeparatedList).option("--headless", "run browser in headless mode, headed by default").option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.").option("--ignore-https-errors", "ignore https errors").option("--init-page <path...>", "path to TypeScript file to evaluate on Playwright page object").option("--init-script <path...>", "path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times.").option("--isolated", "keep the browser profile in memory, do not save it to disk.").option("--image-responses <mode>", 'whether to send image responses to the client. Can be "allow" or "omit", Defaults to "allow".', import_config.enumParser.bind(null, "--image-responses", ["allow", "omit"])).option("--
|
|
46
|
-
options.
|
|
45
|
+
command.option("--allowed-hosts <hosts...>", "comma-separated list of hosts this server is allowed to serve from. Defaults to the host the server is bound to. Pass '*' to disable the host check.", import_config.commaSeparatedList).option("--allowed-origins <origins>", "semicolon-separated list of TRUSTED origins to allow the browser to request. Default is to allow all.\nImportant: *does not* serve as a security boundary and *does not* affect redirects. ", import_config.semicolonSeparatedList).option("--allow-unrestricted-file-access", "allow access to files outside of the workspace roots. Also allows unrestricted access to file:// URLs. By default access to file system is restricted to workspace root directories (or cwd if no roots are configured) only, and navigation to file:// URLs is blocked.").option("--blocked-origins <origins>", "semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed.\nImportant: *does not* serve as a security boundary and *does not* affect redirects.", import_config.semicolonSeparatedList).option("--block-service-workers", "block service workers").option("--browser <browser>", "browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge.").option("--caps <caps>", "comma-separated list of additional capabilities to enable, possible values: vision, pdf, devtools.", import_config.commaSeparatedList).option("--cdp-endpoint <endpoint>", "CDP endpoint to connect to.").option("--cdp-header <headers...>", "CDP headers to send with the connect request, multiple can be specified.", import_config.headerParser).option("--cdp-timeout <timeout>", "timeout in milliseconds for connecting to CDP endpoint, defaults to 30000ms", import_config.numberParser).option("--chromium-sandbox", "enable the chromium sandbox. disable with --no-chromium-sandbox.").option("--no-chromium-sandbox", "disable the chromium sandbox.").option("--codegen <lang>", 'specify the language to use for code generation, possible values: "typescript", "none". Default is "typescript".', import_config.enumParser.bind(null, "--codegen", ["none", "typescript"])).option("--config <path>", "path to the configuration file.").option("--console-level <level>", 'level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels.', import_config.enumParser.bind(null, "--console-level", ["error", "warning", "info", "debug"])).option("--device <device>", 'device to emulate, for example: "iPhone 15"').option("--executable-path <path>", "path to the browser executable.").option("--extension", 'Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed.').option("--grant-permissions <permissions...>", 'List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write".', import_config.commaSeparatedList).option("--headless", "run browser in headless mode, headed by default").option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.").option("--ignore-https-errors", "ignore https errors").option("--init-page <path...>", "path to TypeScript file to evaluate on Playwright page object").option("--init-script <path...>", "path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times.").option("--isolated", "keep the browser profile in memory, do not save it to disk.").option("--image-responses <mode>", 'whether to send image responses to the client. Can be "allow" or "omit", Defaults to "allow".', import_config.enumParser.bind(null, "--image-responses", ["allow", "omit"])).option("--output-dir <path>", "path to the directory for output files.").option("--output-mode <mode>", 'whether to save snapshots, console messages, network logs to a file or to the standard output. Can be "file" or "stdout". Default is "stdout".', import_config.enumParser.bind(null, "--output-mode", ["file", "stdout"])).option("--port <port>", "port to listen on for SSE transport.").option("--proxy-bypass <bypass>", 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"').option("--proxy-server <proxy>", 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"').option("--save-session", "Whether to save the Playwright MCP session into the output directory.").option("--save-trace", "Whether to save the Playwright Trace of the session into the output directory.").option("--save-video <size>", 'Whether to save the video of the session into the output directory. For example "--save-video=800x600"', import_config.resolutionParser.bind(null, "--save-video")).option("--secrets <path>", "path to a file containing secrets in the dotenv format", import_config.dotenvFileLoader).option("--shared-browser-context", "reuse the same browser context between all connected HTTP clients.").option("--snapshot-mode <mode>", 'when taking snapshots for responses, specifies the mode to use. Can be "incremental", "full", or "none". Default is incremental.').option("--storage-state <path>", "path to the storage state file for isolated sessions.").option("--test-id-attribute <attribute>", 'specify the attribute to use for test ids, defaults to "data-testid"').option("--timeout-action <timeout>", "specify action timeout in milliseconds, defaults to 5000ms", import_config.numberParser).option("--timeout-navigation <timeout>", "specify navigation timeout in milliseconds, defaults to 60000ms", import_config.numberParser).option("--user-agent <ua string>", "specify user agent string").option("--user-data-dir <path>", "path to the user data directory. If not specified, a temporary directory will be created.").option("--viewport-size <size>", 'specify browser viewport size in pixels, for example "1280x720"', import_config.resolutionParser.bind(null, "--viewport-size")).addOption(new import_utilsBundle.ProgramOption("--vision", "Legacy option, use --caps=vision instead").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--daemon-session <path>", "path to the daemon config.").hideHelp()).action(async (options) => {
|
|
46
|
+
options.chromiumSandbox = options.chromiumSandbox === true ? void 0 : false;
|
|
47
47
|
(0, import_watchdog.setupExitWatchdog)();
|
|
48
48
|
if (options.vision) {
|
|
49
49
|
console.error("The --vision option is deprecated, use --caps=vision instead");
|
|
@@ -63,8 +63,7 @@ Please run the command below. It will install a local copy of ffmpeg and will no
|
|
|
63
63
|
process.exit(1);
|
|
64
64
|
}
|
|
65
65
|
const browserContextFactory = (0, import_browserContextFactory.contextFactory)(config);
|
|
66
|
-
const
|
|
67
|
-
const extensionContextFactory = new import_extensionContextFactory.ExtensionContextFactory(config.browser.launchOptions.channel || "chrome", config.browser.userDataDir, config.browser.launchOptions.executablePath, forceNewTab);
|
|
66
|
+
const extensionContextFactory = new import_extensionContextFactory.ExtensionContextFactory(config.browser.launchOptions.channel || "chrome", config.browser.userDataDir, config.browser.launchOptions.executablePath);
|
|
68
67
|
if (config.sessionConfig) {
|
|
69
68
|
const contextFactory2 = config.extension ? extensionContextFactory : browserContextFactory;
|
|
70
69
|
try {
|
package/lib/mcp/sdk/tool.js
CHANGED
|
@@ -28,7 +28,7 @@ function toMcpTool(tool) {
|
|
|
28
28
|
return {
|
|
29
29
|
name: tool.name,
|
|
30
30
|
description: tool.description,
|
|
31
|
-
inputSchema: import_mcpBundle.
|
|
31
|
+
inputSchema: import_mcpBundle.z.toJSONSchema(tool.inputSchema),
|
|
32
32
|
annotations: {
|
|
33
33
|
title: tool.title,
|
|
34
34
|
readOnlyHint: readOnly,
|
package/lib/mcp/terminal/cli.js
CHANGED
|
@@ -1,28 +1,6 @@
|
|
|
1
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
2
|
var import_program = require("./program");
|
|
25
|
-
(0, import_program.program)(
|
|
3
|
+
(0, import_program.program)().catch((e) => {
|
|
26
4
|
console.error(e.message);
|
|
27
5
|
process.exit(1);
|
|
28
6
|
});
|
|
@@ -49,7 +49,7 @@ const open = (0, import_command.declareCommand)({
|
|
|
49
49
|
persistent: import_mcpBundle.z.boolean().optional().describe("Use persistent browser profile"),
|
|
50
50
|
profile: import_mcpBundle.z.string().optional().describe("Use persistent browser profile, store profile in specified directory.")
|
|
51
51
|
}),
|
|
52
|
-
toolName: "browser_navigate",
|
|
52
|
+
toolName: ({ url }) => url ? "browser_navigate" : "browser_snapshot",
|
|
53
53
|
toolParams: ({ url }) => ({ url: url || "about:blank" })
|
|
54
54
|
});
|
|
55
55
|
const close = (0, import_command.declareCommand)({
|
|
@@ -681,6 +681,22 @@ const videoStop = (0, import_command.declareCommand)({
|
|
|
681
681
|
toolName: "browser_stop_video",
|
|
682
682
|
toolParams: ({ filename }) => ({ filename })
|
|
683
683
|
});
|
|
684
|
+
const devtoolsShow = (0, import_command.declareCommand)({
|
|
685
|
+
name: "show",
|
|
686
|
+
description: "Show browser DevTools",
|
|
687
|
+
category: "devtools",
|
|
688
|
+
args: import_mcpBundle.z.object({}),
|
|
689
|
+
toolName: "",
|
|
690
|
+
toolParams: () => ({})
|
|
691
|
+
});
|
|
692
|
+
const devtoolsStart = (0, import_command.declareCommand)({
|
|
693
|
+
name: "devtools-start",
|
|
694
|
+
description: "Show browser DevTools",
|
|
695
|
+
category: "devtools",
|
|
696
|
+
args: import_mcpBundle.z.object({}),
|
|
697
|
+
toolName: "browser_devtools_start",
|
|
698
|
+
toolParams: () => ({})
|
|
699
|
+
});
|
|
684
700
|
const sessionList = (0, import_command.declareCommand)({
|
|
685
701
|
name: "list",
|
|
686
702
|
description: "List browser sessions",
|
|
@@ -742,6 +758,14 @@ const installBrowser = (0, import_command.declareCommand)({
|
|
|
742
758
|
toolName: "browser_install",
|
|
743
759
|
toolParams: () => ({})
|
|
744
760
|
});
|
|
761
|
+
const tray = (0, import_command.declareCommand)({
|
|
762
|
+
name: "tray",
|
|
763
|
+
description: "Run tray",
|
|
764
|
+
category: "config",
|
|
765
|
+
hidden: true,
|
|
766
|
+
toolName: "",
|
|
767
|
+
toolParams: () => ({})
|
|
768
|
+
});
|
|
745
769
|
const commandsArray = [
|
|
746
770
|
// core category
|
|
747
771
|
open,
|
|
@@ -819,10 +843,14 @@ const commandsArray = [
|
|
|
819
843
|
tracingStop,
|
|
820
844
|
videoStart,
|
|
821
845
|
videoStop,
|
|
846
|
+
devtoolsShow,
|
|
847
|
+
devtoolsStart,
|
|
822
848
|
// session category
|
|
823
849
|
sessionList,
|
|
824
850
|
sessionCloseAll,
|
|
825
|
-
killAll
|
|
851
|
+
killAll,
|
|
852
|
+
// Hidden commands
|
|
853
|
+
tray
|
|
826
854
|
];
|
|
827
855
|
const commands = Object.fromEntries(commandsArray.map((cmd) => [cmd.name, cmd]));
|
|
828
856
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -0,0 +1,248 @@
|
|
|
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 devtoolsApp_exports = {};
|
|
30
|
+
__export(devtoolsApp_exports, {
|
|
31
|
+
syncLocalStorageWithSettings: () => syncLocalStorageWithSettings
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(devtoolsApp_exports);
|
|
34
|
+
var import_fs = __toESM(require("fs"));
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_os = __toESM(require("os"));
|
|
37
|
+
var import_net = __toESM(require("net"));
|
|
38
|
+
var import_playwright_core = require("playwright-core");
|
|
39
|
+
var import_utils = require("playwright-core/lib/utils");
|
|
40
|
+
var import_registry = require("playwright-core/lib/server/registry/index");
|
|
41
|
+
var import_registry2 = require("./registry");
|
|
42
|
+
var import_session = require("./session");
|
|
43
|
+
function readBody(request) {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const chunks = [];
|
|
46
|
+
request.on("data", (chunk) => chunks.push(chunk));
|
|
47
|
+
request.on("end", () => {
|
|
48
|
+
try {
|
|
49
|
+
const text = Buffer.concat(chunks).toString();
|
|
50
|
+
resolve(text ? JSON.parse(text) : {});
|
|
51
|
+
} catch (e) {
|
|
52
|
+
reject(e);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
request.on("error", reject);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function sendJSON(response, data, statusCode = 200) {
|
|
59
|
+
response.statusCode = statusCode;
|
|
60
|
+
response.setHeader("Content-Type", "application/json");
|
|
61
|
+
response.end(JSON.stringify(data));
|
|
62
|
+
}
|
|
63
|
+
async function handleApiRequest(clientInfo, request, response) {
|
|
64
|
+
const url = new URL(request.url, `http://${request.headers.host}`);
|
|
65
|
+
const apiPath = url.pathname;
|
|
66
|
+
if (apiPath === "/api/sessions/list" && request.method === "GET") {
|
|
67
|
+
const registry = await import_registry2.Registry.load();
|
|
68
|
+
const sessions = [];
|
|
69
|
+
for (const [, entries] of registry.entryMap()) {
|
|
70
|
+
for (const entry of entries) {
|
|
71
|
+
const session = new import_session.Session(clientInfo, entry.config);
|
|
72
|
+
const canConnect = await session.canConnect();
|
|
73
|
+
if (canConnect || entry.config.cli.persistent)
|
|
74
|
+
sessions.push({ config: entry.config, canConnect });
|
|
75
|
+
else
|
|
76
|
+
await session.deleteSessionConfig();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
sendJSON(response, { sessions, clientInfo });
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (apiPath === "/api/sessions/close" && request.method === "POST") {
|
|
83
|
+
const body = await readBody(request);
|
|
84
|
+
if (!body.config)
|
|
85
|
+
throw new Error('Missing "config" parameter');
|
|
86
|
+
await new import_session.Session(clientInfo, body.config).stop();
|
|
87
|
+
sendJSON(response, { success: true });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (apiPath === "/api/sessions/delete-data" && request.method === "POST") {
|
|
91
|
+
const body = await readBody(request);
|
|
92
|
+
if (!body.config)
|
|
93
|
+
throw new Error('Missing "config" parameter');
|
|
94
|
+
await new import_session.Session(clientInfo, body.config).deleteData();
|
|
95
|
+
sendJSON(response, { success: true });
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (apiPath === "/api/sessions/run" && request.method === "POST") {
|
|
99
|
+
const body = await readBody(request);
|
|
100
|
+
if (!body.config)
|
|
101
|
+
throw new Error('Missing "config" parameter');
|
|
102
|
+
if (!body.args)
|
|
103
|
+
throw new Error('Missing "args" parameter');
|
|
104
|
+
const result = await new import_session.Session(clientInfo, body.config).run(body.args);
|
|
105
|
+
sendJSON(response, { result });
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (apiPath === "/api/sessions/devtools-start" && request.method === "POST") {
|
|
109
|
+
const body = await readBody(request);
|
|
110
|
+
if (!body.config)
|
|
111
|
+
throw new Error('Missing "config" parameter');
|
|
112
|
+
const result = await new import_session.Session(clientInfo, body.config).run({ _: ["devtools-start"] });
|
|
113
|
+
const match = result.text.match(/Server is listening on: (.+)/);
|
|
114
|
+
if (!match)
|
|
115
|
+
throw new Error("Failed to parse screencast URL from: " + result.text);
|
|
116
|
+
sendJSON(response, { url: match[1] });
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
response.statusCode = 404;
|
|
120
|
+
response.end(JSON.stringify({ error: "Not found" }));
|
|
121
|
+
}
|
|
122
|
+
async function openDevToolsApp() {
|
|
123
|
+
const httpServer = new import_utils.HttpServer();
|
|
124
|
+
const libDir = require.resolve("playwright-core/package.json");
|
|
125
|
+
const devtoolsDir = import_path.default.join(import_path.default.dirname(libDir), "lib/vite/devtools");
|
|
126
|
+
const clientInfo = (0, import_registry2.createClientInfo)();
|
|
127
|
+
httpServer.routePrefix("/api/", (request, response) => {
|
|
128
|
+
handleApiRequest(clientInfo, request, response).catch((e) => {
|
|
129
|
+
response.statusCode = 500;
|
|
130
|
+
response.end(JSON.stringify({ error: e.message }));
|
|
131
|
+
});
|
|
132
|
+
return true;
|
|
133
|
+
});
|
|
134
|
+
httpServer.routePrefix("/", (request, response) => {
|
|
135
|
+
const pathname = new URL(request.url, `http://${request.headers.host}`).pathname;
|
|
136
|
+
const filePath = pathname === "/" ? "index.html" : pathname.substring(1);
|
|
137
|
+
const resolved = import_path.default.join(devtoolsDir, filePath);
|
|
138
|
+
if (!resolved.startsWith(devtoolsDir))
|
|
139
|
+
return false;
|
|
140
|
+
return httpServer.serveFile(request, response, resolved);
|
|
141
|
+
});
|
|
142
|
+
await httpServer.start();
|
|
143
|
+
const url = httpServer.urlPrefix("human-readable");
|
|
144
|
+
const { page } = await launchApp("devtools");
|
|
145
|
+
await page.goto(url);
|
|
146
|
+
return page;
|
|
147
|
+
}
|
|
148
|
+
async function launchApp(appName) {
|
|
149
|
+
const channel = (0, import_registry.findChromiumChannelBestEffort)("javascript");
|
|
150
|
+
const context = await import_playwright_core.chromium.launchPersistentContext("", {
|
|
151
|
+
ignoreDefaultArgs: ["--enable-automation"],
|
|
152
|
+
channel,
|
|
153
|
+
headless: false,
|
|
154
|
+
args: [
|
|
155
|
+
"--app=data:text/html,",
|
|
156
|
+
"--test-type=",
|
|
157
|
+
`--window-size=1280,800`,
|
|
158
|
+
`--window-position=100,100`
|
|
159
|
+
],
|
|
160
|
+
viewport: null
|
|
161
|
+
});
|
|
162
|
+
const [page] = context.pages();
|
|
163
|
+
if (process.platform === "darwin") {
|
|
164
|
+
context.on("page", async (newPage) => {
|
|
165
|
+
if (newPage.mainFrame().url() === "chrome://new-tab-page/") {
|
|
166
|
+
await page.bringToFront();
|
|
167
|
+
await newPage.close();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
page.on("close", () => {
|
|
172
|
+
(0, import_utils.gracefullyProcessExitDoNotHang)(0);
|
|
173
|
+
});
|
|
174
|
+
const image = await import_fs.default.promises.readFile(import_path.default.join(__dirname, "appIcon.png"));
|
|
175
|
+
await page._setDockTile(image);
|
|
176
|
+
await syncLocalStorageWithSettings(page, appName);
|
|
177
|
+
return { context, page };
|
|
178
|
+
}
|
|
179
|
+
async function syncLocalStorageWithSettings(page, appName) {
|
|
180
|
+
const settingsFile = import_path.default.join(import_registry.registryDirectory, ".settings", `${appName}.json`);
|
|
181
|
+
await page.exposeBinding("_saveSerializedSettings", (_, settings2) => {
|
|
182
|
+
import_fs.default.mkdirSync(import_path.default.dirname(settingsFile), { recursive: true });
|
|
183
|
+
import_fs.default.writeFileSync(settingsFile, settings2);
|
|
184
|
+
});
|
|
185
|
+
const settings = await import_fs.default.promises.readFile(settingsFile, "utf-8").catch(() => "{}");
|
|
186
|
+
await page.addInitScript(
|
|
187
|
+
`(${String((settings2) => {
|
|
188
|
+
if (location && location.protocol === "data:")
|
|
189
|
+
return;
|
|
190
|
+
if (window.top !== window)
|
|
191
|
+
return;
|
|
192
|
+
Object.entries(settings2).map(([k, v]) => localStorage[k] = v);
|
|
193
|
+
window.saveSettings = () => {
|
|
194
|
+
window._saveSerializedSettings(JSON.stringify({ ...localStorage }));
|
|
195
|
+
};
|
|
196
|
+
})})(${settings});
|
|
197
|
+
`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
function socketsDirectory() {
|
|
201
|
+
return process.env.PLAYWRIGHT_DAEMON_SOCKETS_DIR || import_path.default.join(import_os.default.tmpdir(), "playwright-cli");
|
|
202
|
+
}
|
|
203
|
+
function devtoolsSocketPath() {
|
|
204
|
+
return process.platform === "win32" ? `\\\\.\\pipe\\playwright-devtools-${process.env.USERNAME || "default"}` : import_path.default.join(socketsDirectory(), "devtools.sock");
|
|
205
|
+
}
|
|
206
|
+
async function acquireSingleton() {
|
|
207
|
+
const socketPath = devtoolsSocketPath();
|
|
208
|
+
return await new Promise((resolve, reject) => {
|
|
209
|
+
const server = import_net.default.createServer();
|
|
210
|
+
server.listen(socketPath, () => resolve(server));
|
|
211
|
+
server.on("error", (err) => {
|
|
212
|
+
if (err.code !== "EADDRINUSE")
|
|
213
|
+
return reject(err);
|
|
214
|
+
const client = import_net.default.connect(socketPath, () => {
|
|
215
|
+
client.write("bringToFront");
|
|
216
|
+
client.end();
|
|
217
|
+
reject(new Error("already running"));
|
|
218
|
+
});
|
|
219
|
+
client.on("error", () => {
|
|
220
|
+
if (process.platform !== "win32")
|
|
221
|
+
import_fs.default.unlinkSync(socketPath);
|
|
222
|
+
server.listen(socketPath, () => resolve(server));
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
async function main() {
|
|
228
|
+
let server;
|
|
229
|
+
process.on("exit", () => server?.close());
|
|
230
|
+
try {
|
|
231
|
+
server = await acquireSingleton();
|
|
232
|
+
} catch {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const page = await openDevToolsApp();
|
|
236
|
+
server.on("connection", (socket) => {
|
|
237
|
+
socket.on("data", (data) => {
|
|
238
|
+
if (data.toString() === "bringToFront")
|
|
239
|
+
page?.bringToFront().catch(() => {
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
void main();
|
|
245
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
246
|
+
0 && (module.exports = {
|
|
247
|
+
syncLocalStorageWithSettings
|
|
248
|
+
});
|