Skip to content

Commit 95d811b

Browse files
committed
Fix formatting, run doc gen
1 parent 7e0b463 commit 95d811b

8 files changed

Lines changed: 222 additions & 132 deletions

File tree

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -789,11 +789,11 @@ npx chrome-devtools-mcp@latest --browser=edge --channel=beta
789789

790790
The MCP server automatically detects Edge installations in the standard locations:
791791

792-
| Platform | Stable channel path |
793-
|----------|-------------|
794-
| **Windows** | `C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe` |
795-
| **macOS** | `/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge` |
796-
| **Linux** | `/opt/microsoft/msedge/msedge` or `/usr/bin/microsoft-edge` |
792+
| Platform | Stable channel path |
793+
| ----------- | ---------------------------------------------------------------- |
794+
| **Windows** | `C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe` |
795+
| **macOS** | `/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge` |
796+
| **Linux** | `/opt/microsoft/msedge/msedge` or `/usr/bin/microsoft-edge` |
797797

798798
If Edge is installed in a non-standard location, use `--executablePath` to specify the path manually.
799799

@@ -813,7 +813,12 @@ Use `--autoConnect` with `--browser=edge` to connect to an already-running Edge
813813
"mcpServers": {
814814
"chrome-devtools": {
815815
"command": "npx",
816-
"args": ["-y", "chrome-devtools-mcp@latest", "--autoConnect", "--browser=edge"]
816+
"args": [
817+
"-y",
818+
"chrome-devtools-mcp@latest",
819+
"--autoConnect",
820+
"--browser=edge"
821+
]
817822
}
818823
}
819824
}

