mcp-browser-dev-tools 0.0.2-beta.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -139
- package/package.json +3 -1
- package/src/app.mjs +22 -1
- package/src/browser-adapter.mjs +27 -0
- package/src/browser-launch-service.mjs +515 -0
- package/src/cdp-client.mjs +261 -5
- package/src/cli.mjs +57 -202
- package/src/config.mjs +1 -1
- package/src/firefox-bidi-client.mjs +180 -16
- package/src/mcp-server.mjs +553 -0
- package/src/page-context.mjs +217 -0
- package/src/serve-bootstrap.mjs +290 -0
- package/src/session-events.mjs +83 -0
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
import { execFile, spawn } from "node:child_process";
|
|
2
|
+
import { mkdir, mkdtemp, readFile } from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
buildBrowserLaunchArgs,
|
|
10
|
+
findBrowserExecutable,
|
|
11
|
+
} from "./browser-launcher.mjs";
|
|
12
|
+
import { isLoopbackHost } from "./config.mjs";
|
|
13
|
+
import { collectDoctorReport } from "./doctor.mjs";
|
|
14
|
+
|
|
15
|
+
const FIREFOX_BIDI_SERVER_FILENAME = "WebDriverBiDiServer.json";
|
|
16
|
+
const execFileAsync = promisify(execFile);
|
|
17
|
+
|
|
18
|
+
function detectRuntimePlatform(env = process.env) {
|
|
19
|
+
const release = os.release().toLowerCase();
|
|
20
|
+
if (
|
|
21
|
+
process.platform === "linux" &&
|
|
22
|
+
(release.includes("microsoft") || env.WSL_INTEROP)
|
|
23
|
+
) {
|
|
24
|
+
return "wsl";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return process.platform;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function sleep(ms) {
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
setTimeout(resolve, ms);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isHttpLikeUrl(value) {
|
|
37
|
+
try {
|
|
38
|
+
const url = new URL(value);
|
|
39
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
40
|
+
} catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function normalizeFirefoxDoctorHost(value) {
|
|
46
|
+
const host = typeof value === "string" ? value.trim() : "";
|
|
47
|
+
if (!host || host === "0.0.0.0" || host === "::" || host === "[::]") {
|
|
48
|
+
return "127.0.0.1";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return host;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function normalizeFirefoxDoctorPath(value) {
|
|
55
|
+
if (typeof value !== "string") {
|
|
56
|
+
return "/";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const trimmed = value.trim();
|
|
60
|
+
if (!trimmed) {
|
|
61
|
+
return "/";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function normalizeStringValue(value) {
|
|
68
|
+
if (typeof value !== "string") {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const trimmed = value.trim();
|
|
73
|
+
return trimmed ? trimmed : null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function normalizeIntegerValue(value, optionName, { minimum = 1 } = {}) {
|
|
77
|
+
if (value === undefined || value === null || value === "") {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const parsed =
|
|
82
|
+
typeof value === "number" ? value : Number.parseInt(String(value), 10);
|
|
83
|
+
if (!Number.isInteger(parsed) || parsed < minimum) {
|
|
84
|
+
throw new Error(`${optionName} must be an integer >= ${minimum}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return String(parsed);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function resolveDefaultPort(config, family) {
|
|
91
|
+
if (family === "firefox") {
|
|
92
|
+
return new URL(config.firefoxBidiWsUrl).port || "9222";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return new URL(config.cdpBaseUrl).port || "9222";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function resolveDefaultAddress(config) {
|
|
99
|
+
const host = new URL(config.cdpBaseUrl).hostname;
|
|
100
|
+
return host || "127.0.0.1";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function browserProcessMatchers(family) {
|
|
104
|
+
if (family === "edge") {
|
|
105
|
+
return [
|
|
106
|
+
"msedge",
|
|
107
|
+
"msedge.exe",
|
|
108
|
+
"microsoft edge",
|
|
109
|
+
"microsoft-edge",
|
|
110
|
+
"microsoft-edge-stable",
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (family === "firefox") {
|
|
115
|
+
return ["firefox", "firefox.exe"];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return [
|
|
119
|
+
"chrome",
|
|
120
|
+
"chrome.exe",
|
|
121
|
+
"google chrome",
|
|
122
|
+
"google-chrome",
|
|
123
|
+
"google-chrome-stable",
|
|
124
|
+
"chromium",
|
|
125
|
+
"chromium.exe",
|
|
126
|
+
"chromium-browser",
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function normalizeProcessEntry(value) {
|
|
131
|
+
if (typeof value !== "string") {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const trimmed = value.trim().replace(/^"+|"+$/g, "");
|
|
136
|
+
if (!trimmed) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const lowered = trimmed.toLowerCase();
|
|
141
|
+
const basename = lowered.split(/[\\/]/).pop();
|
|
142
|
+
return basename || lowered;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function parsePsProcessList(stdout) {
|
|
146
|
+
return String(stdout)
|
|
147
|
+
.split(/\r?\n/)
|
|
148
|
+
.map((line) => normalizeProcessEntry(line))
|
|
149
|
+
.filter(Boolean);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function parseTasklistProcessList(stdout) {
|
|
153
|
+
return String(stdout)
|
|
154
|
+
.split(/\r?\n/)
|
|
155
|
+
.map((line) => {
|
|
156
|
+
const match = line.match(/^"([^"]+)"/);
|
|
157
|
+
if (!match) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return normalizeProcessEntry(match[1]);
|
|
162
|
+
})
|
|
163
|
+
.filter(Boolean);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async function collectRunningProcesses(
|
|
167
|
+
platform,
|
|
168
|
+
{ execFileFn = execFileAsync } = {},
|
|
169
|
+
) {
|
|
170
|
+
const sources = [];
|
|
171
|
+
const entries = [];
|
|
172
|
+
const errors = [];
|
|
173
|
+
|
|
174
|
+
const runSource = async (source, command, args, parser) => {
|
|
175
|
+
try {
|
|
176
|
+
const { stdout } = await execFileFn(command, args, {
|
|
177
|
+
windowsHide: true,
|
|
178
|
+
maxBuffer: 2 * 1024 * 1024,
|
|
179
|
+
});
|
|
180
|
+
sources.push(source);
|
|
181
|
+
entries.push(...parser(stdout));
|
|
182
|
+
} catch (error) {
|
|
183
|
+
errors.push(`${source}: ${error?.message ?? String(error)}`);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
if (platform === "win32") {
|
|
188
|
+
await runSource(
|
|
189
|
+
"tasklist",
|
|
190
|
+
"tasklist.exe",
|
|
191
|
+
["/fo", "csv", "/nh"],
|
|
192
|
+
parseTasklistProcessList,
|
|
193
|
+
);
|
|
194
|
+
} else {
|
|
195
|
+
await runSource("ps", "ps", ["-A", "-o", "comm="], parsePsProcessList);
|
|
196
|
+
if (platform === "wsl") {
|
|
197
|
+
await runSource(
|
|
198
|
+
"tasklist",
|
|
199
|
+
"tasklist.exe",
|
|
200
|
+
["/fo", "csv", "/nh"],
|
|
201
|
+
parseTasklistProcessList,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
checked: sources.length > 0,
|
|
208
|
+
sources,
|
|
209
|
+
entries: [...new Set(entries)],
|
|
210
|
+
error: errors.length > 0 ? errors.join("; ") : null,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function detectRunningBrowserProcess(
|
|
215
|
+
family,
|
|
216
|
+
{ env = process.env, execFileFn = execFileAsync } = {},
|
|
217
|
+
) {
|
|
218
|
+
const platform = detectRuntimePlatform(env);
|
|
219
|
+
const processList = await collectRunningProcesses(platform, { execFileFn });
|
|
220
|
+
const matchers = browserProcessMatchers(family);
|
|
221
|
+
const matches = processList.entries.filter((entry) =>
|
|
222
|
+
matchers.includes(entry),
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
checked: processList.checked,
|
|
227
|
+
detected: matches.length > 0,
|
|
228
|
+
matches,
|
|
229
|
+
sources: processList.sources,
|
|
230
|
+
error: processList.error,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function maybeCreateAutomaticUserDataDir(
|
|
235
|
+
family,
|
|
236
|
+
normalizedUserDataDir,
|
|
237
|
+
{
|
|
238
|
+
env = process.env,
|
|
239
|
+
execFileFn = execFileAsync,
|
|
240
|
+
mkdtempFn = mkdtemp,
|
|
241
|
+
tmpdirFn = os.tmpdir,
|
|
242
|
+
} = {},
|
|
243
|
+
) {
|
|
244
|
+
const existingBrowserProcess = await detectRunningBrowserProcess(family, {
|
|
245
|
+
env,
|
|
246
|
+
execFileFn,
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
if (
|
|
250
|
+
(family === "chromium" || family === "edge") &&
|
|
251
|
+
!normalizedUserDataDir &&
|
|
252
|
+
existingBrowserProcess.detected
|
|
253
|
+
) {
|
|
254
|
+
return {
|
|
255
|
+
userDataDir: await mkdtempFn(
|
|
256
|
+
path.join(tmpdirFn(), `mcp-browser-dev-tools-${family}-`),
|
|
257
|
+
),
|
|
258
|
+
profileStrategy: "temporary",
|
|
259
|
+
existingBrowserProcess,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
userDataDir: normalizedUserDataDir,
|
|
265
|
+
profileStrategy: normalizedUserDataDir ? "provided" : "default",
|
|
266
|
+
existingBrowserProcess,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export function supportedLaunchFamilies(configuredFamily) {
|
|
271
|
+
if (configuredFamily === "auto") {
|
|
272
|
+
return ["chromium", "edge", "firefox"];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (configuredFamily === "firefox") {
|
|
276
|
+
return ["firefox"];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return ["chromium", "edge"];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function resolveLaunchFamily(configuredFamily, requestedFamily) {
|
|
283
|
+
const allowedFamilies = supportedLaunchFamilies(configuredFamily);
|
|
284
|
+
if (!requestedFamily) {
|
|
285
|
+
if (configuredFamily === "auto") {
|
|
286
|
+
throw new Error(
|
|
287
|
+
"browserFamily is required when multiple browser families are configured",
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return configuredFamily;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (!allowedFamilies.includes(requestedFamily)) {
|
|
295
|
+
throw new Error(
|
|
296
|
+
`browserFamily must be one of: ${allowedFamilies.join(", ")}`,
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return requestedFamily;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export function parseFirefoxBidiServerInfo(contents) {
|
|
304
|
+
const parsed = JSON.parse(contents);
|
|
305
|
+
if (!parsed || typeof parsed !== "object") {
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const directUrl =
|
|
310
|
+
parsed.webSocketUrl ??
|
|
311
|
+
parsed.websocketUrl ??
|
|
312
|
+
parsed.wsUrl ??
|
|
313
|
+
parsed.ws_url ??
|
|
314
|
+
null;
|
|
315
|
+
if (typeof directUrl === "string" && directUrl.trim()) {
|
|
316
|
+
return directUrl.trim().replace(/\/+$/, "");
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const port =
|
|
320
|
+
parsed.ws_port ?? parsed.port ?? parsed.remoteDebuggingPort ?? null;
|
|
321
|
+
if (!Number.isInteger(port) && !/^\d+$/.test(String(port ?? "").trim())) {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const host = normalizeFirefoxDoctorHost(
|
|
326
|
+
parsed.ws_host ?? parsed.host ?? parsed.hostname ?? "127.0.0.1",
|
|
327
|
+
);
|
|
328
|
+
const protocol =
|
|
329
|
+
parsed.protocol === "https" || parsed.protocol === "wss" ? "wss:" : "ws:";
|
|
330
|
+
const endpoint = new URL(`${protocol}//${host}`);
|
|
331
|
+
endpoint.port = String(port);
|
|
332
|
+
endpoint.pathname = normalizeFirefoxDoctorPath(
|
|
333
|
+
parsed.path ?? parsed.ws_path ?? "/",
|
|
334
|
+
);
|
|
335
|
+
return endpoint.toString().replace(/\/+$/, "");
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export async function resolveFirefoxDoctorEndpoint(
|
|
339
|
+
{ userDataDir, fallbackPort },
|
|
340
|
+
{ readFileFn = readFile } = {},
|
|
341
|
+
) {
|
|
342
|
+
if (!userDataDir) {
|
|
343
|
+
return `ws://127.0.0.1:${fallbackPort}`;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
try {
|
|
347
|
+
const serverInfo = await readFileFn(
|
|
348
|
+
path.join(userDataDir, FIREFOX_BIDI_SERVER_FILENAME),
|
|
349
|
+
"utf8",
|
|
350
|
+
);
|
|
351
|
+
return (
|
|
352
|
+
parseFirefoxBidiServerInfo(serverInfo) ?? `ws://127.0.0.1:${fallbackPort}`
|
|
353
|
+
);
|
|
354
|
+
} catch (error) {
|
|
355
|
+
if (error?.code === "ENOENT") {
|
|
356
|
+
return `ws://127.0.0.1:${fallbackPort}`;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return `ws://127.0.0.1:${fallbackPort}`;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export async function launchBrowser(
|
|
364
|
+
{
|
|
365
|
+
config,
|
|
366
|
+
browserFamily,
|
|
367
|
+
url = "about:blank",
|
|
368
|
+
port,
|
|
369
|
+
address,
|
|
370
|
+
userDataDir,
|
|
371
|
+
waitMs = 5_000,
|
|
372
|
+
skipDoctor = false,
|
|
373
|
+
env = process.env,
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
spawnProcess = spawn,
|
|
377
|
+
mkdirFn = mkdir,
|
|
378
|
+
mkdtempFn = mkdtemp,
|
|
379
|
+
execFileFn = execFileAsync,
|
|
380
|
+
tmpdirFn = os.tmpdir,
|
|
381
|
+
findBrowserExecutableFn = findBrowserExecutable,
|
|
382
|
+
collectDoctorReportFn = collectDoctorReport,
|
|
383
|
+
resolveFirefoxDoctorEndpointFn = resolveFirefoxDoctorEndpoint,
|
|
384
|
+
sleepFn = sleep,
|
|
385
|
+
} = {},
|
|
386
|
+
) {
|
|
387
|
+
const family = resolveLaunchFamily(config.browserFamily, browserFamily);
|
|
388
|
+
const targetUrl = normalizeStringValue(url) ?? "about:blank";
|
|
389
|
+
const resolvedPort =
|
|
390
|
+
normalizeIntegerValue(port, "port", { minimum: 1 }) ??
|
|
391
|
+
resolveDefaultPort(config, family);
|
|
392
|
+
const requestedAddress =
|
|
393
|
+
family === "firefox" ? null : normalizeStringValue(address);
|
|
394
|
+
|
|
395
|
+
if (
|
|
396
|
+
requestedAddress &&
|
|
397
|
+
!isLoopbackHost(requestedAddress) &&
|
|
398
|
+
!config.allowRemoteEndpoints
|
|
399
|
+
) {
|
|
400
|
+
throw new Error(
|
|
401
|
+
"--address must be loopback unless MCP_BROWSER_ALLOW_REMOTE_ENDPOINTS=1",
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const executable = await findBrowserExecutableFn(family, env);
|
|
406
|
+
if (!executable) {
|
|
407
|
+
throw new Error(`No local ${family} browser executable found`);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const providedUserDataDir = normalizeStringValue(userDataDir) ?? undefined;
|
|
411
|
+
const {
|
|
412
|
+
userDataDir: normalizedUserDataDir,
|
|
413
|
+
profileStrategy,
|
|
414
|
+
existingBrowserProcess,
|
|
415
|
+
} = await maybeCreateAutomaticUserDataDir(family, providedUserDataDir, {
|
|
416
|
+
env,
|
|
417
|
+
execFileFn,
|
|
418
|
+
mkdtempFn,
|
|
419
|
+
tmpdirFn,
|
|
420
|
+
});
|
|
421
|
+
if (family === "firefox" && normalizedUserDataDir) {
|
|
422
|
+
await mkdirFn(normalizedUserDataDir, { recursive: true });
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const launchAddress = family === "firefox" ? null : requestedAddress;
|
|
426
|
+
const endpointAddress =
|
|
427
|
+
family === "firefox"
|
|
428
|
+
? null
|
|
429
|
+
: (requestedAddress ?? resolveDefaultAddress(config));
|
|
430
|
+
const args = buildBrowserLaunchArgs({
|
|
431
|
+
family,
|
|
432
|
+
url: targetUrl,
|
|
433
|
+
remoteDebuggingPort: resolvedPort,
|
|
434
|
+
remoteDebuggingAddress: launchAddress ?? undefined,
|
|
435
|
+
userDataDir: normalizedUserDataDir,
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
const child = spawnProcess(executable, args, {
|
|
439
|
+
detached: true,
|
|
440
|
+
stdio: "ignore",
|
|
441
|
+
});
|
|
442
|
+
child.unref?.();
|
|
443
|
+
|
|
444
|
+
const launchedAt = new Date().toISOString();
|
|
445
|
+
const result = {
|
|
446
|
+
browserFamily: family,
|
|
447
|
+
url: targetUrl,
|
|
448
|
+
executable,
|
|
449
|
+
args,
|
|
450
|
+
pid: child.pid ?? null,
|
|
451
|
+
launchedAt,
|
|
452
|
+
endpoint:
|
|
453
|
+
family === "firefox"
|
|
454
|
+
? `ws://127.0.0.1:${resolvedPort}`
|
|
455
|
+
: `http://${endpointAddress}:${resolvedPort}`,
|
|
456
|
+
userDataDir: normalizedUserDataDir ?? null,
|
|
457
|
+
profileStrategy,
|
|
458
|
+
existingBrowserProcess,
|
|
459
|
+
doctorReport: null,
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
if (skipDoctor) {
|
|
463
|
+
return result;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const timeoutMs =
|
|
467
|
+
Number.parseInt(
|
|
468
|
+
normalizeIntegerValue(waitMs, "waitMs", { minimum: 0 }) ?? "5000",
|
|
469
|
+
10,
|
|
470
|
+
) || 0;
|
|
471
|
+
const startedAt = Date.now();
|
|
472
|
+
const doctorEnv = {
|
|
473
|
+
...env,
|
|
474
|
+
MCP_BROWSER_FAMILY: family,
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
if (family === "firefox") {
|
|
478
|
+
doctorEnv.FIREFOX_BIDI_WS_URL = await resolveFirefoxDoctorEndpointFn({
|
|
479
|
+
userDataDir: normalizedUserDataDir,
|
|
480
|
+
fallbackPort: resolvedPort,
|
|
481
|
+
});
|
|
482
|
+
} else {
|
|
483
|
+
doctorEnv.CDP_BASE_URL = result.endpoint;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
let report = await collectDoctorReportFn({
|
|
487
|
+
env: doctorEnv,
|
|
488
|
+
url: isHttpLikeUrl(targetUrl) ? targetUrl : null,
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
while (
|
|
492
|
+
!report.browserStatus.available &&
|
|
493
|
+
Date.now() - startedAt < timeoutMs
|
|
494
|
+
) {
|
|
495
|
+
await sleepFn(250);
|
|
496
|
+
if (family === "firefox") {
|
|
497
|
+
doctorEnv.FIREFOX_BIDI_WS_URL = await resolveFirefoxDoctorEndpointFn({
|
|
498
|
+
userDataDir: normalizedUserDataDir,
|
|
499
|
+
fallbackPort: resolvedPort,
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
report = await collectDoctorReportFn({
|
|
504
|
+
env: doctorEnv,
|
|
505
|
+
url: isHttpLikeUrl(targetUrl) ? targetUrl : null,
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
result.endpoint =
|
|
510
|
+
family === "firefox"
|
|
511
|
+
? doctorEnv.FIREFOX_BIDI_WS_URL
|
|
512
|
+
: doctorEnv.CDP_BASE_URL;
|
|
513
|
+
result.doctorReport = report;
|
|
514
|
+
return result;
|
|
515
|
+
}
|