|
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 config_exports = {}; |
|
f7eb47b…
|
lmata
|
30 |
__export(config_exports, { |
|
f7eb47b…
|
lmata
|
31 |
commaSeparatedList: () => commaSeparatedList, |
|
f7eb47b…
|
lmata
|
32 |
configFromCLIOptions: () => configFromCLIOptions, |
|
f7eb47b…
|
lmata
|
33 |
defaultConfig: () => defaultConfig, |
|
f7eb47b…
|
lmata
|
34 |
dotenvFileLoader: () => dotenvFileLoader, |
|
f7eb47b…
|
lmata
|
35 |
enumParser: () => enumParser, |
|
f7eb47b…
|
lmata
|
36 |
headerParser: () => headerParser, |
|
f7eb47b…
|
lmata
|
37 |
numberParser: () => numberParser, |
|
f7eb47b…
|
lmata
|
38 |
outputDir: () => outputDir, |
|
f7eb47b…
|
lmata
|
39 |
outputFile: () => outputFile, |
|
f7eb47b…
|
lmata
|
40 |
resolutionParser: () => resolutionParser, |
|
f7eb47b…
|
lmata
|
41 |
resolveCLIConfig: () => resolveCLIConfig, |
|
f7eb47b…
|
lmata
|
42 |
resolveConfig: () => resolveConfig, |
|
f7eb47b…
|
lmata
|
43 |
semicolonSeparatedList: () => semicolonSeparatedList |
|
f7eb47b…
|
lmata
|
44 |
}); |
|
f7eb47b…
|
lmata
|
45 |
module.exports = __toCommonJS(config_exports); |
|
f7eb47b…
|
lmata
|
46 |
var import_fs = __toESM(require("fs")); |
|
f7eb47b…
|
lmata
|
47 |
var import_os = __toESM(require("os")); |
|
f7eb47b…
|
lmata
|
48 |
var import_path = __toESM(require("path")); |
|
f7eb47b…
|
lmata
|
49 |
var import_playwright_core = require("playwright-core"); |
|
f7eb47b…
|
lmata
|
50 |
var import_utilsBundle = require("playwright-core/lib/utilsBundle"); |
|
f7eb47b…
|
lmata
|
51 |
var import_util = require("../../util"); |
|
f7eb47b…
|
lmata
|
52 |
var import_server = require("../sdk/server"); |
|
f7eb47b…
|
lmata
|
53 |
const defaultConfig = { |
|
f7eb47b…
|
lmata
|
54 |
browser: { |
|
f7eb47b…
|
lmata
|
55 |
browserName: "chromium", |
|
f7eb47b…
|
lmata
|
56 |
launchOptions: { |
|
f7eb47b…
|
lmata
|
57 |
channel: "chrome", |
|
f7eb47b…
|
lmata
|
58 |
headless: import_os.default.platform() === "linux" && !process.env.DISPLAY, |
|
f7eb47b…
|
lmata
|
59 |
chromiumSandbox: true |
|
f7eb47b…
|
lmata
|
60 |
}, |
|
f7eb47b…
|
lmata
|
61 |
contextOptions: { |
|
f7eb47b…
|
lmata
|
62 |
viewport: null |
|
f7eb47b…
|
lmata
|
63 |
} |
|
f7eb47b…
|
lmata
|
64 |
}, |
|
f7eb47b…
|
lmata
|
65 |
console: { |
|
f7eb47b…
|
lmata
|
66 |
level: "info" |
|
f7eb47b…
|
lmata
|
67 |
}, |
|
f7eb47b…
|
lmata
|
68 |
network: { |
|
f7eb47b…
|
lmata
|
69 |
allowedOrigins: void 0, |
|
f7eb47b…
|
lmata
|
70 |
blockedOrigins: void 0 |
|
f7eb47b…
|
lmata
|
71 |
}, |
|
f7eb47b…
|
lmata
|
72 |
server: {}, |
|
f7eb47b…
|
lmata
|
73 |
saveTrace: false, |
|
f7eb47b…
|
lmata
|
74 |
snapshot: { |
|
f7eb47b…
|
lmata
|
75 |
mode: "incremental", |
|
f7eb47b…
|
lmata
|
76 |
output: "stdout" |
|
f7eb47b…
|
lmata
|
77 |
}, |
|
f7eb47b…
|
lmata
|
78 |
timeouts: { |
|
f7eb47b…
|
lmata
|
79 |
action: 5e3, |
|
f7eb47b…
|
lmata
|
80 |
navigation: 6e4 |
|
f7eb47b…
|
lmata
|
81 |
} |
|
f7eb47b…
|
lmata
|
82 |
}; |
|
f7eb47b…
|
lmata
|
83 |
async function resolveConfig(config) { |
|
f7eb47b…
|
lmata
|
84 |
return mergeConfig(defaultConfig, config); |
|
f7eb47b…
|
lmata
|
85 |
} |
|
f7eb47b…
|
lmata
|
86 |
async function resolveCLIConfig(cliOptions) { |
|
f7eb47b…
|
lmata
|
87 |
const configInFile = await loadConfig(cliOptions.config); |
|
f7eb47b…
|
lmata
|
88 |
const envOverrides = configFromEnv(); |
|
f7eb47b…
|
lmata
|
89 |
const cliOverrides = configFromCLIOptions(cliOptions); |
|
f7eb47b…
|
lmata
|
90 |
let result = defaultConfig; |
|
f7eb47b…
|
lmata
|
91 |
result = mergeConfig(result, configInFile); |
|
f7eb47b…
|
lmata
|
92 |
result = mergeConfig(result, envOverrides); |
|
f7eb47b…
|
lmata
|
93 |
result = mergeConfig(result, cliOverrides); |
|
f7eb47b…
|
lmata
|
94 |
await validateConfig(result); |
|
f7eb47b…
|
lmata
|
95 |
return result; |
|
f7eb47b…
|
lmata
|
96 |
} |
|
f7eb47b…
|
lmata
|
97 |
async function validateConfig(config) { |
|
f7eb47b…
|
lmata
|
98 |
if (config.browser.initScript) { |
|
f7eb47b…
|
lmata
|
99 |
for (const script of config.browser.initScript) { |
|
f7eb47b…
|
lmata
|
100 |
if (!await (0, import_util.fileExistsAsync)(script)) |
|
f7eb47b…
|
lmata
|
101 |
throw new Error(`Init script file does not exist: ${script}`); |
|
f7eb47b…
|
lmata
|
102 |
} |
|
f7eb47b…
|
lmata
|
103 |
} |
|
f7eb47b…
|
lmata
|
104 |
if (config.browser.initPage) { |
|
f7eb47b…
|
lmata
|
105 |
for (const page of config.browser.initPage) { |
|
f7eb47b…
|
lmata
|
106 |
if (!await (0, import_util.fileExistsAsync)(page)) |
|
f7eb47b…
|
lmata
|
107 |
throw new Error(`Init page file does not exist: ${page}`); |
|
f7eb47b…
|
lmata
|
108 |
} |
|
f7eb47b…
|
lmata
|
109 |
} |
|
f7eb47b…
|
lmata
|
110 |
if (config.sharedBrowserContext && config.saveVideo) |
|
f7eb47b…
|
lmata
|
111 |
throw new Error("saveVideo is not supported when sharedBrowserContext is true"); |
|
f7eb47b…
|
lmata
|
112 |
} |
|
f7eb47b…
|
lmata
|
113 |
function configFromCLIOptions(cliOptions) { |
|
f7eb47b…
|
lmata
|
114 |
let browserName; |
|
f7eb47b…
|
lmata
|
115 |
let channel; |
|
f7eb47b…
|
lmata
|
116 |
switch (cliOptions.browser) { |
|
f7eb47b…
|
lmata
|
117 |
case "chrome": |
|
f7eb47b…
|
lmata
|
118 |
case "chrome-beta": |
|
f7eb47b…
|
lmata
|
119 |
case "chrome-canary": |
|
f7eb47b…
|
lmata
|
120 |
case "chrome-dev": |
|
f7eb47b…
|
lmata
|
121 |
case "chromium": |
|
f7eb47b…
|
lmata
|
122 |
case "msedge": |
|
f7eb47b…
|
lmata
|
123 |
case "msedge-beta": |
|
f7eb47b…
|
lmata
|
124 |
case "msedge-canary": |
|
f7eb47b…
|
lmata
|
125 |
case "msedge-dev": |
|
f7eb47b…
|
lmata
|
126 |
browserName = "chromium"; |
|
f7eb47b…
|
lmata
|
127 |
channel = cliOptions.browser; |
|
f7eb47b…
|
lmata
|
128 |
break; |
|
f7eb47b…
|
lmata
|
129 |
case "firefox": |
|
f7eb47b…
|
lmata
|
130 |
browserName = "firefox"; |
|
f7eb47b…
|
lmata
|
131 |
break; |
|
f7eb47b…
|
lmata
|
132 |
case "webkit": |
|
f7eb47b…
|
lmata
|
133 |
browserName = "webkit"; |
|
f7eb47b…
|
lmata
|
134 |
break; |
|
f7eb47b…
|
lmata
|
135 |
} |
|
f7eb47b…
|
lmata
|
136 |
const launchOptions = { |
|
f7eb47b…
|
lmata
|
137 |
channel, |
|
f7eb47b…
|
lmata
|
138 |
executablePath: cliOptions.executablePath, |
|
f7eb47b…
|
lmata
|
139 |
headless: cliOptions.headless |
|
f7eb47b…
|
lmata
|
140 |
}; |
|
f7eb47b…
|
lmata
|
141 |
if (cliOptions.sandbox === false) |
|
f7eb47b…
|
lmata
|
142 |
launchOptions.chromiumSandbox = false; |
|
f7eb47b…
|
lmata
|
143 |
if (cliOptions.proxyServer) { |
|
f7eb47b…
|
lmata
|
144 |
launchOptions.proxy = { |
|
f7eb47b…
|
lmata
|
145 |
server: cliOptions.proxyServer |
|
f7eb47b…
|
lmata
|
146 |
}; |
|
f7eb47b…
|
lmata
|
147 |
if (cliOptions.proxyBypass) |
|
f7eb47b…
|
lmata
|
148 |
launchOptions.proxy.bypass = cliOptions.proxyBypass; |
|
f7eb47b…
|
lmata
|
149 |
} |
|
f7eb47b…
|
lmata
|
150 |
if (cliOptions.device && cliOptions.cdpEndpoint) |
|
f7eb47b…
|
lmata
|
151 |
throw new Error("Device emulation is not supported with cdpEndpoint."); |
|
f7eb47b…
|
lmata
|
152 |
const contextOptions = cliOptions.device ? import_playwright_core.devices[cliOptions.device] : {}; |
|
f7eb47b…
|
lmata
|
153 |
if (cliOptions.storageState) |
|
f7eb47b…
|
lmata
|
154 |
contextOptions.storageState = cliOptions.storageState; |
|
f7eb47b…
|
lmata
|
155 |
if (cliOptions.userAgent) |
|
f7eb47b…
|
lmata
|
156 |
contextOptions.userAgent = cliOptions.userAgent; |
|
f7eb47b…
|
lmata
|
157 |
if (cliOptions.viewportSize) |
|
f7eb47b…
|
lmata
|
158 |
contextOptions.viewport = cliOptions.viewportSize; |
|
f7eb47b…
|
lmata
|
159 |
if (cliOptions.ignoreHttpsErrors) |
|
f7eb47b…
|
lmata
|
160 |
contextOptions.ignoreHTTPSErrors = true; |
|
f7eb47b…
|
lmata
|
161 |
if (cliOptions.blockServiceWorkers) |
|
f7eb47b…
|
lmata
|
162 |
contextOptions.serviceWorkers = "block"; |
|
f7eb47b…
|
lmata
|
163 |
if (cliOptions.grantPermissions) |
|
f7eb47b…
|
lmata
|
164 |
contextOptions.permissions = cliOptions.grantPermissions; |
|
f7eb47b…
|
lmata
|
165 |
const result = { |
|
f7eb47b…
|
lmata
|
166 |
browser: { |
|
f7eb47b…
|
lmata
|
167 |
browserName, |
|
f7eb47b…
|
lmata
|
168 |
isolated: cliOptions.isolated, |
|
f7eb47b…
|
lmata
|
169 |
userDataDir: cliOptions.userDataDir, |
|
f7eb47b…
|
lmata
|
170 |
launchOptions, |
|
f7eb47b…
|
lmata
|
171 |
contextOptions, |
|
f7eb47b…
|
lmata
|
172 |
cdpEndpoint: cliOptions.cdpEndpoint, |
|
f7eb47b…
|
lmata
|
173 |
cdpHeaders: cliOptions.cdpHeader, |
|
f7eb47b…
|
lmata
|
174 |
initPage: cliOptions.initPage, |
|
f7eb47b…
|
lmata
|
175 |
initScript: cliOptions.initScript |
|
f7eb47b…
|
lmata
|
176 |
}, |
|
f7eb47b…
|
lmata
|
177 |
server: { |
|
f7eb47b…
|
lmata
|
178 |
port: cliOptions.port, |
|
f7eb47b…
|
lmata
|
179 |
host: cliOptions.host, |
|
f7eb47b…
|
lmata
|
180 |
allowedHosts: cliOptions.allowedHosts |
|
f7eb47b…
|
lmata
|
181 |
}, |
|
f7eb47b…
|
lmata
|
182 |
capabilities: cliOptions.caps, |
|
f7eb47b…
|
lmata
|
183 |
console: { |
|
f7eb47b…
|
lmata
|
184 |
level: cliOptions.consoleLevel |
|
f7eb47b…
|
lmata
|
185 |
}, |
|
f7eb47b…
|
lmata
|
186 |
network: { |
|
f7eb47b…
|
lmata
|
187 |
allowedOrigins: cliOptions.allowedOrigins, |
|
f7eb47b…
|
lmata
|
188 |
blockedOrigins: cliOptions.blockedOrigins |
|
f7eb47b…
|
lmata
|
189 |
}, |
|
f7eb47b…
|
lmata
|
190 |
allowUnrestrictedFileAccess: cliOptions.allowUnrestrictedFileAccess, |
|
f7eb47b…
|
lmata
|
191 |
codegen: cliOptions.codegen, |
|
f7eb47b…
|
lmata
|
192 |
saveSession: cliOptions.saveSession, |
|
f7eb47b…
|
lmata
|
193 |
saveTrace: cliOptions.saveTrace, |
|
f7eb47b…
|
lmata
|
194 |
saveVideo: cliOptions.saveVideo, |
|
f7eb47b…
|
lmata
|
195 |
secrets: cliOptions.secrets, |
|
f7eb47b…
|
lmata
|
196 |
sharedBrowserContext: cliOptions.sharedBrowserContext, |
|
f7eb47b…
|
lmata
|
197 |
snapshot: cliOptions.snapshotMode ? { mode: cliOptions.snapshotMode } : void 0, |
|
f7eb47b…
|
lmata
|
198 |
outputMode: cliOptions.outputMode, |
|
f7eb47b…
|
lmata
|
199 |
outputDir: cliOptions.outputDir, |
|
f7eb47b…
|
lmata
|
200 |
imageResponses: cliOptions.imageResponses, |
|
f7eb47b…
|
lmata
|
201 |
testIdAttribute: cliOptions.testIdAttribute, |
|
f7eb47b…
|
lmata
|
202 |
timeouts: { |
|
f7eb47b…
|
lmata
|
203 |
action: cliOptions.timeoutAction, |
|
f7eb47b…
|
lmata
|
204 |
navigation: cliOptions.timeoutNavigation |
|
f7eb47b…
|
lmata
|
205 |
} |
|
f7eb47b…
|
lmata
|
206 |
}; |
|
f7eb47b…
|
lmata
|
207 |
return result; |
|
f7eb47b…
|
lmata
|
208 |
} |
|
f7eb47b…
|
lmata
|
209 |
function configFromEnv() { |
|
f7eb47b…
|
lmata
|
210 |
const options = {}; |
|
f7eb47b…
|
lmata
|
211 |
options.allowedHosts = commaSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_HOSTNAMES); |
|
f7eb47b…
|
lmata
|
212 |
options.allowedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_ORIGINS); |
|
f7eb47b…
|
lmata
|
213 |
options.allowUnrestrictedFileAccess = envToBoolean(process.env.PLAYWRIGHT_MCP_ALLOW_UNRESTRICTED_FILE_ACCESS); |
|
f7eb47b…
|
lmata
|
214 |
options.blockedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_BLOCKED_ORIGINS); |
|
f7eb47b…
|
lmata
|
215 |
options.blockServiceWorkers = envToBoolean(process.env.PLAYWRIGHT_MCP_BLOCK_SERVICE_WORKERS); |
|
f7eb47b…
|
lmata
|
216 |
options.browser = envToString(process.env.PLAYWRIGHT_MCP_BROWSER); |
|
f7eb47b…
|
lmata
|
217 |
options.caps = commaSeparatedList(process.env.PLAYWRIGHT_MCP_CAPS); |
|
f7eb47b…
|
lmata
|
218 |
options.cdpEndpoint = envToString(process.env.PLAYWRIGHT_MCP_CDP_ENDPOINT); |
|
f7eb47b…
|
lmata
|
219 |
options.cdpHeader = headerParser(process.env.PLAYWRIGHT_MCP_CDP_HEADERS, {}); |
|
f7eb47b…
|
lmata
|
220 |
options.config = envToString(process.env.PLAYWRIGHT_MCP_CONFIG); |
|
f7eb47b…
|
lmata
|
221 |
if (process.env.PLAYWRIGHT_MCP_CONSOLE_LEVEL) |
|
f7eb47b…
|
lmata
|
222 |
options.consoleLevel = enumParser("--console-level", ["error", "warning", "info", "debug"], process.env.PLAYWRIGHT_MCP_CONSOLE_LEVEL); |
|
f7eb47b…
|
lmata
|
223 |
options.device = envToString(process.env.PLAYWRIGHT_MCP_DEVICE); |
|
f7eb47b…
|
lmata
|
224 |
options.executablePath = envToString(process.env.PLAYWRIGHT_MCP_EXECUTABLE_PATH); |
|
f7eb47b…
|
lmata
|
225 |
options.grantPermissions = commaSeparatedList(process.env.PLAYWRIGHT_MCP_GRANT_PERMISSIONS); |
|
f7eb47b…
|
lmata
|
226 |
options.headless = envToBoolean(process.env.PLAYWRIGHT_MCP_HEADLESS); |
|
f7eb47b…
|
lmata
|
227 |
options.host = envToString(process.env.PLAYWRIGHT_MCP_HOST); |
|
f7eb47b…
|
lmata
|
228 |
options.ignoreHttpsErrors = envToBoolean(process.env.PLAYWRIGHT_MCP_IGNORE_HTTPS_ERRORS); |
|
f7eb47b…
|
lmata
|
229 |
const initPage = envToString(process.env.PLAYWRIGHT_MCP_INIT_PAGE); |
|
f7eb47b…
|
lmata
|
230 |
if (initPage) |
|
f7eb47b…
|
lmata
|
231 |
options.initPage = [initPage]; |
|
f7eb47b…
|
lmata
|
232 |
const initScript = envToString(process.env.PLAYWRIGHT_MCP_INIT_SCRIPT); |
|
f7eb47b…
|
lmata
|
233 |
if (initScript) |
|
f7eb47b…
|
lmata
|
234 |
options.initScript = [initScript]; |
|
f7eb47b…
|
lmata
|
235 |
options.isolated = envToBoolean(process.env.PLAYWRIGHT_MCP_ISOLATED); |
|
f7eb47b…
|
lmata
|
236 |
if (process.env.PLAYWRIGHT_MCP_IMAGE_RESPONSES) |
|
f7eb47b…
|
lmata
|
237 |
options.imageResponses = enumParser("--image-responses", ["allow", "omit"], process.env.PLAYWRIGHT_MCP_IMAGE_RESPONSES); |
|
f7eb47b…
|
lmata
|
238 |
options.sandbox = envToBoolean(process.env.PLAYWRIGHT_MCP_SANDBOX); |
|
f7eb47b…
|
lmata
|
239 |
options.outputDir = envToString(process.env.PLAYWRIGHT_MCP_OUTPUT_DIR); |
|
f7eb47b…
|
lmata
|
240 |
options.port = numberParser(process.env.PLAYWRIGHT_MCP_PORT); |
|
f7eb47b…
|
lmata
|
241 |
options.proxyBypass = envToString(process.env.PLAYWRIGHT_MCP_PROXY_BYPASS); |
|
f7eb47b…
|
lmata
|
242 |
options.proxyServer = envToString(process.env.PLAYWRIGHT_MCP_PROXY_SERVER); |
|
f7eb47b…
|
lmata
|
243 |
options.saveTrace = envToBoolean(process.env.PLAYWRIGHT_MCP_SAVE_TRACE); |
|
f7eb47b…
|
lmata
|
244 |
options.saveVideo = resolutionParser("--save-video", process.env.PLAYWRIGHT_MCP_SAVE_VIDEO); |
|
f7eb47b…
|
lmata
|
245 |
options.secrets = dotenvFileLoader(process.env.PLAYWRIGHT_MCP_SECRETS_FILE); |
|
f7eb47b…
|
lmata
|
246 |
options.storageState = envToString(process.env.PLAYWRIGHT_MCP_STORAGE_STATE); |
|
f7eb47b…
|
lmata
|
247 |
options.testIdAttribute = envToString(process.env.PLAYWRIGHT_MCP_TEST_ID_ATTRIBUTE); |
|
f7eb47b…
|
lmata
|
248 |
options.timeoutAction = numberParser(process.env.PLAYWRIGHT_MCP_TIMEOUT_ACTION); |
|
f7eb47b…
|
lmata
|
249 |
options.timeoutNavigation = numberParser(process.env.PLAYWRIGHT_MCP_TIMEOUT_NAVIGATION); |
|
f7eb47b…
|
lmata
|
250 |
options.userAgent = envToString(process.env.PLAYWRIGHT_MCP_USER_AGENT); |
|
f7eb47b…
|
lmata
|
251 |
options.userDataDir = envToString(process.env.PLAYWRIGHT_MCP_USER_DATA_DIR); |
|
f7eb47b…
|
lmata
|
252 |
options.viewportSize = resolutionParser("--viewport-size", process.env.PLAYWRIGHT_MCP_VIEWPORT_SIZE); |
|
f7eb47b…
|
lmata
|
253 |
return configFromCLIOptions(options); |
|
f7eb47b…
|
lmata
|
254 |
} |
|
f7eb47b…
|
lmata
|
255 |
async function loadConfig(configFile) { |
|
f7eb47b…
|
lmata
|
256 |
if (!configFile) |
|
f7eb47b…
|
lmata
|
257 |
return {}; |
|
f7eb47b…
|
lmata
|
258 |
try { |
|
f7eb47b…
|
lmata
|
259 |
return JSON.parse(await import_fs.default.promises.readFile(configFile, "utf8")); |
|
f7eb47b…
|
lmata
|
260 |
} catch (error) { |
|
f7eb47b…
|
lmata
|
261 |
throw new Error(`Failed to load config file: ${configFile}, ${error}`); |
|
f7eb47b…
|
lmata
|
262 |
} |
|
f7eb47b…
|
lmata
|
263 |
} |
|
f7eb47b…
|
lmata
|
264 |
function tmpDir() { |
|
f7eb47b…
|
lmata
|
265 |
return import_path.default.join(process.env.PW_TMPDIR_FOR_TEST ?? import_os.default.tmpdir(), "playwright-mcp-output"); |
|
f7eb47b…
|
lmata
|
266 |
} |
|
f7eb47b…
|
lmata
|
267 |
function outputDir(config, clientInfo) { |
|
f7eb47b…
|
lmata
|
268 |
const rootPath = (0, import_server.firstRootPath)(clientInfo); |
|
f7eb47b…
|
lmata
|
269 |
return config.outputDir ?? (rootPath ? import_path.default.join(rootPath, ".playwright-mcp") : void 0) ?? import_path.default.join(tmpDir(), String(clientInfo.timestamp)); |
|
f7eb47b…
|
lmata
|
270 |
} |
|
f7eb47b…
|
lmata
|
271 |
async function outputFile(config, clientInfo, fileName, options) { |
|
f7eb47b…
|
lmata
|
272 |
const file = await resolveFile(config, clientInfo, fileName, options); |
|
f7eb47b…
|
lmata
|
273 |
await import_fs.default.promises.mkdir(import_path.default.dirname(file), { recursive: true }); |
|
f7eb47b…
|
lmata
|
274 |
(0, import_utilsBundle.debug)("pw:mcp:file")(options.title, file); |
|
f7eb47b…
|
lmata
|
275 |
return file; |
|
f7eb47b…
|
lmata
|
276 |
} |
|
f7eb47b…
|
lmata
|
277 |
async function resolveFile(config, clientInfo, fileName, options) { |
|
f7eb47b…
|
lmata
|
278 |
const dir = outputDir(config, clientInfo); |
|
f7eb47b…
|
lmata
|
279 |
if (options.origin === "code") |
|
f7eb47b…
|
lmata
|
280 |
return import_path.default.resolve(dir, fileName); |
|
f7eb47b…
|
lmata
|
281 |
if (options.origin === "llm") { |
|
f7eb47b…
|
lmata
|
282 |
fileName = fileName.split("\\").join("/"); |
|
f7eb47b…
|
lmata
|
283 |
const resolvedFile = import_path.default.resolve(dir, fileName); |
|
f7eb47b…
|
lmata
|
284 |
if (!resolvedFile.startsWith(import_path.default.resolve(dir) + import_path.default.sep)) |
|
f7eb47b…
|
lmata
|
285 |
throw new Error(`Resolved file path ${resolvedFile} is outside of the output directory ${dir}. Use relative file names to stay within the output directory.`); |
|
f7eb47b…
|
lmata
|
286 |
return resolvedFile; |
|
f7eb47b…
|
lmata
|
287 |
} |
|
f7eb47b…
|
lmata
|
288 |
return import_path.default.join(dir, sanitizeForFilePath(fileName)); |
|
f7eb47b…
|
lmata
|
289 |
} |
|
f7eb47b…
|
lmata
|
290 |
function pickDefined(obj) { |
|
f7eb47b…
|
lmata
|
291 |
return Object.fromEntries( |
|
f7eb47b…
|
lmata
|
292 |
Object.entries(obj ?? {}).filter(([_, v]) => v !== void 0) |
|
f7eb47b…
|
lmata
|
293 |
); |
|
f7eb47b…
|
lmata
|
294 |
} |
|
f7eb47b…
|
lmata
|
295 |
function mergeConfig(base, overrides) { |
|
f7eb47b…
|
lmata
|
296 |
const browser = { |
|
f7eb47b…
|
lmata
|
297 |
...pickDefined(base.browser), |
|
f7eb47b…
|
lmata
|
298 |
...pickDefined(overrides.browser), |
|
f7eb47b…
|
lmata
|
299 |
browserName: overrides.browser?.browserName ?? base.browser?.browserName ?? "chromium", |
|
f7eb47b…
|
lmata
|
300 |
isolated: overrides.browser?.isolated ?? base.browser?.isolated ?? false, |
|
f7eb47b…
|
lmata
|
301 |
launchOptions: { |
|
f7eb47b…
|
lmata
|
302 |
...pickDefined(base.browser?.launchOptions), |
|
f7eb47b…
|
lmata
|
303 |
...pickDefined(overrides.browser?.launchOptions), |
|
f7eb47b…
|
lmata
|
304 |
...{ assistantMode: true } |
|
f7eb47b…
|
lmata
|
305 |
}, |
|
f7eb47b…
|
lmata
|
306 |
contextOptions: { |
|
f7eb47b…
|
lmata
|
307 |
...pickDefined(base.browser?.contextOptions), |
|
f7eb47b…
|
lmata
|
308 |
...pickDefined(overrides.browser?.contextOptions) |
|
f7eb47b…
|
lmata
|
309 |
} |
|
f7eb47b…
|
lmata
|
310 |
}; |
|
f7eb47b…
|
lmata
|
311 |
if (browser.browserName !== "chromium" && browser.launchOptions) |
|
f7eb47b…
|
lmata
|
312 |
delete browser.launchOptions.channel; |
|
f7eb47b…
|
lmata
|
313 |
return { |
|
f7eb47b…
|
lmata
|
314 |
...pickDefined(base), |
|
f7eb47b…
|
lmata
|
315 |
...pickDefined(overrides), |
|
f7eb47b…
|
lmata
|
316 |
browser, |
|
f7eb47b…
|
lmata
|
317 |
console: { |
|
f7eb47b…
|
lmata
|
318 |
...pickDefined(base.console), |
|
f7eb47b…
|
lmata
|
319 |
...pickDefined(overrides.console) |
|
f7eb47b…
|
lmata
|
320 |
}, |
|
f7eb47b…
|
lmata
|
321 |
network: { |
|
f7eb47b…
|
lmata
|
322 |
...pickDefined(base.network), |
|
f7eb47b…
|
lmata
|
323 |
...pickDefined(overrides.network) |
|
f7eb47b…
|
lmata
|
324 |
}, |
|
f7eb47b…
|
lmata
|
325 |
server: { |
|
f7eb47b…
|
lmata
|
326 |
...pickDefined(base.server), |
|
f7eb47b…
|
lmata
|
327 |
...pickDefined(overrides.server) |
|
f7eb47b…
|
lmata
|
328 |
}, |
|
f7eb47b…
|
lmata
|
329 |
snapshot: { |
|
f7eb47b…
|
lmata
|
330 |
...pickDefined(base.snapshot), |
|
f7eb47b…
|
lmata
|
331 |
...pickDefined(overrides.snapshot) |
|
f7eb47b…
|
lmata
|
332 |
}, |
|
f7eb47b…
|
lmata
|
333 |
timeouts: { |
|
f7eb47b…
|
lmata
|
334 |
...pickDefined(base.timeouts), |
|
f7eb47b…
|
lmata
|
335 |
...pickDefined(overrides.timeouts) |
|
f7eb47b…
|
lmata
|
336 |
} |
|
f7eb47b…
|
lmata
|
337 |
}; |
|
f7eb47b…
|
lmata
|
338 |
} |
|
f7eb47b…
|
lmata
|
339 |
function semicolonSeparatedList(value) { |
|
f7eb47b…
|
lmata
|
340 |
if (!value) |
|
f7eb47b…
|
lmata
|
341 |
return void 0; |
|
f7eb47b…
|
lmata
|
342 |
return value.split(";").map((v) => v.trim()); |
|
f7eb47b…
|
lmata
|
343 |
} |
|
f7eb47b…
|
lmata
|
344 |
function commaSeparatedList(value) { |
|
f7eb47b…
|
lmata
|
345 |
if (!value) |
|
f7eb47b…
|
lmata
|
346 |
return void 0; |
|
f7eb47b…
|
lmata
|
347 |
return value.split(",").map((v) => v.trim()); |
|
f7eb47b…
|
lmata
|
348 |
} |
|
f7eb47b…
|
lmata
|
349 |
function dotenvFileLoader(value) { |
|
f7eb47b…
|
lmata
|
350 |
if (!value) |
|
f7eb47b…
|
lmata
|
351 |
return void 0; |
|
f7eb47b…
|
lmata
|
352 |
return import_utilsBundle.dotenv.parse(import_fs.default.readFileSync(value, "utf8")); |
|
f7eb47b…
|
lmata
|
353 |
} |
|
f7eb47b…
|
lmata
|
354 |
function numberParser(value) { |
|
f7eb47b…
|
lmata
|
355 |
if (!value) |
|
f7eb47b…
|
lmata
|
356 |
return void 0; |
|
f7eb47b…
|
lmata
|
357 |
return +value; |
|
f7eb47b…
|
lmata
|
358 |
} |
|
f7eb47b…
|
lmata
|
359 |
function resolutionParser(name, value) { |
|
f7eb47b…
|
lmata
|
360 |
if (!value) |
|
f7eb47b…
|
lmata
|
361 |
return void 0; |
|
f7eb47b…
|
lmata
|
362 |
if (value.includes("x")) { |
|
f7eb47b…
|
lmata
|
363 |
const [width, height] = value.split("x").map((v) => +v); |
|
f7eb47b…
|
lmata
|
364 |
if (isNaN(width) || isNaN(height) || width <= 0 || height <= 0) |
|
f7eb47b…
|
lmata
|
365 |
throw new Error(`Invalid resolution format: use ${name}="800x600"`); |
|
f7eb47b…
|
lmata
|
366 |
return { width, height }; |
|
f7eb47b…
|
lmata
|
367 |
} |
|
f7eb47b…
|
lmata
|
368 |
if (value.includes(",")) { |
|
f7eb47b…
|
lmata
|
369 |
const [width, height] = value.split(",").map((v) => +v); |
|
f7eb47b…
|
lmata
|
370 |
if (isNaN(width) || isNaN(height) || width <= 0 || height <= 0) |
|
f7eb47b…
|
lmata
|
371 |
throw new Error(`Invalid resolution format: use ${name}="800x600"`); |
|
f7eb47b…
|
lmata
|
372 |
return { width, height }; |
|
f7eb47b…
|
lmata
|
373 |
} |
|
f7eb47b…
|
lmata
|
374 |
throw new Error(`Invalid resolution format: use ${name}="800x600"`); |
|
f7eb47b…
|
lmata
|
375 |
} |
|
f7eb47b…
|
lmata
|
376 |
function headerParser(arg, previous) { |
|
f7eb47b…
|
lmata
|
377 |
if (!arg) |
|
f7eb47b…
|
lmata
|
378 |
return previous || {}; |
|
f7eb47b…
|
lmata
|
379 |
const result = previous || {}; |
|
f7eb47b…
|
lmata
|
380 |
const [name, value] = arg.split(":").map((v) => v.trim()); |
|
f7eb47b…
|
lmata
|
381 |
result[name] = value; |
|
f7eb47b…
|
lmata
|
382 |
return result; |
|
f7eb47b…
|
lmata
|
383 |
} |
|
f7eb47b…
|
lmata
|
384 |
function enumParser(name, options, value) { |
|
f7eb47b…
|
lmata
|
385 |
if (!options.includes(value)) |
|
f7eb47b…
|
lmata
|
386 |
throw new Error(`Invalid ${name}: ${value}. Valid values are: ${options.join(", ")}`); |
|
f7eb47b…
|
lmata
|
387 |
return value; |
|
f7eb47b…
|
lmata
|
388 |
} |
|
f7eb47b…
|
lmata
|
389 |
function envToBoolean(value) { |
|
f7eb47b…
|
lmata
|
390 |
if (value === "true" || value === "1") |
|
f7eb47b…
|
lmata
|
391 |
return true; |
|
f7eb47b…
|
lmata
|
392 |
if (value === "false" || value === "0") |
|
f7eb47b…
|
lmata
|
393 |
return false; |
|
f7eb47b…
|
lmata
|
394 |
return void 0; |
|
f7eb47b…
|
lmata
|
395 |
} |
|
f7eb47b…
|
lmata
|
396 |
function envToString(value) { |
|
f7eb47b…
|
lmata
|
397 |
return value ? value.trim() : void 0; |
|
f7eb47b…
|
lmata
|
398 |
} |
|
f7eb47b…
|
lmata
|
399 |
function sanitizeForFilePath(s) { |
|
f7eb47b…
|
lmata
|
400 |
const sanitize = (s2) => s2.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, "-"); |
|
f7eb47b…
|
lmata
|
401 |
const separator = s.lastIndexOf("."); |
|
f7eb47b…
|
lmata
|
402 |
if (separator === -1) |
|
f7eb47b…
|
lmata
|
403 |
return sanitize(s); |
|
f7eb47b…
|
lmata
|
404 |
return sanitize(s.substring(0, separator)) + "." + sanitize(s.substring(separator + 1)); |
|
f7eb47b…
|
lmata
|
405 |
} |
|
f7eb47b…
|
lmata
|
406 |
// Annotate the CommonJS export names for ESM import in node: |
|
f7eb47b…
|
lmata
|
407 |
0 && (module.exports = { |
|
f7eb47b…
|
lmata
|
408 |
commaSeparatedList, |
|
f7eb47b…
|
lmata
|
409 |
configFromCLIOptions, |
|
f7eb47b…
|
lmata
|
410 |
defaultConfig, |
|
f7eb47b…
|
lmata
|
411 |
dotenvFileLoader, |
|
f7eb47b…
|
lmata
|
412 |
enumParser, |
|
f7eb47b…
|
lmata
|
413 |
headerParser, |
|
f7eb47b…
|
lmata
|
414 |
numberParser, |
|
f7eb47b…
|
lmata
|
415 |
outputDir, |
|
f7eb47b…
|
lmata
|
416 |
outputFile, |
|
f7eb47b…
|
lmata
|
417 |
resolutionParser, |
|
f7eb47b…
|
lmata
|
418 |
resolveCLIConfig, |
|
f7eb47b…
|
lmata
|
419 |
resolveConfig, |
|
f7eb47b…
|
lmata
|
420 |
semicolonSeparatedList |
|
f7eb47b…
|
lmata
|
421 |
}); |