ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / mcp / program.js
Source Blame History 111 lines
f7eb47b… lmata 1 "use strict";
f7eb47b… lmata 2 var __create = Object.create;
f7eb47b… lmata 3 var __defProp = Object.defineProperty;
f7eb47b… lmata 4 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
f7eb47b… lmata 5 var __getOwnPropNames = Object.getOwnPropertyNames;
f7eb47b… lmata 6 var __getProtoOf = Object.getPrototypeOf;
f7eb47b… lmata 7 var __hasOwnProp = Object.prototype.hasOwnProperty;
f7eb47b… lmata 8 var __export = (target, all) => {
f7eb47b… lmata 9 for (var name in all)
f7eb47b… lmata 10 __defProp(target, name, { get: all[name], enumerable: true });
f7eb47b… lmata 11 };
f7eb47b… lmata 12 var __copyProps = (to, from, except, desc) => {
f7eb47b… lmata 13 if (from && typeof from === "object" || typeof from === "function") {
f7eb47b… lmata 14 for (let key of __getOwnPropNames(from))
f7eb47b… lmata 15 if (!__hasOwnProp.call(to, key) && key !== except)
f7eb47b… lmata 16 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
f7eb47b… lmata 17 }
f7eb47b… lmata 18 return to;
f7eb47b… lmata 19 };
f7eb47b… lmata 20 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
f7eb47b… lmata 21 // If the importer is in node compatibility mode or this is not an ESM
f7eb47b… lmata 22 // file that has been converted to a CommonJS file using a Babel-
f7eb47b… lmata 23 // compatible transform (i.e. "__esModule" has not been set), then set
f7eb47b… lmata 24 // "default" to the CommonJS "module.exports" for node compatibility.
f7eb47b… lmata 25 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
f7eb47b… lmata 26 mod
f7eb47b… lmata 27 ));
f7eb47b… lmata 28 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
f7eb47b… lmata 29 var program_exports = {};
f7eb47b… lmata 30 __export(program_exports, {
f7eb47b… lmata 31 decorateCommand: () => decorateCommand
f7eb47b… lmata 32 });
f7eb47b… lmata 33 module.exports = __toCommonJS(program_exports);
f7eb47b… lmata 34 var import_fs = __toESM(require("fs"));
f7eb47b… lmata 35 var import_path = __toESM(require("path"));
f7eb47b… lmata 36 var import_utilsBundle = require("playwright-core/lib/utilsBundle");
f7eb47b… lmata 37 var import_server = require("playwright-core/lib/server");
f7eb47b… lmata 38 var mcpServer = __toESM(require("./sdk/server"));
f7eb47b… lmata 39 var import_daemon = require("./terminal/daemon");
f7eb47b… lmata 40 var import_config = require("./browser/config");
f7eb47b… lmata 41 var import_watchdog = require("./browser/watchdog");
f7eb47b… lmata 42 var import_browserContextFactory = require("./browser/browserContextFactory");
f7eb47b… lmata 43 var import_browserServerBackend = require("./browser/browserServerBackend");
f7eb47b… lmata 44 var import_extensionContextFactory = require("./extension/extensionContextFactory");
f7eb47b… lmata 45 function decorateCommand(command, version) {
f7eb47b… lmata 46 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.", import_config.commaSeparatedList).option("--cdp-endpoint <endpoint>", "CDP endpoint to connect to.").option("--cdp-header <headers...>", "CDP headers to send with the connect request, multiple can be specified.", import_config.headerParser).option("--config <path>", "path to the configuration file.").option("--console-level <level>", 'level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels.', import_config.enumParser.bind(null, "--console-level", ["error", "warning", "info", "debug"])).option("--device <device>", 'device to emulate, for example: "iPhone 15"').option("--executable-path <path>", "path to the browser executable.").option("--extension", 'Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed.').option("--grant-permissions <permissions...>", 'List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write".', import_config.commaSeparatedList).option("--headless", "run browser in headless mode, headed by default").option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.").option("--ignore-https-errors", "ignore https errors").option("--init-page <path...>", "path to TypeScript file to evaluate on Playwright page object").option("--init-script <path...>", "path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times.").option("--isolated", "keep the browser profile in memory, do not save it to disk.").option("--image-responses <mode>", 'whether to send image responses to the client. Can be "allow" or "omit", Defaults to "allow".', import_config.enumParser.bind(null, "--image-responses", ["allow", "omit"])).option("--no-sandbox", "disable the sandbox for all process types that are normally sandboxed.").option("--output-dir <path>", "path to the directory for output files.").option("--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")).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"])).addOption(new import_utilsBundle.ProgramOption("--vision", "Legacy option, use --caps=vision instead").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--daemon <socket>", "run as daemon").hideHelp()).action(async (options) => {
f7eb47b… lmata 47 (0, import_watchdog.setupExitWatchdog)();
f7eb47b… lmata 48 if (options.vision) {
f7eb47b… lmata 49 console.error("The --vision option is deprecated, use --caps=vision instead");
f7eb47b… lmata 50 options.caps = "vision";
f7eb47b… lmata 51 }
f7eb47b… lmata 52 const config = await (0, import_config.resolveCLIConfig)(options);
f7eb47b… lmata 53 if (config.saveVideo && !checkFfmpeg()) {
f7eb47b… lmata 54 console.error(import_utilsBundle.colors.red(`
f7eb47b… lmata 55 Error: ffmpeg required to save the video is not installed.`));
f7eb47b… lmata 56 console.error(`
f7eb47b… lmata 57 Please run the command below. It will install a local copy of ffmpeg and will not change any system-wide settings.`);
f7eb47b… lmata 58 console.error(`
f7eb47b… lmata 59 npx playwright install ffmpeg
f7eb47b… lmata 60 `);
f7eb47b… lmata 61 process.exit(1);
f7eb47b… lmata 62 }
f7eb47b… lmata 63 const browserContextFactory = (0, import_browserContextFactory.contextFactory)(config);
f7eb47b… lmata 64 const extensionContextFactory = new import_extensionContextFactory.ExtensionContextFactory(config.browser.launchOptions.channel || "chrome", config.browser.userDataDir, config.browser.launchOptions.executablePath);
f7eb47b… lmata 65 if (options.extension) {
f7eb47b… lmata 66 const serverBackendFactory = {
f7eb47b… lmata 67 name: "Playwright w/ extension",
f7eb47b… lmata 68 nameInConfig: "playwright-extension",
f7eb47b… lmata 69 version,
f7eb47b… lmata 70 create: () => new import_browserServerBackend.BrowserServerBackend(config, extensionContextFactory)
f7eb47b… lmata 71 };
f7eb47b… lmata 72 await mcpServer.start(serverBackendFactory, config.server);
f7eb47b… lmata 73 return;
f7eb47b… lmata 74 }
f7eb47b… lmata 75 if (options.daemon) {
f7eb47b… lmata 76 config.outputDir = import_path.default.join(process.cwd(), ".playwright-cli");
f7eb47b… lmata 77 config.outputMode = "file";
f7eb47b… lmata 78 config.codegen = "none";
f7eb47b… lmata 79 config.snapshot.mode = "full";
f7eb47b… lmata 80 config.capabilities = ["core", "internal", "tracing", "pdf", "vision"];
f7eb47b… lmata 81 const serverBackendFactory = {
f7eb47b… lmata 82 name: "Playwright",
f7eb47b… lmata 83 nameInConfig: "playwright-daemon",
f7eb47b… lmata 84 version,
f7eb47b… lmata 85 create: () => new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory)
f7eb47b… lmata 86 };
f7eb47b… lmata 87 const socketPath = await (0, import_daemon.startMcpDaemonServer)(options.daemon, serverBackendFactory);
f7eb47b… lmata 88 console.error(`Daemon server listening on ${socketPath}`);
f7eb47b… lmata 89 return;
f7eb47b… lmata 90 }
f7eb47b… lmata 91 const factory = {
f7eb47b… lmata 92 name: "Playwright",
f7eb47b… lmata 93 nameInConfig: "playwright",
f7eb47b… lmata 94 version,
f7eb47b… lmata 95 create: () => new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory)
f7eb47b… lmata 96 };
f7eb47b… lmata 97 await mcpServer.start(factory, config.server);
f7eb47b… lmata 98 });
f7eb47b… lmata 99 }
f7eb47b… lmata 100 function checkFfmpeg() {
f7eb47b… lmata 101 try {
f7eb47b… lmata 102 const executable = import_server.registry.findExecutable("ffmpeg");
f7eb47b… lmata 103 return import_fs.default.existsSync(executable.executablePath("javascript"));
f7eb47b… lmata 104 } catch (error) {
f7eb47b… lmata 105 return false;
f7eb47b… lmata 106 }
f7eb47b… lmata 107 }
f7eb47b… lmata 108 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 109 0 && (module.exports = {
f7eb47b… lmata 110 decorateCommand
f7eb47b… lmata 111 });

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button