@botharness/core 1.6.0 → 1.7.0

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.
@@ -0,0 +1,1344 @@
1
+ import { createHash } from "node:crypto";
2
+ import fs, { constants, createReadStream, createWriteStream, existsSync, readFileSync, unlinkSync } from "node:fs";
3
+ import * as path from "node:path";
4
+ import nodePath from "node:path";
5
+ import { execFile, spawn, spawnSync } from "node:child_process";
6
+ import { URL as URL$1, urlToHttpOptions } from "node:url";
7
+ import os from "node:os";
8
+ import { debuglog, promisify } from "node:util";
9
+ import * as http from "node:http";
10
+ import { mkdir, readdir, symlink, unlink } from "node:fs/promises";
11
+ import { Stream, Writable } from "node:stream";
12
+ import { pipeline } from "node:stream/promises";
13
+ import "node:events";
14
+ import * as https from "node:https";
15
+ import assert from "node:assert";
16
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/httpUtil.js
17
+ /**
18
+ * @license
19
+ * Copyright 2023 Google Inc.
20
+ * SPDX-License-Identifier: Apache-2.0
21
+ */
22
+ async function httpRequest(url, method, response, keepAlive = true) {
23
+ let agent;
24
+ try {
25
+ const { ProxyAgent } = await import("proxy-agent");
26
+ agent = new ProxyAgent();
27
+ } catch {}
28
+ const options = {
29
+ protocol: url.protocol,
30
+ hostname: url.hostname,
31
+ port: url.port,
32
+ path: url.pathname + url.search,
33
+ method,
34
+ headers: keepAlive ? { Connection: "keep-alive" } : void 0,
35
+ auth: urlToHttpOptions(url).auth,
36
+ agent
37
+ };
38
+ const requestCallback = (res) => {
39
+ if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
40
+ httpRequest(new URL$1(res.headers.location), method, response);
41
+ res.resume();
42
+ } else response(res);
43
+ };
44
+ const request = options.protocol === "https:" ? https.request(options, requestCallback) : http.request(options, requestCallback);
45
+ request.end();
46
+ return request;
47
+ }
48
+ var HashVerifier = class {
49
+ #hash = createHash("sha256");
50
+ update(chunk) {
51
+ this.#hash.update(chunk);
52
+ }
53
+ verify(url, destinationPath, expectedHash) {
54
+ const actualHash = this.#hash.digest("hex");
55
+ if (actualHash !== expectedHash.toLowerCase()) {
56
+ try {
57
+ unlinkSync(destinationPath);
58
+ } catch {}
59
+ throw new Error(`Integrity check failed for downloaded browser archive.\n URL: ${url}\n Expected: ${expectedHash.toLowerCase()}\n Actual: ${actualHash}`);
60
+ }
61
+ }
62
+ };
63
+ /**
64
+ * @internal
65
+ */
66
+ function downloadFile(url, destinationPath, progressCallback, expectedHash) {
67
+ return new Promise(async (resolve, reject) => {
68
+ let downloadedBytes = 0;
69
+ let totalBytes = 0;
70
+ const verifier = expectedHash ? new HashVerifier() : null;
71
+ try {
72
+ (await httpRequest(url, "GET", (response) => {
73
+ if (response.statusCode !== 200) {
74
+ const error = /* @__PURE__ */ new Error(`Download failed: server returned code ${response.statusCode}. URL: ${url}`);
75
+ response.resume();
76
+ reject(error);
77
+ return;
78
+ }
79
+ const file = createWriteStream(destinationPath);
80
+ file.on("close", () => {
81
+ if (verifier && expectedHash) try {
82
+ verifier.verify(url, destinationPath, expectedHash);
83
+ } catch (err) {
84
+ reject(err);
85
+ return;
86
+ }
87
+ return resolve();
88
+ });
89
+ file.on("error", (error) => {
90
+ return reject(error);
91
+ });
92
+ totalBytes = parseInt(response.headers["content-length"], 10);
93
+ response.on("data", (chunk) => {
94
+ downloadedBytes += chunk.length;
95
+ verifier?.update(chunk);
96
+ if (progressCallback) progressCallback(downloadedBytes, totalBytes);
97
+ });
98
+ response.pipe(file);
99
+ })).on("error", (error) => {
100
+ return reject(error);
101
+ });
102
+ } catch (error) {
103
+ reject(error);
104
+ }
105
+ });
106
+ }
107
+ //#endregion
108
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/browser-data/types.js
109
+ /**
110
+ * @license
111
+ * Copyright 2023 Google Inc.
112
+ * SPDX-License-Identifier: Apache-2.0
113
+ */
114
+ /**
115
+ * Supported browsers.
116
+ *
117
+ * @public
118
+ */
119
+ var Browser;
120
+ (function(Browser) {
121
+ Browser["CHROME"] = "chrome";
122
+ Browser["CHROMEHEADLESSSHELL"] = "chrome-headless-shell";
123
+ Browser["CHROMIUM"] = "chromium";
124
+ Browser["FIREFOX"] = "firefox";
125
+ Browser["CHROMEDRIVER"] = "chromedriver";
126
+ })(Browser || (Browser = {}));
127
+ /**
128
+ * Platform names used to identify a OS platform x architecture combination in the way
129
+ * that is relevant for the browser download.
130
+ *
131
+ * @public
132
+ */
133
+ var BrowserPlatform;
134
+ (function(BrowserPlatform) {
135
+ BrowserPlatform["LINUX"] = "linux";
136
+ BrowserPlatform["LINUX_ARM"] = "linux_arm";
137
+ BrowserPlatform["MAC"] = "mac";
138
+ BrowserPlatform["MAC_ARM"] = "mac_arm";
139
+ BrowserPlatform["WIN32"] = "win32";
140
+ BrowserPlatform["WIN64"] = "win64";
141
+ })(BrowserPlatform || (BrowserPlatform = {}));
142
+ /**
143
+ * Enum describing a release channel for a browser.
144
+ *
145
+ * You can use this in combination with {@link resolveBuildId} to resolve
146
+ * a build ID based on a release channel.
147
+ *
148
+ * @public
149
+ */
150
+ var BrowserTag;
151
+ (function(BrowserTag) {
152
+ BrowserTag["CANARY"] = "canary";
153
+ BrowserTag["NIGHTLY"] = "nightly";
154
+ BrowserTag["BETA"] = "beta";
155
+ BrowserTag["DEV"] = "dev";
156
+ BrowserTag["DEVEDITION"] = "devedition";
157
+ BrowserTag["STABLE"] = "stable";
158
+ BrowserTag["ESR"] = "esr";
159
+ BrowserTag["LATEST"] = "latest";
160
+ })(BrowserTag || (BrowserTag = {}));
161
+ /**
162
+ * @public
163
+ */
164
+ var ChromeReleaseChannel;
165
+ (function(ChromeReleaseChannel) {
166
+ ChromeReleaseChannel["STABLE"] = "stable";
167
+ ChromeReleaseChannel["DEV"] = "dev";
168
+ ChromeReleaseChannel["CANARY"] = "canary";
169
+ ChromeReleaseChannel["BETA"] = "beta";
170
+ })(ChromeReleaseChannel || (ChromeReleaseChannel = {}));
171
+ //#endregion
172
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/browser-data/chrome.js
173
+ /**
174
+ * @license
175
+ * Copyright 2023 Google Inc.
176
+ * SPDX-License-Identifier: Apache-2.0
177
+ */
178
+ function folder$3(platform, buildId) {
179
+ switch (platform) {
180
+ case BrowserPlatform.LINUX_ARM:
181
+ if (buildId && compareVersions$2(buildId, "153.0.8001.0") < 0) return "linux64";
182
+ return "linux-arm64";
183
+ case BrowserPlatform.LINUX: return "linux64";
184
+ case BrowserPlatform.MAC_ARM: return "mac-arm64";
185
+ case BrowserPlatform.MAC: return "mac-x64";
186
+ case BrowserPlatform.WIN32: return "win32";
187
+ case BrowserPlatform.WIN64: return "win64";
188
+ }
189
+ }
190
+ function resolveDownloadUrl$4(platform, buildId, baseUrl = "https://storage.googleapis.com/chrome-for-testing-public") {
191
+ return `${baseUrl}/${resolveDownloadPath$4(platform, buildId).join("/")}`;
192
+ }
193
+ function resolveDownloadPath$4(platform, buildId) {
194
+ return [
195
+ buildId,
196
+ folder$3(platform, buildId),
197
+ `chrome-${folder$3(platform, buildId)}.zip`
198
+ ];
199
+ }
200
+ function relativeExecutablePath$4(platform, buildId) {
201
+ switch (platform) {
202
+ case BrowserPlatform.MAC:
203
+ case BrowserPlatform.MAC_ARM: return nodePath.join("chrome-" + folder$3(platform, buildId), "Google Chrome for Testing.app", "Contents", "MacOS", "Google Chrome for Testing");
204
+ case BrowserPlatform.LINUX_ARM:
205
+ case BrowserPlatform.LINUX: return nodePath.join("chrome-" + folder$3(platform, buildId), "chrome");
206
+ case BrowserPlatform.WIN32:
207
+ case BrowserPlatform.WIN64: return nodePath.join("chrome-" + folder$3(platform, buildId), "chrome.exe");
208
+ }
209
+ }
210
+ function compareVersions$2(a, b) {
211
+ const cleanA = a.trim();
212
+ const cleanB = b.trim();
213
+ const versionRegex = /^\d+(?:\.\d+){0,3}$/;
214
+ if (!versionRegex.test(cleanA)) throw new Error(`Version ${a} is not a valid Chrome version`);
215
+ if (!versionRegex.test(cleanB)) throw new Error(`Version ${b} is not a valid Chrome version`);
216
+ const aParts = cleanA.split(".").map(Number);
217
+ const bParts = cleanB.split(".").map(Number);
218
+ for (let i = 0; i < 4; i++) {
219
+ const aPart = aParts[i] ?? 0;
220
+ const bPart = bParts[i] ?? 0;
221
+ if (aPart > bPart) return 1;
222
+ if (aPart < bPart) return -1;
223
+ }
224
+ return 0;
225
+ }
226
+ //#endregion
227
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/browser-data/chrome-headless-shell.js
228
+ /**
229
+ * @license
230
+ * Copyright 2023 Google Inc.
231
+ * SPDX-License-Identifier: Apache-2.0
232
+ */
233
+ function folder$2(platform, buildId) {
234
+ switch (platform) {
235
+ case BrowserPlatform.LINUX_ARM:
236
+ if (buildId && compareVersions$2(buildId, "153.0.8001.0") < 0) return "linux64";
237
+ return "linux-arm64";
238
+ case BrowserPlatform.LINUX: return "linux64";
239
+ case BrowserPlatform.MAC_ARM: return "mac-arm64";
240
+ case BrowserPlatform.MAC: return "mac-x64";
241
+ case BrowserPlatform.WIN32: return "win32";
242
+ case BrowserPlatform.WIN64: return "win64";
243
+ }
244
+ }
245
+ function resolveDownloadUrl$3(platform, buildId, baseUrl = "https://storage.googleapis.com/chrome-for-testing-public") {
246
+ return `${baseUrl}/${resolveDownloadPath$3(platform, buildId).join("/")}`;
247
+ }
248
+ function resolveDownloadPath$3(platform, buildId) {
249
+ return [
250
+ buildId,
251
+ folder$2(platform, buildId),
252
+ `chrome-headless-shell-${folder$2(platform, buildId)}.zip`
253
+ ];
254
+ }
255
+ function relativeExecutablePath$3(platform, buildId) {
256
+ switch (platform) {
257
+ case BrowserPlatform.MAC:
258
+ case BrowserPlatform.MAC_ARM: return nodePath.join("chrome-headless-shell-" + folder$2(platform, buildId), "chrome-headless-shell");
259
+ case BrowserPlatform.LINUX_ARM:
260
+ case BrowserPlatform.LINUX: return nodePath.join("chrome-headless-shell-" + folder$2(platform, buildId), "chrome-headless-shell");
261
+ case BrowserPlatform.WIN32:
262
+ case BrowserPlatform.WIN64: return nodePath.join("chrome-headless-shell-" + folder$2(platform, buildId), "chrome-headless-shell.exe");
263
+ }
264
+ }
265
+ //#endregion
266
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/browser-data/chromedriver.js
267
+ /**
268
+ * @license
269
+ * Copyright 2023 Google Inc.
270
+ * SPDX-License-Identifier: Apache-2.0
271
+ */
272
+ function folder$1(platform, buildId) {
273
+ switch (platform) {
274
+ case BrowserPlatform.LINUX_ARM:
275
+ if (buildId && compareVersions$2(buildId, "153.0.8001.0") < 0) return "linux64";
276
+ return "linux-arm64";
277
+ case BrowserPlatform.LINUX: return "linux64";
278
+ case BrowserPlatform.MAC_ARM: return "mac-arm64";
279
+ case BrowserPlatform.MAC: return "mac-x64";
280
+ case BrowserPlatform.WIN32: return "win32";
281
+ case BrowserPlatform.WIN64: return "win64";
282
+ }
283
+ }
284
+ function resolveDownloadUrl$2(platform, buildId, baseUrl = "https://storage.googleapis.com/chrome-for-testing-public") {
285
+ return `${baseUrl}/${resolveDownloadPath$2(platform, buildId).join("/")}`;
286
+ }
287
+ function resolveDownloadPath$2(platform, buildId) {
288
+ return [
289
+ buildId,
290
+ folder$1(platform, buildId),
291
+ `chromedriver-${folder$1(platform, buildId)}.zip`
292
+ ];
293
+ }
294
+ function relativeExecutablePath$2(platform, buildId) {
295
+ switch (platform) {
296
+ case BrowserPlatform.MAC:
297
+ case BrowserPlatform.MAC_ARM: return nodePath.join("chromedriver-" + folder$1(platform, buildId), "chromedriver");
298
+ case BrowserPlatform.LINUX_ARM:
299
+ case BrowserPlatform.LINUX: return nodePath.join("chromedriver-" + folder$1(platform, buildId), "chromedriver");
300
+ case BrowserPlatform.WIN32:
301
+ case BrowserPlatform.WIN64: return nodePath.join("chromedriver-" + folder$1(platform, buildId), "chromedriver.exe");
302
+ }
303
+ }
304
+ //#endregion
305
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/browser-data/chromium.js
306
+ /**
307
+ * @license
308
+ * Copyright 2023 Google Inc.
309
+ * SPDX-License-Identifier: Apache-2.0
310
+ */
311
+ function archive$1(platform, buildId) {
312
+ switch (platform) {
313
+ case BrowserPlatform.LINUX_ARM:
314
+ case BrowserPlatform.LINUX: return "chrome-linux";
315
+ case BrowserPlatform.MAC_ARM:
316
+ case BrowserPlatform.MAC: return "chrome-mac";
317
+ case BrowserPlatform.WIN32:
318
+ case BrowserPlatform.WIN64: return parseInt(buildId, 10) > 591479 ? "chrome-win" : "chrome-win32";
319
+ }
320
+ }
321
+ function folder(platform) {
322
+ switch (platform) {
323
+ case BrowserPlatform.LINUX_ARM:
324
+ case BrowserPlatform.LINUX: return "Linux_x64";
325
+ case BrowserPlatform.MAC_ARM: return "Mac_Arm";
326
+ case BrowserPlatform.MAC: return "Mac";
327
+ case BrowserPlatform.WIN32: return "Win";
328
+ case BrowserPlatform.WIN64: return "Win_x64";
329
+ }
330
+ }
331
+ function resolveDownloadUrl$1(platform, buildId, baseUrl = "https://storage.googleapis.com/chromium-browser-snapshots") {
332
+ return `${baseUrl}/${resolveDownloadPath$1(platform, buildId).join("/")}`;
333
+ }
334
+ function resolveDownloadPath$1(platform, buildId) {
335
+ return [
336
+ folder(platform),
337
+ buildId,
338
+ `${archive$1(platform, buildId)}.zip`
339
+ ];
340
+ }
341
+ function relativeExecutablePath$1(platform, _buildId) {
342
+ switch (platform) {
343
+ case BrowserPlatform.MAC:
344
+ case BrowserPlatform.MAC_ARM: return nodePath.join("chrome-mac", "Chromium.app", "Contents", "MacOS", "Chromium");
345
+ case BrowserPlatform.LINUX_ARM:
346
+ case BrowserPlatform.LINUX: return nodePath.join("chrome-linux", "chrome");
347
+ case BrowserPlatform.WIN32:
348
+ case BrowserPlatform.WIN64: return nodePath.join("chrome-win", "chrome.exe");
349
+ }
350
+ }
351
+ function compareVersions$1(a, b) {
352
+ return Number(a) - Number(b);
353
+ }
354
+ //#endregion
355
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/browser-data/firefox.js
356
+ /**
357
+ * @license
358
+ * Copyright 2023 Google Inc.
359
+ * SPDX-License-Identifier: Apache-2.0
360
+ */
361
+ function getFormat(buildId) {
362
+ return Number(buildId.split(".").shift()) >= 135 ? "xz" : "bz2";
363
+ }
364
+ function archiveNightly(platform, buildId) {
365
+ switch (platform) {
366
+ case BrowserPlatform.LINUX: return `firefox-${buildId}.en-US.linux-x86_64.tar.${getFormat(buildId)}`;
367
+ case BrowserPlatform.LINUX_ARM: return `firefox-${buildId}.en-US.linux-aarch64.tar.${getFormat(buildId)}`;
368
+ case BrowserPlatform.MAC_ARM:
369
+ case BrowserPlatform.MAC: return `firefox-${buildId}.en-US.mac.dmg`;
370
+ case BrowserPlatform.WIN32:
371
+ case BrowserPlatform.WIN64: return `firefox-${buildId}.en-US.${platform}.zip`;
372
+ }
373
+ }
374
+ function archive(platform, buildId) {
375
+ switch (platform) {
376
+ case BrowserPlatform.LINUX_ARM:
377
+ case BrowserPlatform.LINUX: return `firefox-${buildId}.tar.${getFormat(buildId)}`;
378
+ case BrowserPlatform.MAC_ARM:
379
+ case BrowserPlatform.MAC: return `Firefox ${buildId}.dmg`;
380
+ case BrowserPlatform.WIN32:
381
+ case BrowserPlatform.WIN64: return `Firefox Setup ${buildId}.exe`;
382
+ }
383
+ }
384
+ function platformName(platform) {
385
+ switch (platform) {
386
+ case BrowserPlatform.LINUX: return `linux-x86_64`;
387
+ case BrowserPlatform.LINUX_ARM: return `linux-aarch64`;
388
+ case BrowserPlatform.MAC_ARM:
389
+ case BrowserPlatform.MAC: return `mac`;
390
+ case BrowserPlatform.WIN32:
391
+ case BrowserPlatform.WIN64: return platform;
392
+ }
393
+ }
394
+ function parseBuildId(buildId) {
395
+ for (const value of Object.values(FirefoxChannel)) if (buildId.startsWith(value + "_")) {
396
+ buildId = buildId.substring(value.length + 1);
397
+ return [value, buildId];
398
+ }
399
+ return [FirefoxChannel.NIGHTLY, buildId];
400
+ }
401
+ function resolveDownloadUrl(platform, buildId, baseUrl) {
402
+ const [channel] = parseBuildId(buildId);
403
+ switch (channel) {
404
+ case FirefoxChannel.NIGHTLY:
405
+ baseUrl ??= "https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central";
406
+ break;
407
+ case FirefoxChannel.DEVEDITION:
408
+ baseUrl ??= "https://archive.mozilla.org/pub/devedition/releases";
409
+ break;
410
+ case FirefoxChannel.BETA:
411
+ case FirefoxChannel.STABLE:
412
+ case FirefoxChannel.ESR: baseUrl ??= "https://archive.mozilla.org/pub/firefox/releases";
413
+ }
414
+ return `${baseUrl}/${resolveDownloadPath(platform, buildId).join("/")}`;
415
+ }
416
+ function resolveDownloadPath(platform, buildId) {
417
+ const [channel, resolvedBuildId] = parseBuildId(buildId);
418
+ switch (channel) {
419
+ case FirefoxChannel.NIGHTLY: return [archiveNightly(platform, resolvedBuildId)];
420
+ case FirefoxChannel.DEVEDITION:
421
+ case FirefoxChannel.BETA:
422
+ case FirefoxChannel.STABLE:
423
+ case FirefoxChannel.ESR: return [
424
+ resolvedBuildId,
425
+ platformName(platform),
426
+ "en-US",
427
+ archive(platform, resolvedBuildId)
428
+ ];
429
+ }
430
+ }
431
+ function relativeExecutablePath(platform, buildId) {
432
+ const [channel] = parseBuildId(buildId);
433
+ switch (channel) {
434
+ case FirefoxChannel.NIGHTLY: switch (platform) {
435
+ case BrowserPlatform.MAC_ARM:
436
+ case BrowserPlatform.MAC: return nodePath.join("Firefox Nightly.app", "Contents", "MacOS", "firefox");
437
+ case BrowserPlatform.LINUX_ARM:
438
+ case BrowserPlatform.LINUX: return nodePath.join("firefox", "firefox");
439
+ case BrowserPlatform.WIN32:
440
+ case BrowserPlatform.WIN64: return nodePath.join("firefox", "firefox.exe");
441
+ }
442
+ case FirefoxChannel.BETA:
443
+ case FirefoxChannel.DEVEDITION:
444
+ case FirefoxChannel.ESR:
445
+ case FirefoxChannel.STABLE: switch (platform) {
446
+ case BrowserPlatform.MAC_ARM:
447
+ case BrowserPlatform.MAC: return nodePath.join("Firefox.app", "Contents", "MacOS", "firefox");
448
+ case BrowserPlatform.LINUX_ARM:
449
+ case BrowserPlatform.LINUX: return nodePath.join("firefox", "firefox");
450
+ case BrowserPlatform.WIN32:
451
+ case BrowserPlatform.WIN64: return nodePath.join("core", "firefox.exe");
452
+ }
453
+ }
454
+ }
455
+ var FirefoxChannel;
456
+ (function(FirefoxChannel) {
457
+ FirefoxChannel["STABLE"] = "stable";
458
+ FirefoxChannel["ESR"] = "esr";
459
+ FirefoxChannel["DEVEDITION"] = "devedition";
460
+ FirefoxChannel["BETA"] = "beta";
461
+ FirefoxChannel["NIGHTLY"] = "nightly";
462
+ })(FirefoxChannel || (FirefoxChannel = {}));
463
+ function compareVersions(a, b) {
464
+ return parseInt(a.replace(".", ""), 16) - parseInt(b.replace(".", ""), 16);
465
+ }
466
+ //#endregion
467
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/browser-data/browser-data.js
468
+ /**
469
+ * @license
470
+ * Copyright 2023 Google Inc.
471
+ * SPDX-License-Identifier: Apache-2.0
472
+ */
473
+ const downloadUrls = {
474
+ [Browser.CHROMEDRIVER]: resolveDownloadUrl$2,
475
+ [Browser.CHROMEHEADLESSSHELL]: resolveDownloadUrl$3,
476
+ [Browser.CHROME]: resolveDownloadUrl$4,
477
+ [Browser.CHROMIUM]: resolveDownloadUrl$1,
478
+ [Browser.FIREFOX]: resolveDownloadUrl
479
+ };
480
+ Browser.CHROMEDRIVER, Browser.CHROMEHEADLESSSHELL, Browser.CHROME, Browser.CHROMIUM, Browser.FIREFOX;
481
+ const executablePathByBrowser = {
482
+ [Browser.CHROMEDRIVER]: relativeExecutablePath$2,
483
+ [Browser.CHROMEHEADLESSSHELL]: relativeExecutablePath$3,
484
+ [Browser.CHROME]: relativeExecutablePath$4,
485
+ [Browser.CHROMIUM]: relativeExecutablePath$1,
486
+ [Browser.FIREFOX]: relativeExecutablePath
487
+ };
488
+ const versionComparators = {
489
+ [Browser.CHROMEDRIVER]: compareVersions$2,
490
+ [Browser.CHROMEHEADLESSSHELL]: compareVersions$2,
491
+ [Browser.CHROME]: compareVersions$2,
492
+ [Browser.CHROMIUM]: compareVersions$1,
493
+ [Browser.FIREFOX]: compareVersions
494
+ };
495
+ /**
496
+ * Returns a version comparator for the given browser that can be used to sort
497
+ * browser versions.
498
+ *
499
+ * @public
500
+ */
501
+ function getVersionComparator(browser) {
502
+ return versionComparators[browser];
503
+ }
504
+ //#endregion
505
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/debug.js
506
+ /**
507
+ * @license
508
+ * Copyright 2023 Google Inc.
509
+ * SPDX-License-Identifier: Apache-2.0
510
+ */
511
+ const DEBUG_PREFIXES = {
512
+ cache: "puppeteer:browsers:cache",
513
+ fileUtil: "puppeteer:browsers:fileUtil",
514
+ install: "puppeteer:browsers:install",
515
+ launcher: "puppeteer:browsers:launcher"
516
+ };
517
+ const debug = (prefix) => {
518
+ const log = debuglog(prefix);
519
+ return log.enabled ? log : void 0;
520
+ };
521
+ //#endregion
522
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/detectPlatform.js
523
+ /**
524
+ * @license
525
+ * Copyright 2023 Google Inc.
526
+ * SPDX-License-Identifier: Apache-2.0
527
+ */
528
+ /**
529
+ * @public
530
+ */
531
+ function detectBrowserPlatform() {
532
+ const platform = os.platform();
533
+ const arch = os.arch();
534
+ switch (platform) {
535
+ case "darwin": return arch === "arm64" ? BrowserPlatform.MAC_ARM : BrowserPlatform.MAC;
536
+ case "linux": return arch === "arm64" ? BrowserPlatform.LINUX_ARM : BrowserPlatform.LINUX;
537
+ case "win32": return arch === "x64" || arch === "arm64" && isWindows11(os.release()) ? BrowserPlatform.WIN64 : BrowserPlatform.WIN32;
538
+ default: return;
539
+ }
540
+ }
541
+ /**
542
+ * Windows 11 is identified by the version 10.0.22000 or greater
543
+ * @internal
544
+ */
545
+ function isWindows11(version) {
546
+ const parts = version.split(".");
547
+ if (parts.length > 2) {
548
+ const major = parseInt(parts[0], 10);
549
+ const minor = parseInt(parts[1], 10);
550
+ const patch = parseInt(parts[2], 10);
551
+ return major > 10 || major === 10 && minor > 0 || major === 10 && minor === 0 && patch >= 22e3;
552
+ }
553
+ return false;
554
+ }
555
+ //#endregion
556
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/Cache.js
557
+ /**
558
+ * @license
559
+ * Copyright 2023 Google Inc.
560
+ * SPDX-License-Identifier: Apache-2.0
561
+ */
562
+ /**
563
+ * @public
564
+ */
565
+ var InstalledBrowser = class {
566
+ browser;
567
+ buildId;
568
+ platform;
569
+ executablePath;
570
+ #cache;
571
+ /**
572
+ * @internal
573
+ */
574
+ constructor(cache, browser, buildId, platform) {
575
+ this.#cache = cache;
576
+ this.browser = browser;
577
+ this.buildId = buildId;
578
+ this.platform = platform;
579
+ this.executablePath = cache.computeExecutablePath({
580
+ browser,
581
+ buildId,
582
+ platform
583
+ });
584
+ }
585
+ /**
586
+ * Path to the root of the installation folder. Use
587
+ * {@link computeExecutablePath} to get the path to the executable binary.
588
+ */
589
+ get path() {
590
+ return this.#cache.installationDir(this.browser, this.platform, this.buildId);
591
+ }
592
+ readMetadata() {
593
+ return this.#cache.readMetadata(this.browser);
594
+ }
595
+ writeMetadata(metadata) {
596
+ this.#cache.writeMetadata(this.browser, metadata);
597
+ }
598
+ };
599
+ /**
600
+ * The cache used by Puppeteer relies on the following structure:
601
+ *
602
+ * - rootDir
603
+ * -- <browser1> | browserRoot(browser1)
604
+ * ---- <platform>-<buildId> | installationDir()
605
+ * ------ the browser-platform-buildId
606
+ * ------ specific structure.
607
+ * -- <browser2> | browserRoot(browser2)
608
+ * ---- <platform>-<buildId> | installationDir()
609
+ * ------ the browser-platform-buildId
610
+ * ------ specific structure.
611
+ * @internal
612
+ */
613
+ var Cache = class {
614
+ #rootDir;
615
+ #logger;
616
+ constructor(rootDir, logger) {
617
+ this.#rootDir = rootDir;
618
+ this.#logger = logger?.(DEBUG_PREFIXES.cache);
619
+ }
620
+ /**
621
+ * @internal
622
+ */
623
+ get rootDir() {
624
+ return this.#rootDir;
625
+ }
626
+ browserRoot(browser) {
627
+ return nodePath.join(this.#rootDir, browser);
628
+ }
629
+ metadataFile(browser) {
630
+ return nodePath.join(this.browserRoot(browser), ".metadata");
631
+ }
632
+ readMetadata(browser) {
633
+ const metatadaPath = this.metadataFile(browser);
634
+ if (!fs.existsSync(metatadaPath)) return { aliases: {} };
635
+ const data = JSON.parse(fs.readFileSync(metatadaPath, "utf8"));
636
+ if (typeof data !== "object") throw new Error(".metadata is not an object");
637
+ return data;
638
+ }
639
+ writeMetadata(browser, metadata) {
640
+ const metatadaPath = this.metadataFile(browser);
641
+ fs.mkdirSync(nodePath.dirname(metatadaPath), { recursive: true });
642
+ fs.writeFileSync(metatadaPath, JSON.stringify(metadata, null, 2));
643
+ }
644
+ readExecutablePath(browser, platform, buildId) {
645
+ const metadata = this.readMetadata(browser);
646
+ const key = `${platform}-${buildId}`;
647
+ return metadata.executablePaths?.[key] ?? null;
648
+ }
649
+ writeExecutablePath(browser, platform, buildId, executablePath) {
650
+ const metadata = this.readMetadata(browser);
651
+ if (!metadata.executablePaths) metadata.executablePaths = {};
652
+ const key = `${platform}-${buildId}`;
653
+ metadata.executablePaths[key] = executablePath;
654
+ this.writeMetadata(browser, metadata);
655
+ }
656
+ resolveAlias(browser, alias) {
657
+ const metadata = this.readMetadata(browser);
658
+ if (alias === "latest") return Object.values(metadata.aliases || {}).sort(getVersionComparator(browser)).at(-1);
659
+ return metadata.aliases[alias];
660
+ }
661
+ installationDir(browser, platform, buildId) {
662
+ return nodePath.join(this.browserRoot(browser), `${platform}-${buildId}`);
663
+ }
664
+ clear() {
665
+ fs.rmSync(this.#rootDir, {
666
+ force: true,
667
+ recursive: true,
668
+ maxRetries: 10,
669
+ retryDelay: 500
670
+ });
671
+ }
672
+ uninstall(browser, platform, buildId) {
673
+ const metadata = this.readMetadata(browser);
674
+ for (const alias of Object.keys(metadata.aliases)) if (metadata.aliases[alias] === buildId) delete metadata.aliases[alias];
675
+ const key = `${platform}-${buildId}`;
676
+ if (metadata.executablePaths?.[key]) {
677
+ delete metadata.executablePaths[key];
678
+ this.writeMetadata(browser, metadata);
679
+ }
680
+ fs.rmSync(this.installationDir(browser, platform, buildId), {
681
+ force: true,
682
+ recursive: true,
683
+ maxRetries: 10,
684
+ retryDelay: 500
685
+ });
686
+ }
687
+ getInstalledBrowsers() {
688
+ if (!fs.existsSync(this.#rootDir)) return [];
689
+ return fs.readdirSync(this.#rootDir).filter((t) => {
690
+ return Object.values(Browser).includes(t);
691
+ }).flatMap((browser) => {
692
+ return fs.readdirSync(this.browserRoot(browser)).map((file) => {
693
+ const result = parseFolderPath(nodePath.join(this.browserRoot(browser), file));
694
+ if (!result) return null;
695
+ return new InstalledBrowser(this, browser, result.buildId, result.platform);
696
+ }).filter((item) => {
697
+ return item !== null;
698
+ });
699
+ });
700
+ }
701
+ computeExecutablePath(options) {
702
+ options.platform ??= detectBrowserPlatform();
703
+ if (!options.platform) throw new Error(`Cannot download a binary for the provided platform: ${os.platform()} (${os.arch()})`);
704
+ try {
705
+ options.buildId = this.resolveAlias(options.browser, options.buildId) ?? options.buildId;
706
+ } catch {
707
+ this.#logger?.("could not read .metadata file for the browser");
708
+ }
709
+ const installationDir = this.installationDir(options.browser, options.platform, options.buildId);
710
+ const storedExecutablePath = this.readExecutablePath(options.browser, options.platform, options.buildId);
711
+ if (storedExecutablePath) return nodePath.join(installationDir, storedExecutablePath);
712
+ return nodePath.join(installationDir, executablePathByBrowser[options.browser](options.platform, options.buildId));
713
+ }
714
+ };
715
+ function parseFolderPath(folderPath) {
716
+ const splits = nodePath.basename(folderPath).split("-");
717
+ if (splits.length !== 2) return;
718
+ const [platform, buildId] = splits;
719
+ if (!buildId || !platform) return;
720
+ return {
721
+ platform,
722
+ buildId
723
+ };
724
+ }
725
+ //#endregion
726
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/launch.js
727
+ /**
728
+ * @license
729
+ * Copyright 2023 Google Inc.
730
+ * SPDX-License-Identifier: Apache-2.0
731
+ */
732
+ //#endregion
733
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/DefaultProvider.js
734
+ /**
735
+ * @license
736
+ * Copyright 2026 Google Inc.
737
+ * SPDX-License-Identifier: Apache-2.0
738
+ */
739
+ /**
740
+ * Default provider implementation that uses default sources.
741
+ * This is the standard provider used by Puppeteer.
742
+ *
743
+ * @public
744
+ */
745
+ var DefaultProvider = class {
746
+ #baseUrl;
747
+ constructor(baseUrl) {
748
+ this.#baseUrl = baseUrl;
749
+ }
750
+ supports(_options) {
751
+ return true;
752
+ }
753
+ getDownloadUrl(options) {
754
+ return this.#getDownloadUrl(options.browser, options.platform, options.buildId);
755
+ }
756
+ #getDownloadUrl(browser, platform, buildId) {
757
+ return new URL(downloadUrls[browser](platform, buildId, this.#baseUrl));
758
+ }
759
+ getExecutablePath(options) {
760
+ return executablePathByBrowser[options.browser](options.platform, options.buildId);
761
+ }
762
+ getName() {
763
+ return "DefaultProvider";
764
+ }
765
+ };
766
+ //#endregion
767
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/fileUtil.js
768
+ /**
769
+ * @license
770
+ * Copyright 2023 Google Inc.
771
+ * SPDX-License-Identifier: Apache-2.0
772
+ */
773
+ const execFileAsync = promisify(execFile);
774
+ /**
775
+ * @internal
776
+ */
777
+ async function unpackArchive(archivePath, folderPath, logger) {
778
+ if (!path.isAbsolute(folderPath)) folderPath = path.resolve(process.cwd(), folderPath);
779
+ if (archivePath.endsWith(".zip")) {
780
+ await mkdir(folderPath, { recursive: true });
781
+ await extractZip(archivePath, folderPath, logger);
782
+ } else if (archivePath.endsWith(".tar.bz2")) await extractTar(archivePath, folderPath, "bzip2", logger);
783
+ else if (archivePath.endsWith(".dmg")) {
784
+ await mkdir(folderPath);
785
+ await installDMG(archivePath, folderPath);
786
+ } else if (archivePath.endsWith(".exe")) {
787
+ const result = spawnSync(archivePath, [`/ExtractDir=${folderPath}`], { env: { __compat_layer: "RunAsInvoker" } });
788
+ if (result.status !== 0) throw new Error(`Failed to extract ${archivePath} to ${folderPath}: ${result.output}`);
789
+ } else if (archivePath.endsWith(".tar.xz")) await extractTar(archivePath, folderPath, "xz");
790
+ else throw new Error(`Unsupported archive format: ${archivePath}`);
791
+ }
792
+ function createTransformStream(child) {
793
+ const stream = new Stream.Transform({
794
+ transform(chunk, encoding, callback) {
795
+ if (!child.stdin.write(chunk, encoding)) child.stdin.once("drain", callback);
796
+ else callback();
797
+ },
798
+ flush(callback) {
799
+ if (child.stdout.destroyed) callback();
800
+ else {
801
+ child.stdin.end();
802
+ child.stdout.on("close", callback);
803
+ }
804
+ }
805
+ });
806
+ child.stdin.on("error", (e) => {
807
+ if ("code" in e && e.code === "EPIPE") stream.emit("end");
808
+ else stream.destroy(e);
809
+ });
810
+ child.stdout.on("data", (data) => {
811
+ return stream.push(data);
812
+ }).on("error", (e) => {
813
+ return stream.destroy(e);
814
+ });
815
+ child.once("close", () => {
816
+ return stream.end();
817
+ });
818
+ return stream;
819
+ }
820
+ /**
821
+ * @internal
822
+ */
823
+ const internalConstantsForTesting = {
824
+ xz: "xz",
825
+ bzip2: "bzip2"
826
+ };
827
+ /**
828
+ * @internal
829
+ */
830
+ async function extractTar(tarPath, folderPath, decompressUtilityName, logger) {
831
+ const { unpackTar } = await import("./fs-CoIYdtCX.mjs");
832
+ return await new Promise((fulfill, reject) => {
833
+ function handleError(utilityName) {
834
+ return (error) => {
835
+ if ("code" in error && error.code === "ENOENT") error = new Error(`\`${utilityName}\` utility is required to unpack this archive`, { cause: error });
836
+ reject(error);
837
+ };
838
+ }
839
+ const unpack = spawn(internalConstantsForTesting[decompressUtilityName], ["-d"], { stdio: [
840
+ "pipe",
841
+ "pipe",
842
+ "inherit"
843
+ ] }).once("error", handleError(decompressUtilityName)).once("exit", (code) => {
844
+ logger?.(DEBUG_PREFIXES.fileUtil)?.(`${decompressUtilityName} exited, code=${code}`);
845
+ });
846
+ const tar = unpackTar(folderPath);
847
+ tar.once("error", handleError("tar"));
848
+ tar.once("finish", fulfill);
849
+ createReadStream(tarPath).pipe(createTransformStream(unpack)).pipe(tar);
850
+ });
851
+ }
852
+ /**
853
+ * @internal
854
+ */
855
+ async function installDMG(dmgPath, folderPath) {
856
+ const { stdout } = await execFileAsync("hdiutil", [
857
+ "attach",
858
+ "-nobrowse",
859
+ "-noautoopen",
860
+ dmgPath
861
+ ]);
862
+ const volumes = stdout.match(/\/Volumes\/(.*)/m);
863
+ if (!volumes) throw new Error(`Could not find volume path in ${stdout}`);
864
+ const mountPath = volumes[0];
865
+ try {
866
+ const appName = (await readdir(mountPath)).find((item) => {
867
+ return typeof item === "string" && item.endsWith(".app");
868
+ });
869
+ if (!appName) throw new Error(`Cannot find app in ${mountPath}`);
870
+ const mountedPath = path.join(mountPath, appName);
871
+ await execFileAsync("cp", [
872
+ "-R",
873
+ mountedPath,
874
+ folderPath
875
+ ]);
876
+ } finally {
877
+ await execFileAsync("hdiutil", [
878
+ "detach",
879
+ mountPath,
880
+ "-quiet"
881
+ ]);
882
+ }
883
+ }
884
+ /**
885
+ * @internal
886
+ */
887
+ var ArchiverUnavailableError = class extends Error {};
888
+ /**
889
+ * @internal
890
+ */
891
+ async function extractZip(archivePath, folderPath, logger) {
892
+ for (const extract of [extractZipWithCli, extractZipWithYauzl]) try {
893
+ await extract(archivePath, folderPath, logger);
894
+ return;
895
+ } catch (error) {
896
+ if (!(error instanceof ArchiverUnavailableError)) throw error;
897
+ }
898
+ throw new Error(`Extraction failed: no zip archiver is available. Install \`unzip\` (or \`tar.exe\`/Powershell on Windows), or add the optional \`yauzl\` dependency.`);
899
+ }
900
+ /**
901
+ * @internal
902
+ */
903
+ async function extractZipWithYauzl(archivePath, folderPath, _logger) {
904
+ const { default: yauzl } = await import(
905
+ /* webpackIgnore: true */
906
+ "yauzl"
907
+ ).catch(() => {
908
+ throw new ArchiverUnavailableError("Extraction failed: The optional `yauzl` dependency is not installed.");
909
+ });
910
+ const open = promisify(yauzl.open);
911
+ try {
912
+ const zipFile = await open(archivePath, { lazyEntries: true });
913
+ await new Promise((resolve, reject) => {
914
+ zipFile.on("error", reject).on("end", resolve).on("entry", (entry) => {
915
+ extractZipEntry(zipFile, entry, folderPath).then(() => {
916
+ zipFile.readEntry();
917
+ }, reject);
918
+ }).readEntry();
919
+ });
920
+ } catch (error) {
921
+ throw new Error(`Extraction failed: ${archivePath}`, { cause: error });
922
+ }
923
+ }
924
+ /**
925
+ * @internal
926
+ */
927
+ async function extractZipWithCli(archivePath, folderPath, logger) {
928
+ try {
929
+ if (process.platform === "win32") {
930
+ const systemRoot = process.env["SystemRoot"] ?? process.env["SYSTEMROOT"] ?? "C:\\Windows";
931
+ try {
932
+ const systemTar = `${systemRoot}\\System32\\tar.exe`;
933
+ await execFileAsync(systemTar, [
934
+ "-xf",
935
+ archivePath,
936
+ "-C",
937
+ folderPath
938
+ ]);
939
+ return;
940
+ } catch (tarError) {
941
+ logger?.(DEBUG_PREFIXES.fileUtil)?.(`tar.exe extraction failed: ${tarError}`);
942
+ }
943
+ try {
944
+ await execFileAsync("powershell.exe", [
945
+ "-NoProfile",
946
+ "-NonInteractive",
947
+ "-Command",
948
+ "& { Expand-Archive -LiteralPath $args[0] -DestinationPath $args[1] -Force }",
949
+ archivePath,
950
+ folderPath
951
+ ]);
952
+ return;
953
+ } catch (powershellError) {
954
+ logger?.(DEBUG_PREFIXES.fileUtil)?.(`powershell.exe extraction failed: ${powershellError}`);
955
+ }
956
+ await execFileAsync("pwsh.exe", [
957
+ "-NoProfile",
958
+ "-NonInteractive",
959
+ "-Command",
960
+ "& { Expand-Archive -LiteralPath $args[0] -DestinationPath $args[1] -Force }",
961
+ archivePath,
962
+ folderPath
963
+ ]);
964
+ } else await execFileAsync("unzip", [
965
+ "-o",
966
+ archivePath,
967
+ "-d",
968
+ folderPath
969
+ ]);
970
+ } catch (error) {
971
+ if (error?.code === "ENOENT") throw new ArchiverUnavailableError(`Extraction failed: Required native binary ('tar.exe', 'powershell.exe', 'pwsh.exe' or 'unzip') was not found in the system PATH.`);
972
+ throw new Error(`Extraction failed: ${error?.stderr?.toString() || error?.message}`);
973
+ }
974
+ }
975
+ /**
976
+ * @internal
977
+ */
978
+ function isInsideDirectory(directory, candidate) {
979
+ const resolvedDirectory = path.resolve(directory);
980
+ const resolvedCandidate = path.resolve(candidate);
981
+ return resolvedCandidate === resolvedDirectory || resolvedCandidate.startsWith(resolvedDirectory + path.sep);
982
+ }
983
+ /**
984
+ * @internal
985
+ */
986
+ async function extractZipEntry(zipFile, entry, folderPath) {
987
+ const { S_IFMT, S_IFDIR, S_IFLNK } = constants;
988
+ const unixMode = entry.externalFileAttributes >>> 16;
989
+ const isDirectory = (unixMode & S_IFMT) === S_IFDIR || entry.fileName.endsWith("/") || entry.versionMadeBy >> 8 === 0 && entry.externalFileAttributes === 16;
990
+ const isSymlink = (unixMode & S_IFMT) === S_IFLNK;
991
+ const mode = unixMode === 0 ? isDirectory ? 493 : 420 : unixMode & 511;
992
+ const destination = path.join(folderPath, entry.fileName);
993
+ if (isDirectory) {
994
+ await mkdir(destination, {
995
+ recursive: true,
996
+ mode
997
+ });
998
+ return;
999
+ }
1000
+ await mkdir(path.dirname(destination), { recursive: true });
1001
+ const readStream = await promisify(zipFile.openReadStream.bind(zipFile))(entry);
1002
+ if (isSymlink) {
1003
+ const chunks = [];
1004
+ await pipeline(readStream, new Writable({ write(chunk, _encoding, callback) {
1005
+ if (chunk instanceof Buffer) chunks.push(chunk);
1006
+ callback();
1007
+ } }));
1008
+ const linkTarget = Buffer.concat(chunks).toString();
1009
+ if (!isInsideDirectory(folderPath, path.resolve(path.dirname(destination), linkTarget))) throw new Error(`Zip symlink "${entry.fileName}" would point outside of the target directory.`);
1010
+ await symlink(linkTarget, destination);
1011
+ return;
1012
+ }
1013
+ await pipeline(readStream, createWriteStream(destination, { mode }));
1014
+ }
1015
+ //#endregion
1016
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/ProgressBar.js
1017
+ /**
1018
+ * @license
1019
+ * Copyright 2026 Google Inc.
1020
+ * SPDX-License-Identifier: Apache-2.0
1021
+ */
1022
+ let activeBar = null;
1023
+ /**
1024
+ * Manages one or more concurrent progress bars on separate terminal lines.
1025
+ * Use {@link ProgressBar.createBarTicker} to add a bar; concurrent calls
1026
+ * automatically share a session so bars don't overwrite each other.
1027
+ *
1028
+ * @internal
1029
+ */
1030
+ var ProgressBar = class ProgressBar {
1031
+ #stream;
1032
+ #totalRows = 0;
1033
+ #doneCount = 0;
1034
+ #bars = [];
1035
+ #renderScheduled = false;
1036
+ #lastRenderTime = 0;
1037
+ #allDone = false;
1038
+ constructor(stream) {
1039
+ this.#stream = stream;
1040
+ }
1041
+ /**
1042
+ * Returns a `tick(delta)` function for a new progress bar. If another bar
1043
+ * is already active on the same stream, the new bar appears on the next line
1044
+ * and both update in place. The trailing newline is emitted automatically
1045
+ * once every bar in the session has reached 100%.
1046
+ */
1047
+ static createBarTicker(title, total, stream = process.stderr) {
1048
+ if (!activeBar || activeBar.#stream !== stream) activeBar = new ProgressBar(stream);
1049
+ return activeBar.#addBar(title, total);
1050
+ }
1051
+ #claimRow() {
1052
+ const row = this.#totalRows++;
1053
+ if (row > 0 && this.#stream.isTTY) this.#stream.write("\n");
1054
+ return row;
1055
+ }
1056
+ #addBar(title, total) {
1057
+ const row = this.#claimRow();
1058
+ this.#bars.push({
1059
+ title,
1060
+ total,
1061
+ downloaded: 0,
1062
+ startTime: 0,
1063
+ lastRendered: ""
1064
+ });
1065
+ let doneNotified = false;
1066
+ return (delta) => {
1067
+ const bar = this.#bars[row];
1068
+ if (bar.startTime === 0) bar.startTime = Date.now();
1069
+ bar.downloaded += delta;
1070
+ const isDone = bar.downloaded >= bar.total;
1071
+ if (isDone || Date.now() - this.#lastRenderTime >= 100) this.#scheduleRender();
1072
+ if (isDone && !doneNotified) {
1073
+ doneNotified = true;
1074
+ this.#onBarDone();
1075
+ }
1076
+ };
1077
+ }
1078
+ #scheduleRender() {
1079
+ if (!this.#renderScheduled) {
1080
+ this.#renderScheduled = true;
1081
+ queueMicrotask(() => {
1082
+ this.#renderScheduled = false;
1083
+ this.#lastRenderTime = Date.now();
1084
+ this.#renderAll();
1085
+ });
1086
+ }
1087
+ }
1088
+ #computeRendered(row) {
1089
+ const bar = this.#bars[row];
1090
+ const ratio = Math.min(1, Math.max(0, bar.downloaded / bar.total));
1091
+ const percent = Math.round(ratio * 100);
1092
+ const elapsedMs = bar.startTime > 0 ? Date.now() - bar.startTime : 0;
1093
+ const rate = elapsedMs > 0 ? bar.downloaded / elapsedMs : 0;
1094
+ const etaSec = rate > 0 ? (bar.total - bar.downloaded) / rate / 1e3 : 0;
1095
+ const width = 20;
1096
+ const completeCount = Math.round(width * ratio);
1097
+ const barStr = "=".repeat(completeCount) + " ".repeat(width - completeCount);
1098
+ const status = ratio >= 1 ? "unpacking" : `${percent}% ${etaSec.toFixed(1)}s`;
1099
+ return `${bar.title} [${barStr}] ${status} `;
1100
+ }
1101
+ #renderAll() {
1102
+ if (!this.#stream.isTTY) return;
1103
+ const N = this.#totalRows;
1104
+ if (N === 0) return;
1105
+ if (N > 1) this.#stream.moveCursor(0, -(N - 1));
1106
+ for (let row = 0; row < N; row++) {
1107
+ const rendered = this.#computeRendered(row);
1108
+ if (rendered !== this.#bars[row].lastRendered) {
1109
+ this.#stream.cursorTo(0);
1110
+ this.#stream.write(rendered);
1111
+ this.#stream.clearLine(1);
1112
+ this.#bars[row].lastRendered = rendered;
1113
+ }
1114
+ if (row < N - 1) this.#stream.moveCursor(0, 1);
1115
+ }
1116
+ this.#stream.cursorTo(0);
1117
+ if (this.#allDone) {
1118
+ activeBar = null;
1119
+ this.#stream.write("\n");
1120
+ }
1121
+ }
1122
+ #onBarDone() {
1123
+ this.#doneCount++;
1124
+ if (this.#doneCount >= this.#totalRows && this.#totalRows > 0) this.#allDone = true;
1125
+ }
1126
+ };
1127
+ //#endregion
1128
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/install.js
1129
+ /**
1130
+ * @license
1131
+ * Copyright 2017 Google Inc.
1132
+ * SPDX-License-Identifier: Apache-2.0
1133
+ */
1134
+ const times = /* @__PURE__ */ new Map();
1135
+ function debugTime(label) {
1136
+ times.set(label, process.hrtime());
1137
+ }
1138
+ function debugTimeEnd(label, logger) {
1139
+ const end = process.hrtime();
1140
+ const start = times.get(label);
1141
+ if (!start) return;
1142
+ const duration = end[0] * 1e3 + end[1] / 1e6 - (start[0] * 1e3 + start[1] / 1e6);
1143
+ logger?.(DEBUG_PREFIXES.install)?.(`Duration for ${label}: ${duration}ms`);
1144
+ }
1145
+ /**
1146
+ * Thrown when an installation folder is present but does not hold a browser
1147
+ * that can be launched.
1148
+ *
1149
+ * @internal
1150
+ */
1151
+ var IncompleteInstallationError = class extends Error {};
1152
+ /**
1153
+ * Install using custom provider plugins.
1154
+ * Tries each provider in order until one succeeds.
1155
+ * Falls back to default provider if all custom providers fail.
1156
+ *
1157
+ * @internal
1158
+ */
1159
+ async function installWithProviders(options) {
1160
+ if (!options.platform) throw new Error("Platform must be defined");
1161
+ const logger = options.logger;
1162
+ const browserRoot = new Cache(options.cacheDir, options.logger).browserRoot(options.browser);
1163
+ const providers = [...options.providers || []];
1164
+ if (options.baseUrl) providers.push(new DefaultProvider(options.baseUrl));
1165
+ if (!options.baseUrl || options.forceFallbackForTesting) providers.push(new DefaultProvider());
1166
+ const downloadOptions = {
1167
+ browser: options.browser,
1168
+ platform: options.platform,
1169
+ buildId: options.buildId,
1170
+ progressCallback: options.downloadProgressCallback === "default" ? await makeProgressCallback(options.browser, options.buildIdAlias ?? options.buildId) : options.downloadProgressCallback
1171
+ };
1172
+ const errors = [];
1173
+ for (const provider of providers) try {
1174
+ if (!await provider.supports(downloadOptions)) {
1175
+ logger?.(DEBUG_PREFIXES.install)?.(`Provider ${provider.getName()} does not support ${options.browser} on ${options.platform}`);
1176
+ continue;
1177
+ }
1178
+ if (!(provider instanceof DefaultProvider)) {
1179
+ logger?.(DEBUG_PREFIXES.install)?.(`⚠️ Using custom downloader: ${provider.getName()}`);
1180
+ logger?.(DEBUG_PREFIXES.install)?.(`⚠️ Puppeteer does not guarantee compatibility with non-default providers`);
1181
+ }
1182
+ logger?.(DEBUG_PREFIXES.install)?.(`Trying provider: ${provider.getName()} for ${options.browser} ${options.buildId}`);
1183
+ const url = await provider.getDownloadUrl(downloadOptions);
1184
+ if (!url) {
1185
+ logger?.(DEBUG_PREFIXES.install)?.(`Provider ${provider.getName()} returned no URL for ${options.browser} ${options.buildId}`);
1186
+ continue;
1187
+ }
1188
+ logger?.(DEBUG_PREFIXES.install)?.(`Successfully got URL from ${provider.getName()}: ${url}`);
1189
+ if (!existsSync(browserRoot)) await mkdir(browserRoot, { recursive: true });
1190
+ return await installUrl(url, options, provider, logger);
1191
+ } catch (err) {
1192
+ logger?.(DEBUG_PREFIXES.install)?.(`Provider ${provider.getName()} failed: ${err.message}`);
1193
+ errors.push({
1194
+ providerName: provider.getName(),
1195
+ error: err
1196
+ });
1197
+ }
1198
+ const errorDetails = errors.map((e) => {
1199
+ return ` - ${e.providerName}: ${e.error.message}`;
1200
+ }).join("\n");
1201
+ const message = `All providers failed for ${options.browser} ${options.buildId}:\n${errorDetails}`;
1202
+ if (errors.length > 0 && errors.every((e) => {
1203
+ return e.error instanceof IncompleteInstallationError;
1204
+ })) throw new IncompleteInstallationError(message);
1205
+ throw new Error(message);
1206
+ }
1207
+ async function install(options) {
1208
+ options.platform ??= detectBrowserPlatform();
1209
+ options.unpack ??= true;
1210
+ options.logger ??= debug;
1211
+ if (!options.platform) throw new Error(`Cannot download a binary for the provided platform: ${os.platform()} (${os.arch()})`);
1212
+ options.providers ??= [];
1213
+ return await installWithProviders(options);
1214
+ }
1215
+ async function installDeps(installedBrowser, logger) {
1216
+ if (process.platform !== "linux" || installedBrowser.platform !== BrowserPlatform.LINUX && installedBrowser.platform !== BrowserPlatform.LINUX_ARM) return;
1217
+ const depsPath = nodePath.join(nodePath.dirname(installedBrowser.executablePath), "deb.deps");
1218
+ if (!existsSync(depsPath)) {
1219
+ logger?.(DEBUG_PREFIXES.install)?.(`deb.deps file was not found at ${depsPath}`);
1220
+ return;
1221
+ }
1222
+ const data = readFileSync(depsPath, "utf-8").split("\n").join(",");
1223
+ if (process.getuid?.() !== 0) throw new Error("Installing system dependencies requires root privileges");
1224
+ let result = spawnSync("apt-get", ["-v"]);
1225
+ if (result.status !== 0) throw new Error("Failed to install system dependencies: apt-get does not seem to be available");
1226
+ logger?.(DEBUG_PREFIXES.install)?.(`Trying to install dependencies: ${data}`);
1227
+ result = spawnSync("apt-get", [
1228
+ "satisfy",
1229
+ "-y",
1230
+ data,
1231
+ "--no-install-recommends"
1232
+ ]);
1233
+ if (result.status !== 0) throw new Error(`Failed to install system dependencies: status=${result.status},error=${result.error},stdout=${result.stdout.toString("utf8")},stderr=${result.stderr.toString("utf8")}`);
1234
+ logger?.(DEBUG_PREFIXES.install)?.(`Installed system dependencies ${data}`);
1235
+ }
1236
+ async function installUrl(url, options, provider, logger) {
1237
+ if (!provider) throw new Error("Provider is required for installation");
1238
+ options.platform ??= detectBrowserPlatform();
1239
+ if (!options.platform) throw new Error(`Cannot download a binary for the provided platform: ${os.platform()} (${os.arch()})`);
1240
+ let downloadProgressCallback = options.downloadProgressCallback;
1241
+ if (downloadProgressCallback === "default") downloadProgressCallback = await makeProgressCallback(options.browser, options.buildIdAlias ?? options.buildId);
1242
+ const fileName = decodeURIComponent(url.toString()).split("/").pop();
1243
+ assert(fileName, `A malformed download URL was found: ${url}.`);
1244
+ const cache = new Cache(options.cacheDir, options.logger);
1245
+ const browserRoot = cache.browserRoot(options.browser);
1246
+ const archivePath = nodePath.join(browserRoot, `${options.buildId}-${fileName}`);
1247
+ if (!existsSync(browserRoot)) await mkdir(browserRoot, { recursive: true });
1248
+ if (options.expectedHash) logger?.(DEBUG_PREFIXES.install)?.(`Using provided checksum for ${fileName}: ${options.expectedHash}`);
1249
+ if (!options.unpack) {
1250
+ if (existsSync(archivePath)) return archivePath;
1251
+ logger?.(DEBUG_PREFIXES.install)?.(`Downloading binary from ${url}`);
1252
+ debugTime("download");
1253
+ await downloadFile(url, archivePath, downloadProgressCallback, options.expectedHash);
1254
+ debugTimeEnd("download", logger);
1255
+ return archivePath;
1256
+ }
1257
+ const outputPath = cache.installationDir(options.browser, options.platform, options.buildId);
1258
+ const relativeExecutablePath = await provider.getExecutablePath({
1259
+ browser: options.browser,
1260
+ buildId: options.buildId,
1261
+ platform: options.platform
1262
+ });
1263
+ logger?.(DEBUG_PREFIXES.install)?.(`Using executable path from provider: ${relativeExecutablePath}`);
1264
+ const installedBrowser = new InstalledBrowser(cache, options.browser, options.buildId, options.platform);
1265
+ if (!(provider instanceof DefaultProvider)) cache.writeExecutablePath(options.browser, options.platform, options.buildId, relativeExecutablePath);
1266
+ try {
1267
+ if (existsSync(outputPath)) {
1268
+ if (!existsSync(installedBrowser.executablePath)) throw new IncompleteInstallationError(`The browser folder (${outputPath}) exists but the executable (${installedBrowser.executablePath}) is missing. An earlier install of this build probably did not finish. Delete ${outputPath} and install the browser again.`);
1269
+ await runSetup(installedBrowser, logger);
1270
+ if (options.installDeps) await installDeps(installedBrowser, logger);
1271
+ return installedBrowser;
1272
+ }
1273
+ if (!existsSync(archivePath)) {
1274
+ logger?.(DEBUG_PREFIXES.install)?.(`Downloading binary from ${url}`);
1275
+ try {
1276
+ debugTime("download");
1277
+ await downloadFile(url, archivePath, downloadProgressCallback, options.expectedHash);
1278
+ } finally {
1279
+ debugTimeEnd("download", logger);
1280
+ }
1281
+ } else logger?.(DEBUG_PREFIXES.install)?.(`Using existing archive at ${archivePath}`);
1282
+ logger?.(DEBUG_PREFIXES.install)?.(`Installing ${archivePath} to ${outputPath}`);
1283
+ try {
1284
+ debugTime("extract");
1285
+ await unpackArchive(archivePath, outputPath, options.logger);
1286
+ } finally {
1287
+ debugTimeEnd("extract", logger);
1288
+ }
1289
+ if (options.buildIdAlias) {
1290
+ const metadata = installedBrowser.readMetadata();
1291
+ metadata.aliases[options.buildIdAlias] = options.buildId;
1292
+ installedBrowser.writeMetadata(metadata);
1293
+ }
1294
+ await runSetup(installedBrowser, logger);
1295
+ if (options.installDeps) await installDeps(installedBrowser, logger);
1296
+ return installedBrowser;
1297
+ } finally {
1298
+ if (existsSync(archivePath)) await unlink(archivePath);
1299
+ }
1300
+ }
1301
+ async function runSetup(installedBrowser, logger) {
1302
+ if ((installedBrowser.platform === BrowserPlatform.WIN32 || installedBrowser.platform === BrowserPlatform.WIN64) && installedBrowser.browser === Browser.CHROME && installedBrowser.platform === detectBrowserPlatform()) try {
1303
+ debugTime("permissions");
1304
+ const browserDir = nodePath.dirname(installedBrowser.executablePath);
1305
+ const setupExePath = nodePath.join(browserDir, "setup.exe");
1306
+ if (!existsSync(setupExePath)) return;
1307
+ spawnSync(nodePath.join(browserDir, "setup.exe"), [`--configure-browser-in-directory=` + browserDir], { shell: false });
1308
+ } finally {
1309
+ debugTimeEnd("permissions", logger);
1310
+ }
1311
+ }
1312
+ /**
1313
+ * @internal
1314
+ */
1315
+ async function makeProgressCallback(browser, buildId) {
1316
+ let ticker;
1317
+ let lastDownloadedBytes = 0;
1318
+ return (downloadedBytes, totalBytes) => {
1319
+ if (!ticker) ticker = ProgressBar.createBarTicker(`Downloading ${browser} ${buildId} - ${toMegabytes(totalBytes)}`, totalBytes);
1320
+ const delta = downloadedBytes - lastDownloadedBytes;
1321
+ lastDownloadedBytes = downloadedBytes;
1322
+ ticker(delta);
1323
+ };
1324
+ }
1325
+ function toMegabytes(bytes) {
1326
+ const mb = bytes / 1e3 / 1e3;
1327
+ return `${Math.round(mb * 10) / 10} MB`;
1328
+ }
1329
+ //#endregion
1330
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/CLI.js
1331
+ /**
1332
+ * @license
1333
+ * Copyright 2023 Google Inc.
1334
+ * SPDX-License-Identifier: Apache-2.0
1335
+ */
1336
+ //#endregion
1337
+ //#region node_modules/.pnpm/@puppeteer+browsers@3.2.2/node_modules/@puppeteer/browsers/lib/main.js
1338
+ /**
1339
+ * @license
1340
+ * Copyright 2023 Google Inc.
1341
+ * SPDX-License-Identifier: Apache-2.0
1342
+ */
1343
+ //#endregion
1344
+ export { Browser, install };