@smoothdeploy/playwright 1.58.3 → 1.60.0-beta-1780662356000

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.
Files changed (182) hide show
  1. package/ThirdPartyNotices.txt +8 -5036
  2. package/lib/agents/agentParser.js +2 -2
  3. package/lib/agents/generateAgents.js +21 -22
  4. package/lib/agents/playwright-test-healer.agent.md +1 -0
  5. package/lib/agents/playwright-test-planner.agent.md +2 -1
  6. package/lib/cli/reportActions.js +78 -0
  7. package/lib/cli/testActions.js +211 -0
  8. package/lib/common/index.js +2898 -0
  9. package/lib/common/index.js.txt +35 -0
  10. package/lib/errorContext.js +130 -0
  11. package/lib/index.js +283 -206
  12. package/lib/{isomorphic/testServerConnection.js → isomorphic.js} +70 -35
  13. package/lib/isomorphic.js.txt +9 -0
  14. package/lib/loader/loaderProcessEntry.js +34 -0
  15. package/lib/loader/loaderProcessEntry.js.txt +9 -0
  16. package/lib/matchers/expect.js +12988 -249
  17. package/lib/matchers/expect.js.LICENSE +693 -0
  18. package/lib/matchers/expect.js.txt +72 -0
  19. package/lib/mcp/test/browserBackend.js +49 -22
  20. package/lib/mcp/test/generatorTools.js +16 -16
  21. package/lib/mcp/test/plannerTools.js +25 -20
  22. package/lib/mcp/test/seed.js +7 -7
  23. package/lib/mcp/test/testBackend.js +30 -30
  24. package/lib/mcp/test/testContext.js +50 -33
  25. package/lib/mcp/test/testTools.js +15 -25
  26. package/lib/{internalsForTest.js → package.js} +13 -8
  27. package/lib/program.js +63 -263
  28. package/lib/runner/index.js +8339 -0
  29. package/lib/runner/index.js.txt +60 -0
  30. package/lib/transform/babelBundle.js +71002 -18
  31. package/lib/transform/babelBundle.js.LICENSE +2359 -0
  32. package/lib/transform/babelBundle.js.txt +325 -0
  33. package/lib/transform/esmLoader.js +5884 -30
  34. package/lib/transform/esmLoader.js.LICENSE +335 -0
  35. package/lib/transform/esmLoader.js.txt +55 -0
  36. package/lib/util.js +37 -34
  37. package/lib/worker/workerProcessEntry.js +3251 -0
  38. package/lib/worker/workerProcessEntry.js.txt +24 -0
  39. package/package.json +5 -16
  40. package/test.mjs +1 -0
  41. package/types/test.d.ts +173 -12
  42. package/types/testReporter.d.ts +7 -5
  43. package/lib/common/config.js +0 -282
  44. package/lib/common/configLoader.js +0 -344
  45. package/lib/common/esmLoaderHost.js +0 -104
  46. package/lib/common/expectBundle.js +0 -28
  47. package/lib/common/expectBundleImpl.js +0 -407
  48. package/lib/common/fixtures.js +0 -302
  49. package/lib/common/ipc.js +0 -60
  50. package/lib/common/poolBuilder.js +0 -85
  51. package/lib/common/process.js +0 -132
  52. package/lib/common/suiteUtils.js +0 -140
  53. package/lib/common/test.js +0 -321
  54. package/lib/common/testLoader.js +0 -101
  55. package/lib/common/testType.js +0 -298
  56. package/lib/common/validators.js +0 -68
  57. package/lib/fsWatcher.js +0 -67
  58. package/lib/isomorphic/events.js +0 -77
  59. package/lib/isomorphic/folders.js +0 -30
  60. package/lib/isomorphic/stringInternPool.js +0 -69
  61. package/lib/isomorphic/teleReceiver.js +0 -521
  62. package/lib/isomorphic/teleSuiteUpdater.js +0 -157
  63. package/lib/isomorphic/testServerInterface.js +0 -16
  64. package/lib/isomorphic/testTree.js +0 -329
  65. package/lib/isomorphic/types.d.js +0 -16
  66. package/lib/loader/loaderMain.js +0 -59
  67. package/lib/matchers/matcherHint.js +0 -44
  68. package/lib/matchers/matchers.js +0 -383
  69. package/lib/matchers/toBeTruthy.js +0 -75
  70. package/lib/matchers/toEqual.js +0 -100
  71. package/lib/matchers/toHaveURL.js +0 -101
  72. package/lib/matchers/toMatchAriaSnapshot.js +0 -159
  73. package/lib/matchers/toMatchSnapshot.js +0 -342
  74. package/lib/matchers/toMatchText.js +0 -99
  75. package/lib/mcp/browser/browserContextFactory.js +0 -329
  76. package/lib/mcp/browser/browserServerBackend.js +0 -84
  77. package/lib/mcp/browser/config.js +0 -421
  78. package/lib/mcp/browser/context.js +0 -244
  79. package/lib/mcp/browser/response.js +0 -278
  80. package/lib/mcp/browser/sessionLog.js +0 -75
  81. package/lib/mcp/browser/tab.js +0 -343
  82. package/lib/mcp/browser/tools/common.js +0 -65
  83. package/lib/mcp/browser/tools/console.js +0 -46
  84. package/lib/mcp/browser/tools/dialogs.js +0 -60
  85. package/lib/mcp/browser/tools/evaluate.js +0 -61
  86. package/lib/mcp/browser/tools/files.js +0 -58
  87. package/lib/mcp/browser/tools/form.js +0 -63
  88. package/lib/mcp/browser/tools/install.js +0 -72
  89. package/lib/mcp/browser/tools/keyboard.js +0 -107
  90. package/lib/mcp/browser/tools/mouse.js +0 -107
  91. package/lib/mcp/browser/tools/navigate.js +0 -71
  92. package/lib/mcp/browser/tools/network.js +0 -63
  93. package/lib/mcp/browser/tools/open.js +0 -57
  94. package/lib/mcp/browser/tools/pdf.js +0 -49
  95. package/lib/mcp/browser/tools/runCode.js +0 -78
  96. package/lib/mcp/browser/tools/screenshot.js +0 -93
  97. package/lib/mcp/browser/tools/snapshot.js +0 -173
  98. package/lib/mcp/browser/tools/tabs.js +0 -67
  99. package/lib/mcp/browser/tools/tool.js +0 -47
  100. package/lib/mcp/browser/tools/tracing.js +0 -74
  101. package/lib/mcp/browser/tools/utils.js +0 -94
  102. package/lib/mcp/browser/tools/verify.js +0 -143
  103. package/lib/mcp/browser/tools/wait.js +0 -63
  104. package/lib/mcp/browser/tools.js +0 -84
  105. package/lib/mcp/browser/watchdog.js +0 -44
  106. package/lib/mcp/config.d.js +0 -16
  107. package/lib/mcp/extension/cdpRelay.js +0 -351
  108. package/lib/mcp/extension/extensionContextFactory.js +0 -76
  109. package/lib/mcp/extension/protocol.js +0 -28
  110. package/lib/mcp/index.js +0 -61
  111. package/lib/mcp/log.js +0 -35
  112. package/lib/mcp/program.js +0 -111
  113. package/lib/mcp/sdk/exports.js +0 -28
  114. package/lib/mcp/sdk/http.js +0 -152
  115. package/lib/mcp/sdk/inProcessTransport.js +0 -71
  116. package/lib/mcp/sdk/server.js +0 -223
  117. package/lib/mcp/sdk/tool.js +0 -47
  118. package/lib/mcp/terminal/cli.js +0 -296
  119. package/lib/mcp/terminal/command.js +0 -56
  120. package/lib/mcp/terminal/commands.js +0 -333
  121. package/lib/mcp/terminal/daemon.js +0 -129
  122. package/lib/mcp/terminal/help.json +0 -32
  123. package/lib/mcp/terminal/helpGenerator.js +0 -88
  124. package/lib/mcp/terminal/socketConnection.js +0 -80
  125. package/lib/plugins/gitCommitInfoPlugin.js +0 -198
  126. package/lib/plugins/index.js +0 -28
  127. package/lib/plugins/webServerPlugin.js +0 -237
  128. package/lib/reporters/base.js +0 -634
  129. package/lib/reporters/blob.js +0 -138
  130. package/lib/reporters/dot.js +0 -99
  131. package/lib/reporters/empty.js +0 -32
  132. package/lib/reporters/github.js +0 -128
  133. package/lib/reporters/html.js +0 -633
  134. package/lib/reporters/internalReporter.js +0 -138
  135. package/lib/reporters/json.js +0 -254
  136. package/lib/reporters/junit.js +0 -232
  137. package/lib/reporters/line.js +0 -131
  138. package/lib/reporters/list.js +0 -253
  139. package/lib/reporters/listModeReporter.js +0 -69
  140. package/lib/reporters/markdown.js +0 -144
  141. package/lib/reporters/merge.js +0 -558
  142. package/lib/reporters/multiplexer.js +0 -112
  143. package/lib/reporters/reporterV2.js +0 -102
  144. package/lib/reporters/smoothdeploy.js +0 -333
  145. package/lib/reporters/teleEmitter.js +0 -317
  146. package/lib/reporters/versions/blobV1.js +0 -16
  147. package/lib/runner/dispatcher.js +0 -531
  148. package/lib/runner/failureTracker.js +0 -72
  149. package/lib/runner/lastRun.js +0 -77
  150. package/lib/runner/loadUtils.js +0 -334
  151. package/lib/runner/loaderHost.js +0 -89
  152. package/lib/runner/processHost.js +0 -180
  153. package/lib/runner/projectUtils.js +0 -241
  154. package/lib/runner/rebase.js +0 -189
  155. package/lib/runner/reporters.js +0 -140
  156. package/lib/runner/sigIntWatcher.js +0 -96
  157. package/lib/runner/storage.js +0 -91
  158. package/lib/runner/taskRunner.js +0 -127
  159. package/lib/runner/tasks.js +0 -410
  160. package/lib/runner/testGroups.js +0 -125
  161. package/lib/runner/testRunner.js +0 -398
  162. package/lib/runner/testServer.js +0 -269
  163. package/lib/runner/uiModeReporter.js +0 -30
  164. package/lib/runner/vcs.js +0 -72
  165. package/lib/runner/watchMode.js +0 -396
  166. package/lib/runner/workerHost.js +0 -104
  167. package/lib/third_party/pirates.js +0 -62
  168. package/lib/third_party/tsconfig-loader.js +0 -103
  169. package/lib/transform/babelBundleImpl.js +0 -461
  170. package/lib/transform/compilationCache.js +0 -274
  171. package/lib/transform/md.js +0 -221
  172. package/lib/transform/portTransport.js +0 -67
  173. package/lib/transform/transform.js +0 -303
  174. package/lib/utilsBundle.js +0 -50
  175. package/lib/utilsBundleImpl.js +0 -103
  176. package/lib/worker/fixtureRunner.js +0 -262
  177. package/lib/worker/testInfo.js +0 -536
  178. package/lib/worker/testTracing.js +0 -345
  179. package/lib/worker/timeoutManager.js +0 -174
  180. package/lib/worker/util.js +0 -31
  181. package/lib/worker/workerMain.js +0 -530
  182. /package/lib/{common/globals.js → globals.js} +0 -0
