chrome-devtools-mcp 0.20.1 → 0.20.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 CHANGED
@@ -156,6 +156,9 @@ Then, install the plugin:
156
156
 
157
157
  Restart Claude Code to have the MCP server and skills load (check with `/skills`).
158
158
 
159
+ > [!TIP]
160
+ > If the plugin installation fails with a `Failed to clone repository` error (e.g., HTTPS connectivity issues behind a corporate firewall), see the [troubleshooting guide](./docs/troubleshooting.md#claude-code-plugin-installation-fails-with-failed-to-clone-repository) for workarounds, or use the CLI installation method above instead.
161
+
159
162
  </details>
160
163
 
161
164
  <details>
@@ -6,6 +6,52 @@
6
6
  import { PuppeteerDevToolsConnection } from './DevToolsConnectionAdapter.js';
7
7
  import { Mutex } from './Mutex.js';
8
8
  import { DevTools } from './third_party/index.js';
9
+ export function extractUrlLikeFromDevToolsTitle(title) {
10
+ const match = title.match(new RegExp(`DevTools - (.*)`));
11
+ return match?.[1] ?? undefined;
12
+ }
13
+ export function urlsEqual(url1, url2) {
14
+ const normalizedUrl1 = normalizeUrl(url1);
15
+ const normalizedUrl2 = normalizeUrl(url2);
16
+ return normalizedUrl1 === normalizedUrl2;
17
+ }
18
+ /**
19
+ * For the sake of the MCP server, when we determine if two URLs are equal we
20
+ * remove some parts:
21
+ *
22
+ * 1. We do not care about the protocol.
23
+ * 2. We do not care about trailing slashes.
24
+ * 3. We do not care about "www".
25
+ * 4. We ignore the hash parts.
26
+ *
27
+ * For example, if the user types "record a trace on foo.com", we would want to
28
+ * match a tab in the connected Chrome instance that is showing "www.foo.com/"
29
+ */
30
+ function normalizeUrl(url) {
31
+ let result = url.trim();
32
+ // Remove protocols
33
+ if (result.startsWith('https://')) {
34
+ result = result.slice(8);
35
+ }
36
+ else if (result.startsWith('http://')) {
37
+ result = result.slice(7);
38
+ }
39
+ // Remove 'www.'. This ensures that we find the right URL regardless of if the user adds `www` or not.
40
+ if (result.startsWith('www.')) {
41
+ result = result.slice(4);
42
+ }
43
+ // We use target URLs to locate DevTools but those often do
44
+ // no include hash.
45
+ const hashIdx = result.lastIndexOf('#');
46
+ if (hashIdx !== -1) {
47
+ result = result.slice(0, hashIdx);
48
+ }
49
+ // Remove trailing slash
50
+ if (result.endsWith('/')) {
51
+ result = result.slice(0, -1);
52
+ }
53
+ return result;
54
+ }
9
55
  /**
10
56
  * A mock implementation of an issues manager that only implements the methods
11
57
  * that are actually used by the IssuesAggregator
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import fs from 'node:fs/promises';
7
7
  import path from 'node:path';
8
- import { UniverseManager } from './DevtoolsUtils.js';
8
+ import { extractUrlLikeFromDevToolsTitle, UniverseManager, urlsEqual, } from './DevtoolsUtils.js';
9
9
  import { McpPage } from './McpPage.js';
10
10
  import { NetworkCollector, ConsoleCollector } from './PageCollector.js';
11
11
  import { Locator } from './third_party/index.js';
@@ -467,18 +467,38 @@ export class McpContext {
467
467
  async detectOpenDevToolsWindows() {
468
468
  this.logger('Detecting open DevTools windows');
469
469
  const { pages } = await this.#getAllPages();
470
- await Promise.all(pages.map(async (page) => {
471
- const mcpPage = this.#mcpPages.get(page);
472
- if (!mcpPage) {
473
- return;
474
- }
475
- if (await page.hasDevTools()) {
476
- mcpPage.devToolsPage = await page.openDevTools();
477
- }
478
- else {
479
- mcpPage.devToolsPage = undefined;
470
+ // Clear all devToolsPage references before re-detecting.
471
+ for (const mcpPage of this.#mcpPages.values()) {
472
+ mcpPage.devToolsPage = undefined;
473
+ }
474
+ for (const devToolsPage of pages) {
475
+ if (devToolsPage.url().startsWith('devtools://')) {
476
+ try {
477
+ this.logger('Calling getTargetInfo for ' + devToolsPage.url());
478
+ const data = await devToolsPage
479
+ // @ts-expect-error no types for _client().
480
+ ._client()
481
+ .send('Target.getTargetInfo');
482
+ const devtoolsPageTitle = data.targetInfo.title;
483
+ const urlLike = extractUrlLikeFromDevToolsTitle(devtoolsPageTitle);
484
+ if (!urlLike) {
485
+ continue;
486
+ }
487
+ // TODO: lookup without a loop.
488
+ for (const page of this.#pages) {
489
+ if (urlsEqual(page.url(), urlLike)) {
490
+ const mcpPage = this.#mcpPages.get(page);
491
+ if (mcpPage) {
492
+ mcpPage.devToolsPage = devToolsPage;
493
+ }
494
+ }
495
+ }
496
+ }
497
+ catch (error) {
498
+ this.logger('Issue occurred while trying to find DevTools', error);
499
+ }
480
500
  }
481
- }));
501
+ }
482
502
  }
483
503
  getExtensionServiceWorkers() {
484
504
  return this.#extensionServiceWorkers;
@@ -5,5 +5,5 @@
5
5
  */
6
6
  // If moved update release-please config
7
7
  // x-release-please-start-version
8
- export const VERSION = '0.20.1';
8
+ export const VERSION = '0.20.2';
9
9
  // x-release-please-end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chrome-devtools-mcp",
3
- "version": "0.20.1",
3
+ "version": "0.20.2",
4
4
  "description": "MCP server for Chrome DevTools",
5
5
  "type": "module",
6
6
  "bin": {