src/McpContext.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,7 @@ export class McpContext implements Context {
507507
const allTargets = await this.browser.targets();
508508

509509
const serviceWorkers = allTargets.filter(target => {
510-
return (
511-
target.type() === 'service_worker' &&
512-
isExtensionUrl(target.url())
513-
);
510+
return target.type() === 'service_worker' && isExtensionUrl(target.url());
514511
});
515512

516513
for (const serviceWorker of serviceWorkers) {
@@ -589,10 +586,7 @@ export class McpContext implements Context {
589586

590587
const allTargets = this.browser.targets();
591588
const extensionTargets = allTargets.filter(target => {
592-
return (
593-
isExtensionUrl(target.url()) &&
594-
target.type() === 'page'
595-
);
589+
return isExtensionUrl(target.url()) && target.type() === 'page';
596590
});
597591

598592
for (const target of extensionTargets) {

src/bin/chrome-devtools-mcp-cli-options.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,11 @@ export function parseArguments(version: string, argv = process.argv) {
281281
args.channel = 'stable';
282282
}
283283
// Edge Canary is not available on Linux.
284-
if (args.browser === 'edge' && args.channel === 'canary' && os.platform() === 'linux') {
284+
if (
285+
args.browser === 'edge' &&
286+
args.channel === 'canary' &&
287+
os.platform() === 'linux'
288+
) {
285289
throw new Error(
286290
`Edge Canary is not available on Linux. Use --executablePath to specify a custom Edge binary.`,
287291
);

src/browser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,9 @@ export function inspectUrl(browserKind: BrowserKind): string {
317317
}
318318

319319
export function isExtensionUrl(url: string): boolean {
320-
return url.startsWith('chrome-extension://') ||
321-
url.startsWith('edge-extension://');
320+
return (
321+
url.startsWith('chrome-extension://') || url.startsWith('edge-extension://')
322+
);
322323
}
323324

324325
export function isBrowserNewTabUrl(url: string): boolean {

src/edgePaths.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ const EDGE_EXECUTABLE_PATHS: Record<
111111
],
112112
},
113113
darwin: {
114-
stable: [
115-
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
116-
],
114+
stable: ['/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge'],
117115
beta: [
118116
'/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta',
119117
],
@@ -135,27 +133,25 @@ export function resolveEdgeExecutablePath(channel: Channel): string {
135133
const platform = os.platform();
136134
const paths = EDGE_EXECUTABLE_PATHS[platform]?.[channel];
137135
if (!paths || paths.length === 0) {
138-
throw new Error(
139-
`Edge ${channel} channel is not available on ${platform}.`,
140-
);
136+
throw new Error(`Edge ${channel} channel is not available on ${platform}.`);
141137
}
142138
for (const candidate of paths) {
143139
if (fs.existsSync(candidate)) {
144140
return candidate;
145141
}
146142
}
147-
const channelName = channel === 'stable' ? 'Edge' : `Edge ${channel[0].toUpperCase() + channel.slice(1)}`;
143+
const channelName =
144+
channel === 'stable'
145+
? 'Edge'
146+
: `Edge ${channel[0].toUpperCase() + channel.slice(1)}`;
148147
throw new Error(
149148
`Could not find Microsoft ${channelName} executable. Tried:\n` +
150149
paths.map(p => ` ${p}`).join('\n') +
151150
`\nInstall ${channelName} or use --executablePath to specify the path manually.`,
152151
);
153152
}
154153

155-
const EDGE_USER_DATA_DIRS: Record<
156-
string,
157-
Partial<Record<Channel, string>>
158-
> = {
154+
const EDGE_USER_DATA_DIRS: Record<string, Partial<Record<Channel, string>>> = {
159155
win32: {
160156
...(process.env['LOCALAPPDATA']
161157
? {
@@ -223,9 +219,7 @@ export function resolveEdgeUserDataDir(channel: Channel): string {
223219
const platform = os.platform();
224220
const dir = EDGE_USER_DATA_DIRS[platform]?.[channel];
225221
if (!dir) {
226-
throw new Error(
227-
`Edge ${channel} channel is not available on ${platform}.`,
228-
);
222+
throw new Error(`Edge ${channel} channel is not available on ${platform}.`);
229223
}
230224
return dir;
231225
}

tests/browser.test.ts

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ describe('ensureBrowserConnected Edge auto-connect', () => {
184184
return; // Edge not installed — skip
185185
}
186186

187-
const folderPath = path.join(os.tmpdir(), `edge-autoconnect-${crypto.randomUUID()}`);
187+
const folderPath = path.join(
188+
os.tmpdir(),
189+
`edge-autoconnect-${crypto.randomUUID()}`,
190+
);
188191
let browser;
189192
try {
190193
browser = await launch({
@@ -240,8 +243,11 @@ describe('ensureBrowserConnected Edge auto-connect', () => {
240243
});
241244

242245
it('uses Edge-specific error message on connection failure', async () => {
243-
const fakePath = path.join(os.tmpdir(), `edge-no-exist-${crypto.randomUUID()}`);
244-
await fs.promises.mkdir(fakePath, { recursive: true });
246+
const fakePath = path.join(
247+
os.tmpdir(),
248+
`edge-no-exist-${crypto.randomUUID()}`,
249+
);
250+
await fs.promises.mkdir(fakePath, {recursive: true});
245251
try {
246252
await ensureBrowserConnected({
247253
userDataDir: fakePath,
@@ -250,16 +256,25 @@ describe('ensureBrowserConnected Edge auto-connect', () => {
250256
});
251257
assert.fail('should have thrown');
252258
} catch (err) {
253-
assert.ok(err.message.includes('Edge'), `Error should mention Edge: ${err.message}`);
254-
assert.ok(err.message.includes('edge://inspect'), `Error should mention edge://inspect: ${err.message}`);
259+
assert.ok(
260+
err.message.includes('Edge'),
261+
`Error should mention Edge: ${err.message}`,
262+
);
263+
assert.ok(
264+
err.message.includes('edge://inspect'),
265+
`Error should mention edge://inspect: ${err.message}`,
266+
);
255267
} finally {
256-
await fs.promises.rm(fakePath, { recursive: true, force: true });
268+
await fs.promises.rm(fakePath, {recursive: true, force: true});
257269
}
258270
});
259271

260272
it('uses Chrome-specific error message on connection failure', async () => {
261-
const fakePath = path.join(os.tmpdir(), `chrome-no-exist-${crypto.randomUUID()}`);
262-
await fs.promises.mkdir(fakePath, { recursive: true });
273+
const fakePath = path.join(
274+
os.tmpdir(),
275+
`chrome-no-exist-${crypto.randomUUID()}`,
276+
);
277+
await fs.promises.mkdir(fakePath, {recursive: true});
263278
try {
264279
await ensureBrowserConnected({
265280
userDataDir: fakePath,
@@ -268,10 +283,16 @@ describe('ensureBrowserConnected Edge auto-connect', () => {
268283
});
269284
assert.fail('should have thrown');
270285
} catch (err) {
271-
assert.ok(err.message.includes('Chrome'), `Error should mention Chrome: ${err.message}`);
272-
assert.ok(err.message.includes('chrome://inspect'), `Error should mention chrome://inspect: ${err.message}`);
286+
assert.ok(
287+
err.message.includes('Chrome'),
288+
`Error should mention Chrome: ${err.message}`,
289+
);
290+
assert.ok(
291+
err.message.includes('chrome://inspect'),
292+
`Error should mention chrome://inspect: ${err.message}`,
293+
);
273294
} finally {
274-
await fs.promises.rm(fakePath, { recursive: true, force: true });
295+
await fs.promises.rm(fakePath, {recursive: true, force: true});
275296
}
276297
});
277298
});
@@ -285,7 +306,10 @@ describe('launch Edge executable resolution', () => {
285306
}
286307

287308
const tmpDir = os.tmpdir();
288-
const folderPath = path.join(tmpDir, `edge-launch-test-${crypto.randomUUID()}`);
309+
const folderPath = path.join(
310+
tmpDir,
311+
`edge-launch-test-${crypto.randomUUID()}`,
312+
);
289313
let browser;
290314
try {
291315
browser = await launch({
@@ -314,7 +338,10 @@ describe('launch Edge executable resolution', () => {
314338
}
315339

316340
const tmpDir = os.tmpdir();
317-
const folderPath = path.join(tmpDir, `edge-beta-launch-${crypto.randomUUID()}`);
341+
const folderPath = path.join(
342+
tmpDir,
343+
`edge-beta-launch-${crypto.randomUUID()}`,
344+
);
318345
let browser;
319346
try {
320347
browser = await launch({
@@ -344,7 +371,10 @@ describe('launch Edge executable resolution', () => {
344371
}
345372

346373
const tmpDir = os.tmpdir();
347-
const folderPath = path.join(tmpDir, `edge-dev-launch-${crypto.randomUUID()}`);
374+
const folderPath = path.join(
375+
tmpDir,
376+
`edge-dev-launch-${crypto.randomUUID()}`,
377+
);
348378
let browser;
349379
try {
350380
browser = await launch({
@@ -368,18 +398,27 @@ describe('launch Edge executable resolution', () => {
368398

369399
it('creates edge-profile directory prefix for Edge', async () => {
370400
const tmpDir = os.tmpdir();
371-
const basePath = path.join(tmpDir, `edge-profile-test-${crypto.randomUUID()}`);
372-
await fs.promises.mkdir(basePath, { recursive: true });
401+
const basePath = path.join(
402+
tmpDir,
403+
`edge-profile-test-${crypto.randomUUID()}`,
404+
);
405+
await fs.promises.mkdir(basePath, {recursive: true});
373406

374407
try {
375408
resolveEdgeExecutablePath('stable');
376409
} catch {
377-
await fs.promises.rm(basePath, { recursive: true, force: true });
410+
await fs.promises.rm(basePath, {recursive: true, force: true});
378411
return; // Edge not installed — skip
379412
}
380413

381-
const cliCacheDir = path.join(os.homedir(), '.cache', 'chrome-devtools-mcp-cli');
382-
const entriesBefore = await fs.promises.readdir(cliCacheDir).catch(() => [] as string[]);
414+
const cliCacheDir = path.join(
415+
os.homedir(),
416+
'.cache',
417+
'chrome-devtools-mcp-cli',
418+
);
419+
const entriesBefore = await fs.promises
420+
.readdir(cliCacheDir)
421+
.catch(() => [] as string[]);
383422

384423
const browser = await launch({
385424
headless: true,
@@ -398,14 +437,19 @@ describe('launch Edge executable resolution', () => {
398437
} finally {
399438
await browser.close();
400439
// Clean up any new edge-profile dirs created by this test
401-
const entriesAfter = await fs.promises.readdir(cliCacheDir).catch(() => [] as string[]);
440+
const entriesAfter = await fs.promises
441+
.readdir(cliCacheDir)
442+
.catch(() => [] as string[]);
402443
const newEntries = entriesAfter.filter(
403444
e => e.startsWith('edge-profile') && !entriesBefore.includes(e),
404445
);
405446
for (const entry of newEntries) {
406-
await fs.promises.rm(path.join(cliCacheDir, entry), { recursive: true, force: true });
447+
await fs.promises.rm(path.join(cliCacheDir, entry), {
448+
recursive: true,
449+
force: true,
450+
});
407451
}
408-
await fs.promises.rm(basePath, { recursive: true, force: true });
452+
await fs.promises.rm(basePath, {recursive: true, force: true});
409453
}
410454
});
411455

@@ -414,12 +458,12 @@ describe('launch Edge executable resolution', () => {
414458
// The launch function uses `${browserPrefix}-profile-${channel}` for non-stable
415459
const browserPrefix = 'edge';
416460
const cases = [
417-
{ channel: 'stable', expected: 'edge-profile' },
418-
{ channel: 'beta', expected: 'edge-profile-beta' },
419-
{ channel: 'dev', expected: 'edge-profile-dev' },
420-
{ channel: 'canary', expected: 'edge-profile-canary' },
461+
{channel: 'stable', expected: 'edge-profile'},
462+
{channel: 'beta', expected: 'edge-profile-beta'},
463+
{channel: 'dev', expected: 'edge-profile-dev'},
464+
{channel: 'canary', expected: 'edge-profile-canary'},
421465
];
422-
for (const { channel, expected } of cases) {
466+
for (const {channel, expected} of cases) {
423467
const profileDirName =
424468
channel && channel !== 'stable'
425469
? `${browserPrefix}-profile-${channel}`
@@ -428,5 +472,3 @@ describe('launch Edge executable resolution', () => {
428472
}
429473
});
430474
});
431-
432-

0 commit comments

Comments
 (0)