@@ -1,421 +0,0 @@
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 config_exports = {};
30
- __export(config_exports, {
31
- commaSeparatedList: () => commaSeparatedList,
32
- configFromCLIOptions: () => configFromCLIOptions,
33
- defaultConfig: () => defaultConfig,
34
- dotenvFileLoader: () => dotenvFileLoader,
35
- enumParser: () => enumParser,
36
- headerParser: () => headerParser,
37
- numberParser: () => numberParser,
38
- outputDir: () => outputDir,
39
- outputFile: () => outputFile,
40
- resolutionParser: () => resolutionParser,
41
- resolveCLIConfig: () => resolveCLIConfig,
42
- resolveConfig: () => resolveConfig,
43
- semicolonSeparatedList: () => semicolonSeparatedList
44
- });
45
- module.exports = __toCommonJS(config_exports);
46
- var import_fs = __toESM(require("fs"));
47
- var import_os = __toESM(require("os"));
48
- var import_path = __toESM(require("path"));
49
- var import_playwright_core = require("playwright-core");
50
- var import_utilsBundle = require("playwright-core/lib/utilsBundle");
51
- var import_util = require("../../util");
52
- var import_server = require("../sdk/server");
53
- const defaultConfig = {
54
- browser: {
55
- browserName: "chromium",
56
- launchOptions: {
57
- channel: "chrome",
58
- headless: import_os.default.platform() === "linux" && !process.env.DISPLAY,
59
- chromiumSandbox: true
60
- },
61
- contextOptions: {
62
- viewport: null
63
- }
64
- },
65
- console: {
66
- level: "info"
67
- },
68
- network: {
69
- allowedOrigins: void 0,
70
- blockedOrigins: void 0
71
- },
72
- server: {},
73
- saveTrace: false,
74
- snapshot: {
75
- mode: "incremental",
76
- output: "stdout"
77
- },
78
- timeouts: {
79
- action: 5e3,
80
- navigation: 6e4
81
- }
82
- };
83
- async function resolveConfig(config) {
84
- return mergeConfig(defaultConfig, config);
85
- }
86
- async function resolveCLIConfig(cliOptions) {
87
- const configInFile = await loadConfig(cliOptions.config);
88
- const envOverrides = configFromEnv();
89
- const cliOverrides = configFromCLIOptions(cliOptions);
90
- let result = defaultConfig;
91
- result = mergeConfig(result, configInFile);
92
- result = mergeConfig(result, envOverrides);
93
- result = mergeConfig(result, cliOverrides);
94
- await validateConfig(result);
95
- return result;
96
- }
97
- async function validateConfig(config) {
98
- if (config.browser.initScript) {
99
- for (const script of config.browser.initScript) {
100
- if (!await (0, import_util.fileExistsAsync)(script))
101
- throw new Error(`Init script file does not exist: ${script}`);
102
- }
103
- }
104
- if (config.browser.initPage) {
105
- for (const page of config.browser.initPage) {
106
- if (!await (0, import_util.fileExistsAsync)(page))
107
- throw new Error(`Init page file does not exist: ${page}`);
108
- }
109
- }
110
- if (config.sharedBrowserContext && config.saveVideo)
111
- throw new Error("saveVideo is not supported when sharedBrowserContext is true");
112
- }
113
- function configFromCLIOptions(cliOptions) {
114
- let browserName;
115
- let channel;
116
- switch (cliOptions.browser) {
117
- case "chrome":
118
- case "chrome-beta":
119
- case "chrome-canary":
120
- case "chrome-dev":
121
- case "chromium":
122
- case "msedge":
123
- case "msedge-beta":
124
- case "msedge-canary":
125
- case "msedge-dev":
126
- browserName = "chromium";
127
- channel = cliOptions.browser;
128
- break;
129
- case "firefox":
130
- browserName = "firefox";
131
- break;
132
- case "webkit":
133
- browserName = "webkit";
134
- break;
135
- }
136
- const launchOptions = {
137
- channel,
138
- executablePath: cliOptions.executablePath,
139
- headless: cliOptions.headless
140
- };
141
- if (cliOptions.sandbox === false)
142
- launchOptions.chromiumSandbox = false;
143
- if (cliOptions.proxyServer) {
144
- launchOptions.proxy = {
145
- server: cliOptions.proxyServer
146
- };
147
- if (cliOptions.proxyBypass)
148
- launchOptions.proxy.bypass = cliOptions.proxyBypass;
149
- }
150
- if (cliOptions.device && cliOptions.cdpEndpoint)
151
- throw new Error("Device emulation is not supported with cdpEndpoint.");
152
- const contextOptions = cliOptions.device ? import_playwright_core.devices[cliOptions.device] : {};
153
- if (cliOptions.storageState)
154
- contextOptions.storageState = cliOptions.storageState;
155
- if (cliOptions.userAgent)
156
- contextOptions.userAgent = cliOptions.userAgent;
157
- if (cliOptions.viewportSize)
158
- contextOptions.viewport = cliOptions.viewportSize;
159
- if (cliOptions.ignoreHttpsErrors)
160
- contextOptions.ignoreHTTPSErrors = true;
161
- if (cliOptions.blockServiceWorkers)
162
- contextOptions.serviceWorkers = "block";
163
- if (cliOptions.grantPermissions)
164
- contextOptions.permissions = cliOptions.grantPermissions;
165
- const result = {
166
- browser: {
167
- browserName,
168
- isolated: cliOptions.isolated,
169
- userDataDir: cliOptions.userDataDir,
170
- launchOptions,
171
- contextOptions,
172
- cdpEndpoint: cliOptions.cdpEndpoint,
173
- cdpHeaders: cliOptions.cdpHeader,
174
- initPage: cliOptions.initPage,
175
- initScript: cliOptions.initScript
176
- },
177
- server: {
178
- port: cliOptions.port,
179
- host: cliOptions.host,
180
- allowedHosts: cliOptions.allowedHosts
181
- },
182
- capabilities: cliOptions.caps,
183
- console: {
184
- level: cliOptions.consoleLevel
185
- },
186
- network: {
187
- allowedOrigins: cliOptions.allowedOrigins,
188
- blockedOrigins: cliOptions.blockedOrigins
189
- },
190
- allowUnrestrictedFileAccess: cliOptions.allowUnrestrictedFileAccess,
191
- codegen: cliOptions.codegen,
192
- saveSession: cliOptions.saveSession,
193
- saveTrace: cliOptions.saveTrace,
194
- saveVideo: cliOptions.saveVideo,
195
- secrets: cliOptions.secrets,
196
- sharedBrowserContext: cliOptions.sharedBrowserContext,
197
- snapshot: cliOptions.snapshotMode ? { mode: cliOptions.snapshotMode } : void 0,
198
- outputMode: cliOptions.outputMode,
199
- outputDir: cliOptions.outputDir,
200
- imageResponses: cliOptions.imageResponses,
201
- testIdAttribute: cliOptions.testIdAttribute,
202
- timeouts: {
203
- action: cliOptions.timeoutAction,
204
- navigation: cliOptions.timeoutNavigation
205
- }
206
- };
207
- return result;
208
- }
209
- function configFromEnv() {
210
- const options = {};
211
- options.allowedHosts = commaSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_HOSTNAMES);
212
- options.allowedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_ORIGINS);
213
- options.allowUnrestrictedFileAccess = envToBoolean(process.env.PLAYWRIGHT_MCP_ALLOW_UNRESTRICTED_FILE_ACCESS);
214
- options.blockedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_BLOCKED_ORIGINS);
215
- options.blockServiceWorkers = envToBoolean(process.env.PLAYWRIGHT_MCP_BLOCK_SERVICE_WORKERS);
216
- options.browser = envToString(process.env.PLAYWRIGHT_MCP_BROWSER);
217
- options.caps = commaSeparatedList(process.env.PLAYWRIGHT_MCP_CAPS);
218
- options.cdpEndpoint = envToString(process.env.PLAYWRIGHT_MCP_CDP_ENDPOINT);
219
- options.cdpHeader = headerParser(process.env.PLAYWRIGHT_MCP_CDP_HEADERS, {});
220
- options.config = envToString(process.env.PLAYWRIGHT_MCP_CONFIG);
221
- if (process.env.PLAYWRIGHT_MCP_CONSOLE_LEVEL)
222
- options.consoleLevel = enumParser("--console-level", ["error", "warning", "info", "debug"], process.env.PLAYWRIGHT_MCP_CONSOLE_LEVEL);
223
- options.device = envToString(process.env.PLAYWRIGHT_MCP_DEVICE);
224
- options.executablePath = envToString(process.env.PLAYWRIGHT_MCP_EXECUTABLE_PATH);
225
- options.grantPermissions = commaSeparatedList(process.env.PLAYWRIGHT_MCP_GRANT_PERMISSIONS);
226
- options.headless = envToBoolean(process.env.PLAYWRIGHT_MCP_HEADLESS);
227
- options.host = envToString(process.env.PLAYWRIGHT_MCP_HOST);
228
- options.ignoreHttpsErrors = envToBoolean(process.env.PLAYWRIGHT_MCP_IGNORE_HTTPS_ERRORS);
229
- const initPage = envToString(process.env.PLAYWRIGHT_MCP_INIT_PAGE);
230
- if (initPage)
231
- options.initPage = [initPage];
232
- const initScript = envToString(process.env.PLAYWRIGHT_MCP_INIT_SCRIPT);
233
- if (initScript)
234
- options.initScript = [initScript];
235
- options.isolated = envToBoolean(process.env.PLAYWRIGHT_MCP_ISOLATED);
236
- if (process.env.PLAYWRIGHT_MCP_IMAGE_RESPONSES)
237
- options.imageResponses = enumParser("--image-responses", ["allow", "omit"], process.env.PLAYWRIGHT_MCP_IMAGE_RESPONSES);
238
- options.sandbox = envToBoolean(process.env.PLAYWRIGHT_MCP_SANDBOX);
239
- options.outputDir = envToString(process.env.PLAYWRIGHT_MCP_OUTPUT_DIR);
240
- options.port = numberParser(process.env.PLAYWRIGHT_MCP_PORT);
241
- options.proxyBypass = envToString(process.env.PLAYWRIGHT_MCP_PROXY_BYPASS);
242
- options.proxyServer = envToString(process.env.PLAYWRIGHT_MCP_PROXY_SERVER);
243
- options.saveTrace = envToBoolean(process.env.PLAYWRIGHT_MCP_SAVE_TRACE);
244
- options.saveVideo = resolutionParser("--save-video", process.env.PLAYWRIGHT_MCP_SAVE_VIDEO);
245
- options.secrets = dotenvFileLoader(process.env.PLAYWRIGHT_MCP_SECRETS_FILE);
246
- options.storageState = envToString(process.env.PLAYWRIGHT_MCP_STORAGE_STATE);
247
- options.testIdAttribute = envToString(process.env.PLAYWRIGHT_MCP_TEST_ID_ATTRIBUTE);
248
- options.timeoutAction = numberParser(process.env.PLAYWRIGHT_MCP_TIMEOUT_ACTION);
249
- options.timeoutNavigation = numberParser(process.env.PLAYWRIGHT_MCP_TIMEOUT_NAVIGATION);
250
- options.userAgent = envToString(process.env.PLAYWRIGHT_MCP_USER_AGENT);
251
- options.userDataDir = envToString(process.env.PLAYWRIGHT_MCP_USER_DATA_DIR);
252
- options.viewportSize = resolutionParser("--viewport-size", process.env.PLAYWRIGHT_MCP_VIEWPORT_SIZE);
253
- return configFromCLIOptions(options);
254
- }
255
- async function loadConfig(configFile) {
256
- if (!configFile)
257
- return {};
258
- try {
259
- return JSON.parse(await import_fs.default.promises.readFile(configFile, "utf8"));
260
- } catch (error) {
261
- throw new Error(`Failed to load config file: ${configFile}, ${error}`);
262
- }
263
- }
264
- function tmpDir() {
265
- return import_path.default.join(process.env.PW_TMPDIR_FOR_TEST ?? import_os.default.tmpdir(), "playwright-mcp-output");
266
- }
267
- function outputDir(config, clientInfo) {
268
- const rootPath = (0, import_server.firstRootPath)(clientInfo);
269
- return config.outputDir ?? (rootPath ? import_path.default.join(rootPath, ".playwright-mcp") : void 0) ?? import_path.default.join(tmpDir(), String(clientInfo.timestamp));
270
- }
271
- async function outputFile(config, clientInfo, fileName, options) {
272
- const file = await resolveFile(config, clientInfo, fileName, options);
273
- await import_fs.default.promises.mkdir(import_path.default.dirname(file), { recursive: true });
274
- (0, import_utilsBundle.debug)("pw:mcp:file")(options.title, file);
275
- return file;
276
- }
277
- async function resolveFile(config, clientInfo, fileName, options) {
278
- const dir = outputDir(config, clientInfo);
279
- if (options.origin === "code")
280
- return import_path.default.resolve(dir, fileName);
281
- if (options.origin === "llm") {
282
- fileName = fileName.split("\\").join("/");
283
- const resolvedFile = import_path.default.resolve(dir, fileName);
284
- if (!resolvedFile.startsWith(import_path.default.resolve(dir) + import_path.default.sep))
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.`);
286
- return resolvedFile;
287
- }
288
- return import_path.default.join(dir, sanitizeForFilePath(fileName));
289
- }
290
- function pickDefined(obj) {
291
- return Object.fromEntries(
292
- Object.entries(obj ?? {}).filter(([_, v]) => v !== void 0)
293
- );
294
- }
295
- function mergeConfig(base, overrides) {
296
- const browser = {
297
- ...pickDefined(base.browser),
298
- ...pickDefined(overrides.browser),
299
- browserName: overrides.browser?.browserName ?? base.browser?.browserName ?? "chromium",
300
- isolated: overrides.browser?.isolated ?? base.browser?.isolated ?? false,
301
- launchOptions: {
302
- ...pickDefined(base.browser?.launchOptions),
303
- ...pickDefined(overrides.browser?.launchOptions),
304
- ...{ assistantMode: true }
305
- },
306
- contextOptions: {
307
- ...pickDefined(base.browser?.contextOptions),
308
- ...pickDefined(overrides.browser?.contextOptions)
309
- }
310
- };
311
- if (browser.browserName !== "chromium" && browser.launchOptions)
312
- delete browser.launchOptions.channel;
313
- return {
314
- ...pickDefined(base),
315
- ...pickDefined(overrides),
316
- browser,
317
- console: {
318
- ...pickDefined(base.console),
319
- ...pickDefined(overrides.console)
320
- },
321
- network: {
322
- ...pickDefined(base.network),
323
- ...pickDefined(overrides.network)
324
- },
325
- server: {
326
- ...pickDefined(base.server),
327
- ...pickDefined(overrides.server)
328
- },
329
- snapshot: {
330
- ...pickDefined(base.snapshot),
331
- ...pickDefined(overrides.snapshot)
332
- },
333
- timeouts: {
334
- ...pickDefined(base.timeouts),
335
- ...pickDefined(overrides.timeouts)
336
- }
337
- };
338
- }
339
- function semicolonSeparatedList(value) {
340
- if (!value)
341
- return void 0;
342
- return value.split(";").map((v) => v.trim());
343
- }
344
- function commaSeparatedList(value) {
345
- if (!value)
346
- return void 0;
347
- return value.split(",").map((v) => v.trim());
348
- }
349
- function dotenvFileLoader(value) {
350
- if (!value)
351
- return void 0;
352
- return import_utilsBundle.dotenv.parse(import_fs.default.readFileSync(value, "utf8"));
353
- }
354
- function numberParser(value) {
355
- if (!value)
356
- return void 0;
357
- return +value;
358
- }
359
- function resolutionParser(name, value) {
360
- if (!value)
361
- return void 0;
362
- if (value.includes("x")) {
363
- const [width, height] = value.split("x").map((v) => +v);
364
- if (isNaN(width) || isNaN(height) || width <= 0 || height <= 0)
365
- throw new Error(`Invalid resolution format: use ${name}="800x600"`);
366
- return { width, height };
367
- }
368
- if (value.includes(",")) {
369
- const [width, height] = value.split(",").map((v) => +v);
370
- if (isNaN(width) || isNaN(height) || width <= 0 || height <= 0)
371
- throw new Error(`Invalid resolution format: use ${name}="800x600"`);
372
- return { width, height };
373
- }
374
- throw new Error(`Invalid resolution format: use ${name}="800x600"`);
375
- }
376
- function headerParser(arg, previous) {
377
- if (!arg)
378
- return previous || {};
379
- const result = previous || {};
380
- const [name, value] = arg.split(":").map((v) => v.trim());
381
- result[name] = value;
382
- return result;
383
- }
384
- function enumParser(name, options, value) {
385
- if (!options.includes(value))
386
- throw new Error(`Invalid ${name}: ${value}. Valid values are: ${options.join(", ")}`);
387
- return value;
388
- }
389
- function envToBoolean(value) {
390
- if (value === "true" || value === "1")
391
- return true;
392
- if (value === "false" || value === "0")
393
- return false;
394
- return void 0;
395
- }
396
- function envToString(value) {
397
- return value ? value.trim() : void 0;
398
- }
399
- function sanitizeForFilePath(s) {
400
- const sanitize = (s2) => s2.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, "-");
401
- const separator = s.lastIndexOf(".");
402
- if (separator === -1)
403
- return sanitize(s);
404
- return sanitize(s.substring(0, separator)) + "." + sanitize(s.substring(separator + 1));
405
- }
406
- // Annotate the CommonJS export names for ESM import in node:
407
- 0 && (module.exports = {
408
- commaSeparatedList,
409
- configFromCLIOptions,
410
- defaultConfig,
411
- dotenvFileLoader,
412
- enumParser,
413
- headerParser,
414
- numberParser,
415
- outputDir,
416
- outputFile,
417
- resolutionParser,
418
- resolveCLIConfig,
419
- resolveConfig,
420
- semicolonSeparatedList
421
- });
@@ -1,244 +0,0 @@
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 context_exports = {};
30
- __export(context_exports, {
31
- Context: () => Context
32
- });
33
- module.exports = __toCommonJS(context_exports);
34
- var import_utilsBundle = require("playwright-core/lib/utilsBundle");
35
- var import_utils = require("playwright-core/lib/utils");
36
- var import_playwright_core = require("playwright-core");
37
- var import_url = require("url");
38
- var import_os = __toESM(require("os"));
39
- var import_log = require("../log");
40
- var import_tab = require("./tab");
41
- var import_config = require("./config");
42
- const testDebug = (0, import_utilsBundle.debug)("pw:mcp:test");
43
- class Context {
44
- constructor(options) {
45
- this._tabs = [];
46
- this._abortController = new AbortController();
47
- this.config = options.config;
48
- this.sessionLog = options.sessionLog;
49
- this.options = options;
50
- this._browserContextFactory = options.browserContextFactory;
51
- this._clientInfo = options.clientInfo;
52
- testDebug("create context");
53
- Context._allContexts.add(this);
54
- }
55
- static {
56
- this._allContexts = /* @__PURE__ */ new Set();
57
- }
58
- static async disposeAll() {
59
- await Promise.all([...Context._allContexts].map((context) => context.dispose()));
60
- }
61
- tabs() {
62
- return this._tabs;
63
- }
64
- currentTab() {
65
- return this._currentTab;
66
- }
67
- currentTabOrDie() {
68
- if (!this._currentTab)
69
- throw new Error("No open pages available.");
70
- return this._currentTab;
71
- }
72
- async newTab() {
73
- const { browserContext } = await this._ensureBrowserContext({});
74
- const page = await browserContext.newPage();
75
- this._currentTab = this._tabs.find((t) => t.page === page);
76
- return this._currentTab;
77
- }
78
- async selectTab(index) {
79
- const tab = this._tabs[index];
80
- if (!tab)
81
- throw new Error(`Tab ${index} not found`);
82
- await tab.page.bringToFront();
83
- this._currentTab = tab;
84
- return tab;
85
- }
86
- async ensureTab(options = {}) {
87
- const { browserContext } = await this._ensureBrowserContext(options);
88
- if (!this._currentTab)
89
- await browserContext.newPage();
90
- return this._currentTab;
91
- }
92
- async closeTab(index) {
93
- const tab = index === void 0 ? this._currentTab : this._tabs[index];
94
- if (!tab)
95
- throw new Error(`Tab ${index} not found`);
96
- const url = tab.page.url();
97
- await tab.page.close();
98
- return url;
99
- }
100
- async outputFile(fileName, options) {
101
- return (0, import_config.outputFile)(this.config, this._clientInfo, fileName, options);
102
- }
103
- _onPageCreated(page) {
104
- const tab = new import_tab.Tab(this, page, (tab2) => this._onPageClosed(tab2));
105
- this._tabs.push(tab);
106
- if (!this._currentTab)
107
- this._currentTab = tab;
108
- }
109
- _onPageClosed(tab) {
110
- const index = this._tabs.indexOf(tab);
111
- if (index === -1)
112
- return;
113
- this._tabs.splice(index, 1);
114
- if (this._currentTab === tab)
115
- this._currentTab = this._tabs[Math.min(index, this._tabs.length - 1)];
116
- if (!this._tabs.length)
117
- void this.closeBrowserContext();
118
- }
119
- async closeBrowserContext() {
120
- if (!this._closeBrowserContextPromise)
121
- this._closeBrowserContextPromise = this._closeBrowserContextImpl().catch(import_log.logUnhandledError);
122
- await this._closeBrowserContextPromise;
123
- this._closeBrowserContextPromise = void 0;
124
- }
125
- isRunningTool() {
126
- return this._runningToolName !== void 0;
127
- }
128
- setRunningTool(name) {
129
- this._runningToolName = name;
130
- }
131
- async _closeBrowserContextImpl() {
132
- if (!this._browserContextPromise)
133
- return;
134
- testDebug("close context");
135
- const promise = this._browserContextPromise;
136
- this._browserContextPromise = void 0;
137
- this._browserContextOption = void 0;
138
- await promise.then(async ({ browserContext, close }) => {
139
- if (this.config.saveTrace)
140
- await browserContext.tracing.stop();
141
- await close();
142
- });
143
- }
144
- async dispose() {
145
- this._abortController.abort("MCP context disposed");
146
- await this.closeBrowserContext();
147
- Context._allContexts.delete(this);
148
- }
149
- async _setupRequestInterception(context) {
150
- if (this.config.network?.allowedOrigins?.length) {
151
- await context.route("**", (route) => route.abort("blockedbyclient"));
152
- for (const origin of this.config.network.allowedOrigins)
153
- await context.route(originOrHostGlob(origin), (route) => route.continue());
154
- }
155
- if (this.config.network?.blockedOrigins?.length) {
156
- for (const origin of this.config.network.blockedOrigins)
157
- await context.route(originOrHostGlob(origin), (route) => route.abort("blockedbyclient"));
158
- }
159
- }
160
- async ensureBrowserContext(options = {}) {
161
- const { browserContext } = await this._ensureBrowserContext(options);
162
- return browserContext;
163
- }
164
- _ensureBrowserContext(options) {
165
- if (this._browserContextPromise && (options.forceHeadless === void 0 || this._browserContextOption?.forceHeadless === options.forceHeadless))
166
- return this._browserContextPromise;
167
- const closePrework = this._browserContextPromise ? this.closeBrowserContext() : Promise.resolve();
168
- this._browserContextPromise = closePrework.then(() => this._setupBrowserContext(options));
169
- this._browserContextPromise.catch(() => {
170
- this._browserContextPromise = void 0;
171
- this._browserContextOption = void 0;
172
- });
173
- this._browserContextOption = options;
174
- return this._browserContextPromise;
175
- }
176
- async _setupBrowserContext(options) {
177
- if (this._closeBrowserContextPromise)
178
- throw new Error("Another browser context is being closed.");
179
- if (this.config.testIdAttribute)
180
- import_playwright_core.selectors.setTestIdAttribute(this.config.testIdAttribute);
181
- const result = await this._browserContextFactory.createContext(this._clientInfo, this._abortController.signal, { toolName: this._runningToolName, ...options });
182
- const { browserContext } = result;
183
- if (!this.config.allowUnrestrictedFileAccess) {
184
- browserContext._setAllowedProtocols(["http:", "https:", "about:", "data:"]);
185
- browserContext._setAllowedDirectories(allRootPaths(this._clientInfo));
186
- }
187
- await this._setupRequestInterception(browserContext);
188
- for (const page of browserContext.pages())
189
- this._onPageCreated(page);
190
- browserContext.on("page", (page) => this._onPageCreated(page));
191
- if (this.config.saveTrace) {
192
- await browserContext.tracing.start({
193
- name: "trace-" + Date.now(),
194
- screenshots: true,
195
- snapshots: true,
196
- _live: true
197
- });
198
- }
199
- return result;
200
- }
201
- lookupSecret(secretName) {
202
- if (!this.config.secrets?.[secretName])
203
- return { value: secretName, code: (0, import_utils.escapeWithQuotes)(secretName, "'") };
204
- return {
205
- value: this.config.secrets[secretName],
206
- code: `process.env['${secretName}']`
207
- };
208
- }
209
- firstRootPath() {
210
- return allRootPaths(this._clientInfo)[0];
211
- }
212
- }
213
- function allRootPaths(clientInfo) {
214
- const paths = [];
215
- for (const root of clientInfo.roots) {
216
- const url = new URL(root.uri);
217
- let rootPath;
218
- try {
219
- rootPath = (0, import_url.fileURLToPath)(url);
220
- } catch (e) {
221
- if (e.code === "ERR_INVALID_FILE_URL_PATH" && import_os.default.platform() === "win32")
222
- rootPath = decodeURIComponent(url.pathname);
223
- }
224
- if (!rootPath)
225
- continue;
226
- paths.push(rootPath);
227
- }
228
- if (paths.length === 0)
229
- paths.push(process.cwd());
230
- return paths;
231
- }
232
- function originOrHostGlob(originOrHost) {
233
- try {
234
- const url = new URL(originOrHost);
235
- if (url.origin !== "null")
236
- return `${url.origin}/**`;
237
- } catch {
238
- }
239
- return `*://${originOrHost}/**`;
240
- }
241
- // Annotate the CommonJS export names for ESM import in node:
242
- 0 && (module.exports = {
243
- Context
244
- });