chrome-devtools-mcp 0.10.2 → 0.12.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.
Files changed (121) hide show
  1. package/README.md +73 -10
  2. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/common.js +1 -3
  3. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/AidaClient.js +1 -1
  4. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/InspectorFrontendHost.js +31 -449
  5. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/InspectorFrontendHostStub.js +430 -0
  6. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/ResourceLoader.js +10 -22
  7. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/UserMetrics.js +2 -5
  8. package/build/node_modules/chrome-devtools-frontend/front_end/core/i18n/collect-ui-strings.js +1 -1
  9. package/build/node_modules/chrome-devtools-frontend/front_end/core/i18n/generate-locales-js.js +1 -1
  10. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/HostRuntime.js +19 -0
  11. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/StringUtilities.js +1 -1
  12. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/api/HostRuntime.js +4 -0
  13. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/api/api.js +5 -0
  14. package/build/node_modules/chrome-devtools-frontend/front_end/core/{common/Worker.js → platform/browser/HostRuntime.js} +18 -7
  15. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/browser/browser.js +5 -0
  16. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/node/HostRuntime.js +72 -0
  17. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/node/node.js +5 -0
  18. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/platform.js +2 -2
  19. package/build/node_modules/chrome-devtools-frontend/front_end/core/root/DevToolsContext.js +4 -0
  20. package/build/node_modules/chrome-devtools-frontend/front_end/core/root/Runtime.js +7 -0
  21. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/AnimationModel.js +1 -1
  22. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSMatchedStyles.js +2 -2
  23. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSMetadata.js +17 -5
  24. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSModel.js +3 -3
  25. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSProperty.js +1 -1
  26. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSPropertyParserMatchers.js +10 -10
  27. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ConsoleModel.js +1 -1
  28. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/Cookie.js +1 -1
  29. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/DOMModel.js +5 -2
  30. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/DebuggerModel.js +1 -1
  31. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js +46 -34
  32. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkRequest.js +3 -0
  33. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/PageResourceLoader.js +43 -33
  34. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/PreloadingModel.js +1 -1
  35. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/RemoteObject.js +1 -1
  36. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ResourceTreeModel.js +1 -1
  37. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/Script.js +26 -1
  38. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMap.js +4 -0
  39. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMapCache.js +16 -0
  40. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMapManager.js +11 -5
  41. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMapScopesInfo.js +129 -20
  42. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/Target.js +4 -13
  43. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/TargetManager.js +35 -4
  44. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/sdk-meta.js +72 -0
  45. package/build/node_modules/chrome-devtools-frontend/front_end/foundation/Universe.js +5 -1
  46. package/build/node_modules/chrome-devtools-frontend/front_end/generated/Deprecation.js +48 -4
  47. package/build/node_modules/chrome-devtools-frontend/front_end/generated/InspectorBackendCommands.js +45 -42
  48. package/build/node_modules/chrome-devtools-frontend/front_end/generated/SupportedCSSProperties.js +56 -77
  49. package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.js +21 -6
  50. package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AICallTree.js +9 -3
  51. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/CSSWorkspaceBinding.js +4 -3
  52. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/CompilerScriptMapping.js +34 -0
  53. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/DebuggerWorkspaceBinding.js +15 -0
  54. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/ResourceMapping.js +59 -0
  55. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/ResourceScriptMapping.js +38 -0
  56. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/SASSSourceMapping.js +5 -4
  57. package/build/node_modules/chrome-devtools-frontend/front_end/models/cpu_profile/CPUProfileDataModel.js +9 -7
  58. package/build/node_modules/chrome-devtools-frontend/front_end/models/crux-manager/CrUXManager.js +5 -3
  59. package/build/node_modules/chrome-devtools-frontend/front_end/models/formatter/FormatterWorkerPool.js +2 -2
  60. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/AttributionReportingIssue.js +5 -6
  61. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/BounceTrackingIssue.js +3 -11
  62. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/ClientHintIssue.js +4 -9
  63. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/ContentSecurityPolicyIssue.js +4 -9
  64. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/ContrastCheckTrigger.js +1 -1
  65. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/CookieDeprecationMetadataIssue.js +5 -11
  66. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/CookieIssue.js +26 -25
  67. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/CorsIssue.js +7 -14
  68. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/CrossOriginEmbedderPolicyIssue.js +4 -6
  69. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/DeprecationIssue.js +6 -11
  70. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/ElementAccessibilityIssue.js +6 -11
  71. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/FederatedAuthRequestIssue.js +3 -8
  72. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/FederatedAuthUserInfoRequestIssue.js +3 -8
  73. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/GenericIssue.js +36 -21
  74. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/HeavyAdIssue.js +3 -8
  75. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/Issue.js +6 -1
  76. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/IssueAggregator.js +6 -1
  77. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/LowTextContrastIssue.js +2 -7
  78. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/MixedContentIssue.js +6 -10
  79. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/PartitioningBlobURLIssue.js +3 -8
  80. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/PropertyRuleIssue.js +5 -10
  81. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/QuirksModeIssue.js +2 -7
  82. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/SRIMessageSignatureIssue.js +6 -10
  83. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/SharedArrayBufferIssue.js +3 -8
  84. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/SharedDictionaryIssue.js +5 -10
  85. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/StylesheetLoadingIssue.js +7 -11
  86. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/UnencodedDigestIssue.js +1 -6
  87. package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/descriptions/genericNavigationEntryMarkedSkippable.md +7 -0
  88. package/build/node_modules/chrome-devtools-frontend/front_end/models/source_map_scopes/FunctionCodeResolver.js +192 -0
  89. package/build/node_modules/chrome-devtools-frontend/front_end/models/source_map_scopes/source_map_scopes.js +2 -1
  90. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/SamplesHandler.js +3 -0
  91. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/helpers/Trace.js +10 -0
  92. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace_source_maps_resolver/SourceMapsResolver.js +23 -0
  93. package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/IgnoreListManager.js +1 -1
  94. package/build/node_modules/chrome-devtools-frontend/front_end/models/workspace/UISourceCode.js +38 -0
  95. package/build/node_modules/chrome-devtools-frontend/mcp/HostBindings.js +222 -0
  96. package/build/node_modules/chrome-devtools-frontend/mcp/mcp.js +15 -1
  97. package/build/src/DevToolsConnectionAdapter.js +56 -19
  98. package/build/src/DevtoolsUtils.js +143 -1
  99. package/build/src/McpContext.js +33 -11
  100. package/build/src/McpResponse.js +18 -26
  101. package/build/src/PageCollector.js +4 -11
  102. package/build/src/browser.js +52 -2
  103. package/build/src/cli.js +31 -3
  104. package/build/src/formatters/consoleFormatter.js +81 -3
  105. package/build/src/formatters/snapshotFormatter.js +18 -4
  106. package/build/src/issue-descriptions.js +4 -0
  107. package/build/src/main.js +27 -50
  108. package/build/src/third_party/THIRD_PARTY_NOTICES +27 -27
  109. package/build/src/third_party/index.js +21898 -15109
  110. package/build/src/tools/console.js +0 -4
  111. package/build/src/tools/emulation.js +29 -6
  112. package/build/src/tools/screenshot.js +4 -2
  113. package/build/src/tools/snapshot.js +1 -1
  114. package/build/src/tools/tools.js +29 -0
  115. package/build/src/utils/keyboard.js +5 -0
  116. package/package.json +7 -7
  117. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Linkifier.js +0 -34
  118. package/build/node_modules/chrome-devtools-frontend/front_end/core/platform/DOMUtilities.js +0 -122
  119. package/build/src/features.js +0 -14
  120. /package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/descriptions/{genericFormAriaLabelledByToNonExistingId.md → genericFormAriaLabelledByToNonExistingIdError.md} +0 -0
  121. /package/build/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/descriptions/{genericFormLabelHasNeitherForNorNestedInput.md → genericFormLabelHasNeitherForNorNestedInputError.md} +0 -0
package/README.md CHANGED
@@ -7,7 +7,7 @@ control and inspect a live Chrome browser. It acts as a Model-Context-Protocol
7
7
  (MCP) server, giving your AI coding assistant access to the full power of
8
8
  Chrome DevTools for reliable automation, in-depth debugging, and performance analysis.
9
9
 
10
- ## [Tool reference](./docs/tool-reference.md) | [Changelog](./CHANGELOG.md) | [Contributing](./CONTRIBUTING.md) | [Troubleshooting](./docs/troubleshooting.md)
10
+ ## [Tool reference](./docs/tool-reference.md) | [Changelog](./CHANGELOG.md) | [Contributing](./CONTRIBUTING.md) | [Troubleshooting](./docs/troubleshooting.md) | [Design Principles](./docs/design-principles.md)
11
11
 
12
12
  ## Key features
13
13
 
@@ -63,6 +63,32 @@ amp mcp add chrome-devtools -- npx chrome-devtools-mcp@latest
63
63
 
64
64
  </details>
65
65
 
66
+ <details>
67
+ <summary>Antigravity</summary>
68
+
69
+ To use the Chrome DevTools MCP server follow the instructions from <a href="https://antigravity.google/docs/mcp">Antigravity's docs<a/> to install a custom MCP server. Add the following config to the MCP servers config:
70
+
71
+ ```bash
72
+ {
73
+ "mcpServers": {
74
+ "chrome-devtools": {
75
+ "command": "npx",
76
+ "args": [
77
+ "chrome-devtools-mcp@latest",
78
+ "--browser-url=http://127.0.0.1:9222",
79
+ "-y"
80
+ ]
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ This will make the Chrome DevTools MCP server automatically connect to the browser that Antigravity is using. If you are not using port 9222, make sure to adjust accordingly.
87
+
88
+ Chrome DevTools MCP will not start the browser instance automatically using this approach as as the Chrome DevTools MCP server runs in Antigravity's built-in browser. If the browser is not already running, you have to start it first by clicking the Chrome icon at the top right corner.
89
+
90
+ </details>
91
+
66
92
  <details>
67
93
  <summary>Claude Code</summary>
68
94
  Use the Claude Code CLI to add the Chrome DevTools MCP server (<a href="https://docs.anthropic.com/en/docs/claude-code/mcp">guide</a>):
@@ -131,12 +157,22 @@ Configure the following fields and press `CTRL+S` to save the configuration:
131
157
 
132
158
  <details>
133
159
  <summary>Copilot / VS Code</summary>
134
- Follow the MCP install <a href="https://code.visualstudio.com/docs/copilot/chat/mcp-servers#_add-an-mcp-server">guide</a>,
135
- with the standard config from above. You can also install the Chrome DevTools MCP server using the VS Code CLI:
136
-
137
- ```bash
138
- code --add-mcp '{"name":"chrome-devtools","command":"npx","args":["chrome-devtools-mcp@latest"]}'
139
- ```
160
+
161
+ **Click the button to install:**
162
+
163
+ [<img src="https://mcpbadge.dev/badge-install-in-vs-code-stable-dark" alt="Install in VS Code">](https://vscode.dev/redirect/mcp/install?name=io.github.ChromeDevTools%2Fchrome-devtools-mcp&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22chrome-devtools-mcp%22%5D%2C%22env%22%3A%7B%7D%7D)
164
+
165
+ [<img src="https://mcpbadge.dev/badge-install-in-vs-code-insiders-dark" alt="Install in VS Code Insiders">](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522io.github.ChromeDevTools%252Fchrome-devtools-mcp%2522%252C%2522config%2522%253A%257B%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522-y%2522%252C%2522chrome-devtools-mcp%2522%255D%252C%2522env%2522%253A%257B%257D%257D%257D)
166
+
167
+ **Or install manually:**
168
+
169
+ Follow the MCP install <a href="https://code.visualstudio.com/docs/copilot/chat/mcp-servers#_add-an-mcp-server">guide</a>,
170
+ with the standard config from above. You can also install the Chrome DevTools MCP server using the VS Code CLI:
171
+
172
+ ```bash
173
+ code --add-mcp '{"name":"io.github.ChromeDevTools/chrome-devtools-mcp","command":"npx","args":["-y","chrome-devtools-mcp"],"env":{}}'
174
+ ```
175
+
140
176
  </details>
141
177
 
142
178
  <details>
@@ -214,6 +250,25 @@ Alternatively, follow the <a href="https://docs.qoder.com/user-guide/chat/model-
214
250
 
215
251
  </details>
216
252
 
253
+ <details>
254
+ <summary>Qoder CLI</summary>
255
+
256
+ Install the Chrome DevTools MCP server using the Qoder CLI (<a href="https://docs.qoder.com/cli/using-cli#mcp-servsers">guide</a>):
257
+
258
+ **Project wide:**
259
+
260
+ ```bash
261
+ qodercli mcp add chrome-devtools -- npx chrome-devtools-mcp@latest
262
+ ```
263
+
264
+ **Globally:**
265
+
266
+ ```bash
267
+ qodercli mcp add -s user chrome-devtools -- npx chrome-devtools-mcp@latest
268
+ ```
269
+
270
+ </details>
271
+
217
272
  <details>
218
273
  <summary>Visual Studio</summary>
219
274
 
@@ -295,8 +350,13 @@ The Chrome DevTools MCP server supports the following configuration option:
295
350
 
296
351
  <!-- BEGIN AUTO GENERATED OPTIONS -->
297
352
 
353
+ - **`--autoConnect`**
354
+ If specified, automatically connects to a browser (Chrome 145+) running in the user data directory identified by the channel param. Requires remote debugging being enabled in Chrome here: chrome://inspect/#remote-debugging.
355
+ - **Type:** boolean
356
+ - **Default:** `false`
357
+
298
358
  - **`--browserUrl`, `-u`**
299
- Connect to a running Chrome instance using port forwarding. For more details see: https://developer.chrome.com/docs/devtools/remote-debugging/local-server.
359
+ Connect to a running, debuggable Chrome instance (e.g. `http://127.0.0.1:9222`). For more details see: https://github.com/ChromeDevTools/chrome-devtools-mcp#connecting-to-a-running-chrome-instance.
300
360
  - **Type:** string
301
361
 
302
362
  - **`--wsEndpoint`, `-w`**
@@ -317,9 +377,12 @@ The Chrome DevTools MCP server supports the following configuration option:
317
377
  - **Type:** string
318
378
 
319
379
  - **`--isolated`**
320
- If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed.
380
+ If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to false.
321
381
  - **Type:** boolean
322
- - **Default:** `false`
382
+
383
+ - **`--userDataDir`**
384
+ Path to the user data directory for Chrome. Default is $HOME/.cache/chrome-devtools-mcp/chrome-profile$CHANNEL_SUFFIX_IF_NON_STABLE
385
+ - **Type:** string
323
386
 
324
387
  - **`--channel`**
325
388
  Specify a different Chrome channel that should be used. The default is the stable channel version.
@@ -14,7 +14,6 @@ import * as EventTarget from './EventTarget.js';
14
14
  import * as Gzip from './Gzip.js';
15
15
  import * as JavaScriptMetaData from './JavaScriptMetaData.js';
16
16
  import * as Lazy from './Lazy.js';
17
- import * as Linkifier from './Linkifier.js';
18
17
  import * as MapWithDefault from './MapWithDefault.js';
19
18
  import * as Mutex from './Mutex.js';
20
19
  import * as ObjectWrapper from './Object.js';
@@ -33,11 +32,10 @@ import * as StringOutputStream from './StringOutputStream.js';
33
32
  import * as TextDictionary from './TextDictionary.js';
34
33
  import * as Throttler from './Throttler.js';
35
34
  import * as Trie from './Trie.js';
36
- import * as Worker from './Worker.js';
37
35
  /*
38
36
  * This is re-exported here because we moved UIString into platform from
39
37
  * common and wanted to avoid a huge rename of imports. A future CL will
40
38
  * update all references to `Common.UIString` to `Platform.UIString`.
41
39
  */
42
40
  export { UIString } from '../platform/platform.js';
43
- export { App, AppProvider, Base64, CharacterIdMap, Color, ColorConverter, ColorUtils, Console, Debouncer, EventTarget, Gzip, JavaScriptMetaData, Lazy, Linkifier, MapWithDefault, Mutex, ObjectWrapper, ParsedURL, Progress, ResolverBase, ResourceType, ReturnToPanel, Revealer, Runnable, SegmentedRange, SettingRegistration, Settings, SimpleHistoryManager, StringOutputStream, TextDictionary, Throttler, Trie, Worker, };
41
+ export { App, AppProvider, Base64, CharacterIdMap, Color, ColorConverter, ColorUtils, Console, Debouncer, EventTarget, Gzip, JavaScriptMetaData, Lazy, MapWithDefault, Mutex, ObjectWrapper, ParsedURL, Progress, ResolverBase, ResourceType, ReturnToPanel, Revealer, Runnable, SegmentedRange, SettingRegistration, Settings, SimpleHistoryManager, StringOutputStream, TextDictionary, Throttler, Trie, };
@@ -389,7 +389,7 @@ export function convertToUserTierEnum(userTier) {
389
389
  return UserTier.PUBLIC;
390
390
  }
391
391
  }
392
- return UserTier.BETA;
392
+ return UserTier.PUBLIC;
393
393
  }
394
394
  let hostConfigTrackerInstance;
395
395
  export class HostConfigTracker extends Common.ObjectWrapper.ObjectWrapper {
@@ -2,436 +2,12 @@
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
4
  import * as Common from '../common/common.js';
5
- import * as i18n from '../i18n/i18n.js';
6
- import * as Platform from '../platform/platform.js';
7
5
  import * as Root from '../root/root.js';
8
- import { EventDescriptors, Events, } from './InspectorFrontendHostAPI.js';
6
+ import { EventDescriptors, } from './InspectorFrontendHostAPI.js';
7
+ import { InspectorFrontendHostStub } from './InspectorFrontendHostStub.js';
9
8
  import { streamWrite as resourceLoaderStreamWrite } from './ResourceLoader.js';
10
- const UIStrings = {
11
- /**
12
- * @description Document title in Inspector Frontend Host of the DevTools window
13
- * @example {example.com} PH1
14
- */
15
- devtoolsS: 'DevTools - {PH1}',
16
- };
17
- const str_ = i18n.i18n.registerUIStrings('core/host/InspectorFrontendHost.ts', UIStrings);
18
- const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
19
- const MAX_RECORDED_HISTOGRAMS_SIZE = 100;
20
- const OVERRIDES_FILE_SYSTEM_PATH = '/overrides';
21
- /**
22
- * The `InspectorFrontendHostStub` is a stub interface used the frontend is loaded like a webpage. Examples:
23
- * - devtools://devtools/bundled/devtools_app.html
24
- * - https://chrome-devtools-frontend.appspot.com/serve_rev/@030cc140435b0152645522b9864b75cac6c0a854/worker_app.html
25
- * - http://localhost:9222/devtools/inspector.html?ws=localhost:9222/devtools/page/xTARGET_IDx
26
- *
27
- * When the frontend runs within the native embedder, then the InspectorFrontendHostAPI methods are provided
28
- * by devtools_compatibility.js. Those leverage `DevToolsAPI.sendMessageToEmbedder()` which match up with
29
- * the embedder API defined here: https://source.chromium.org/search?q=f:devtools%20f:dispatcher%20f:cc%20symbol:CreateForDevToolsFrontend&sq=&ss=chromium%2Fchromium%2Fsrc
30
- * The native implementations live in devtools_ui_bindings.cc: https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/devtools/devtools_ui_bindings.cc
31
- */
32
- export class InspectorFrontendHostStub {
33
- #urlsBeingSaved = new Map();
34
- #fileSystem = null;
35
- recordedCountHistograms = [];
36
- recordedEnumeratedHistograms = [];
37
- recordedPerformanceHistograms = [];
38
- constructor() {
39
- // Guard against errors should this file ever be imported at the top level
40
- // within a worker - in which case this constructor is run. If there's no
41
- // document, we can early exit.
42
- if (typeof document === 'undefined') {
43
- return;
44
- }
45
- function stopEventPropagation(event) {
46
- // Let browser handle Ctrl+/Ctrl- shortcuts in hosted mode.
47
- const zoomModifier = this.platform() === 'mac' ? event.metaKey : event.ctrlKey;
48
- if (zoomModifier && (event.key === '+' || event.key === '-')) {
49
- event.stopPropagation();
50
- }
51
- }
52
- document.addEventListener('keydown', event => {
53
- stopEventPropagation.call(this, (event));
54
- }, true);
55
- }
56
- platform() {
57
- const userAgent = navigator.userAgent;
58
- if (userAgent.includes('Windows NT')) {
59
- return 'windows';
60
- }
61
- if (userAgent.includes('Mac OS X')) {
62
- return 'mac';
63
- }
64
- return 'linux';
65
- }
66
- loadCompleted() {
67
- }
68
- bringToFront() {
69
- }
70
- closeWindow() {
71
- }
72
- setIsDocked(_isDocked, callback) {
73
- window.setTimeout(callback, 0);
74
- }
75
- showSurvey(_trigger, callback) {
76
- window.setTimeout(() => callback({ surveyShown: false }), 0);
77
- }
78
- canShowSurvey(_trigger, callback) {
79
- window.setTimeout(() => callback({ canShowSurvey: false }), 0);
80
- }
81
- /**
82
- * Requests inspected page to be placed atop of the inspector frontend with specified bounds.
83
- */
84
- setInspectedPageBounds(_bounds) {
85
- }
86
- inspectElementCompleted() {
87
- }
88
- setInjectedScriptForOrigin(_origin, _script) {
89
- }
90
- inspectedURLChanged(url) {
91
- document.title = i18nString(UIStrings.devtoolsS, { PH1: url.replace(/^https?:\/\//, '') });
92
- }
93
- copyText(text) {
94
- if (text === undefined || text === null) {
95
- return;
96
- }
97
- void navigator.clipboard.writeText(text);
98
- }
99
- openInNewTab(url) {
100
- if (Common.ParsedURL.schemeIs(url, 'javascript:')) {
101
- return;
102
- }
103
- window.open(url, '_blank');
104
- }
105
- openSearchResultsInNewTab(_query) {
106
- Common.Console.Console.instance().error('Search is not enabled in hosted mode. Please inspect using chrome://inspect');
107
- }
108
- showItemInFolder(_fileSystemPath) {
109
- Common.Console.Console.instance().error('Show item in folder is not enabled in hosted mode. Please inspect using chrome://inspect');
110
- }
111
- // Reminder: the methods in this class belong to InspectorFrontendHostStub and are typically not executed.
112
- // InspectorFrontendHostStub is ONLY used in the uncommon case of devtools not being embedded. For example: trace.cafe or http://localhost:9222/devtools/inspector.html?ws=localhost:9222/devtools/page/xTARGET_IDx
113
- save(url, content, _forceSaveAs, isBase64) {
114
- let buffer = this.#urlsBeingSaved.get(url)?.buffer;
115
- if (!buffer) {
116
- buffer = [];
117
- this.#urlsBeingSaved.set(url, { isBase64, buffer });
118
- }
119
- buffer.push(content);
120
- this.events.dispatchEventToListeners(Events.SavedURL, { url, fileSystemPath: url });
121
- }
122
- append(url, content) {
123
- const buffer = this.#urlsBeingSaved.get(url)?.buffer;
124
- if (buffer) {
125
- buffer.push(content);
126
- this.events.dispatchEventToListeners(Events.AppendedToURL, url);
127
- }
128
- }
129
- close(url) {
130
- const { isBase64, buffer } = this.#urlsBeingSaved.get(url) || { isBase64: false, buffer: [] };
131
- this.#urlsBeingSaved.delete(url);
132
- let fileName = '';
133
- if (url) {
134
- try {
135
- const trimmed = Platform.StringUtilities.trimURL(url);
136
- fileName = Platform.StringUtilities.removeURLFragment(trimmed);
137
- }
138
- catch {
139
- // If url is not a valid URL, it is probably a filename.
140
- fileName = url;
141
- }
142
- }
143
- /* eslint-disable-next-line @devtools/no-imperative-dom-api */
144
- const link = document.createElement('a');
145
- link.download = fileName;
146
- let blob;
147
- if (isBase64) {
148
- const bytes = Common.Base64.decode(buffer.join(''));
149
- blob = new Blob([bytes], { type: 'application/gzip' });
150
- }
151
- else {
152
- blob = new Blob(buffer, { type: 'text/plain' });
153
- }
154
- const blobUrl = URL.createObjectURL(blob);
155
- link.href = blobUrl;
156
- link.click();
157
- URL.revokeObjectURL(blobUrl);
158
- }
159
- sendMessageToBackend(_message) {
160
- }
161
- recordCountHistogram(histogramName, sample, min, exclusiveMax, bucketSize) {
162
- if (this.recordedCountHistograms.length >= MAX_RECORDED_HISTOGRAMS_SIZE) {
163
- this.recordedCountHistograms.shift();
164
- }
165
- this.recordedCountHistograms.push({ histogramName, sample, min, exclusiveMax, bucketSize });
166
- }
167
- recordEnumeratedHistogram(actionName, actionCode, _bucketSize) {
168
- if (this.recordedEnumeratedHistograms.length >= MAX_RECORDED_HISTOGRAMS_SIZE) {
169
- this.recordedEnumeratedHistograms.shift();
170
- }
171
- this.recordedEnumeratedHistograms.push({ actionName, actionCode });
172
- }
173
- recordPerformanceHistogram(histogramName, duration) {
174
- if (this.recordedPerformanceHistograms.length >= MAX_RECORDED_HISTOGRAMS_SIZE) {
175
- this.recordedPerformanceHistograms.shift();
176
- }
177
- this.recordedPerformanceHistograms.push({ histogramName, duration });
178
- }
179
- recordUserMetricsAction(_umaName) {
180
- }
181
- recordNewBadgeUsage(_featureName) {
182
- }
183
- connectAutomaticFileSystem(_fileSystemPath, _fileSystemUUID, _addIfMissing, callback) {
184
- queueMicrotask(() => callback({ success: false }));
185
- }
186
- disconnectAutomaticFileSystem(_fileSystemPath) {
187
- }
188
- requestFileSystems() {
189
- this.events.dispatchEventToListeners(Events.FileSystemsLoaded, []);
190
- }
191
- addFileSystem(_type) {
192
- const onFileSystem = (fs) => {
193
- this.#fileSystem = fs;
194
- const fileSystem = {
195
- fileSystemName: 'sandboxedRequestedFileSystem',
196
- fileSystemPath: OVERRIDES_FILE_SYSTEM_PATH,
197
- rootURL: 'filesystem:devtools://devtools/isolated/',
198
- type: 'overrides',
199
- };
200
- this.events.dispatchEventToListeners(Events.FileSystemAdded, { fileSystem });
201
- };
202
- window.webkitRequestFileSystem(window.TEMPORARY, 1024 * 1024, onFileSystem);
203
- }
204
- removeFileSystem(_fileSystemPath) {
205
- const removalCallback = (entries) => {
206
- entries.forEach(entry => {
207
- if (entry.isDirectory) {
208
- entry.removeRecursively(() => { });
209
- }
210
- else if (entry.isFile) {
211
- entry.remove(() => { });
212
- }
213
- });
214
- };
215
- if (this.#fileSystem) {
216
- this.#fileSystem.root.createReader().readEntries(removalCallback);
217
- }
218
- this.#fileSystem = null;
219
- this.events.dispatchEventToListeners(Events.FileSystemRemoved, OVERRIDES_FILE_SYSTEM_PATH);
220
- }
221
- isolatedFileSystem(_fileSystemId, _registeredName) {
222
- return this.#fileSystem;
223
- }
224
- loadNetworkResource(url, _headers, streamId, callback) {
225
- fetch(url)
226
- .then(async (result) => {
227
- const respBuffer = await result.arrayBuffer();
228
- const text = await Common.Gzip.arrayBufferToString(respBuffer);
229
- return text;
230
- })
231
- .then(function (text) {
232
- resourceLoaderStreamWrite(streamId, text);
233
- callback({
234
- statusCode: 200,
235
- headers: undefined,
236
- messageOverride: undefined,
237
- netError: undefined,
238
- netErrorName: undefined,
239
- urlValid: undefined,
240
- });
241
- })
242
- .catch(function () {
243
- callback({
244
- statusCode: 404,
245
- headers: undefined,
246
- messageOverride: undefined,
247
- netError: undefined,
248
- netErrorName: undefined,
249
- urlValid: undefined,
250
- });
251
- });
252
- }
253
- registerPreference(_name, _options) {
254
- }
255
- getPreferences(callback) {
256
- const prefs = {};
257
- for (const name in window.localStorage) {
258
- prefs[name] = window.localStorage[name];
259
- }
260
- callback(prefs);
261
- }
262
- getPreference(name, callback) {
263
- callback(window.localStorage[name]);
264
- }
265
- setPreference(name, value) {
266
- window.localStorage[name] = value;
267
- }
268
- removePreference(name) {
269
- delete window.localStorage[name];
270
- }
271
- clearPreferences() {
272
- window.localStorage.clear();
273
- }
274
- getSyncInformation(callback) {
275
- if ('getSyncInformationForTesting' in globalThis) {
276
- // @ts-expect-error for testing
277
- return callback(globalThis.getSyncInformationForTesting());
278
- }
279
- callback({
280
- isSyncActive: false,
281
- arePreferencesSynced: false,
282
- });
283
- }
284
- getHostConfig(callback) {
285
- // This HostConfig config is used in the hosted mode (see the
286
- // comment on top of this class). Only add non-default config params
287
- // here that you want to also apply in the hosted mode. For tests
288
- // use the hostConfigForTesting override.
289
- const hostConfigForHostedMode = {
290
- devToolsVeLogging: {
291
- enabled: true,
292
- },
293
- thirdPartyCookieControls: {
294
- thirdPartyCookieMetadataEnabled: true,
295
- thirdPartyCookieHeuristicsEnabled: true,
296
- managedBlockThirdPartyCookies: 'Unset',
297
- },
298
- devToolsFlexibleLayout: {
299
- verticalDrawerEnabled: true,
300
- },
301
- devToolsStartingStyleDebugging: {
302
- enabled: false,
303
- },
304
- };
305
- if ('hostConfigForTesting' in globalThis) {
306
- const { hostConfigForTesting } = globalThis;
307
- for (const key of Object.keys(hostConfigForTesting)) {
308
- const mergeEntry = (key) => {
309
- if (typeof hostConfigForHostedMode[key] === 'object' && typeof hostConfigForTesting[key] === 'object') {
310
- // If the config is an object, merge the settings, but preferring
311
- // the hostConfigForTesting values over the result values.
312
- hostConfigForHostedMode[key] = { ...hostConfigForHostedMode[key], ...hostConfigForTesting[key] };
313
- }
314
- else {
315
- // Override with the testing config if the value is present + not null/undefined.
316
- hostConfigForHostedMode[key] = hostConfigForTesting[key] ?? hostConfigForHostedMode[key];
317
- }
318
- };
319
- mergeEntry(key);
320
- }
321
- }
322
- callback(hostConfigForHostedMode);
323
- }
324
- upgradeDraggedFileSystemPermissions(_fileSystem) {
325
- }
326
- indexPath(_requestId, _fileSystemPath, _excludedFolders) {
327
- }
328
- stopIndexing(_requestId) {
329
- }
330
- searchInPath(_requestId, _fileSystemPath, _query) {
331
- }
332
- zoomFactor() {
333
- return 1;
334
- }
335
- zoomIn() {
336
- }
337
- zoomOut() {
338
- }
339
- resetZoom() {
340
- }
341
- setWhitelistedShortcuts(_shortcuts) {
342
- }
343
- setEyeDropperActive(_active) {
344
- }
345
- showCertificateViewer(_certChain) {
346
- }
347
- reattach(_callback) {
348
- }
349
- readyForTest() {
350
- }
351
- connectionReady() {
352
- }
353
- setOpenNewWindowForPopups(_value) {
354
- }
355
- setDevicesDiscoveryConfig(_config) {
356
- }
357
- setDevicesUpdatesEnabled(_enabled) {
358
- }
359
- openRemotePage(_browserId, _url) {
360
- }
361
- openNodeFrontend() {
362
- }
363
- showContextMenuAtPoint(_x, _y, _items, _document) {
364
- throw new Error('Soft context menu should be used');
365
- }
366
- /**
367
- * Think of **Hosted mode** as "non-embedded" mode; you can see a devtools frontend URL as the tab's URL. It's an atypical way that DevTools is run.
368
- * Whereas in **Non-hosted** (aka "embedded"), DevTools is embedded and fully dockable. It's the common way DevTools is run.
369
- *
370
- * **Hosted mode** == we're using the `InspectorFrontendHostStub`. impl. (@see `InspectorFrontendHostStub` class comment)
371
- * Whereas with **non-hosted** mode, native `DevToolsEmbedderMessageDispatcher` is used for CDP and more. `globalThis.DevToolsAPI` is present.
372
- *
373
- * Relationships to other signals:
374
- * - _Connection_: Hosted-ness does not indicate whether the frontend is _connected to a valid CDP target_.
375
- * - _Dockability_: Being _"dockable"_ (aka `canDock`) is typically aligned but technically orthogonal.
376
- * - _URL scheme_: If the main frame's URL scheme is `devtools://`, it's non-hosted.
377
- *
378
- * | Example case | Mode | Example devtools |
379
- * | :------------------------------------------ | :------------- | :---------------------------------------------------------------------------- |
380
- * | tab URL: `devtools://…` | **NOT Hosted** | `devtools://devtools/bundled/devtools_app.html?targetType=tab&...` |
381
- * | tab URL: `devtools://…?ws=…` | **NOT Hosted** | `devtools://devtools/bundled/devtools_app.html?ws=localhost:9228/...` |
382
- * | tab URL: `devtools://…` but no connection | **NOT Hosted** | `devtools://devtools/bundled/trace_app.html` |
383
- * | tab URL: `https://…` but no connection | **Hosted** | `https://chrome-devtools-frontend.appspot.com/serve_rev/@.../trace_app.html` |
384
- * | tab URL: `http://…?ws=` (connected) | **Hosted** | `http://localhost:9222/devtools/inspector.html?ws=localhost:9222/...` |
385
- */
386
- isHostedMode() {
387
- return true;
388
- }
389
- setAddExtensionCallback(_callback) {
390
- // Extensions are not supported in hosted mode.
391
- }
392
- async initialTargetId() {
393
- return null;
394
- }
395
- doAidaConversation(_request, _streamId, callback) {
396
- callback({
397
- error: 'Not implemented',
398
- });
399
- }
400
- registerAidaClientEvent(_request, callback) {
401
- callback({
402
- error: 'Not implemented',
403
- });
404
- }
405
- aidaCodeComplete(_request, callback) {
406
- callback({
407
- error: 'Not implemented',
408
- });
409
- }
410
- dispatchHttpRequest(_request, callback) {
411
- callback({ error: 'Not implemented' });
412
- }
413
- recordImpression(_event) {
414
- }
415
- recordResize(_event) {
416
- }
417
- recordClick(_event) {
418
- }
419
- recordHover(_event) {
420
- }
421
- recordDrag(_event) {
422
- }
423
- recordChange(_event) {
424
- }
425
- recordKeyDown(_event) {
426
- }
427
- recordSettingAccess(_event) {
428
- }
429
- recordFunctionCall(_event) {
430
- }
431
- }
432
- // @ts-expect-error Global injected by devtools_compatibility.js
433
9
  // eslint-disable-next-line @typescript-eslint/naming-convention
434
- export let InspectorFrontendHostInstance = globalThis.InspectorFrontendHost;
10
+ export let InspectorFrontendHostInstance;
435
11
  class InspectorFrontendAPIImpl {
436
12
  constructor() {
437
13
  for (const descriptor of EventDescriptors) {
@@ -467,33 +43,37 @@ class InspectorFrontendAPIImpl {
467
43
  resourceLoaderStreamWrite(id, chunk);
468
44
  }
469
45
  }
470
- (function () {
471
- function initializeInspectorFrontendHost() {
472
- if (!InspectorFrontendHostInstance) {
473
- // Instantiate stub for web-hosted mode if necessary.
474
- // @ts-expect-error Global injected by devtools_compatibility.js
475
- globalThis.InspectorFrontendHost = InspectorFrontendHostInstance = new InspectorFrontendHostStub();
476
- }
477
- else {
478
- // Otherwise add stubs for missing methods that are declared in the interface.
479
- const proto = InspectorFrontendHostStub.prototype;
480
- for (const name of Object.getOwnPropertyNames(proto)) {
481
- const stub = proto[name];
482
- if (typeof stub !== 'function' || InspectorFrontendHostInstance[name]) {
483
- continue;
484
- }
485
- console.error(`Incompatible embedder: method Host.InspectorFrontendHost.${name} is missing. Using stub instead.`);
486
- // @ts-expect-error Global injected by devtools_compatibility.js
487
- InspectorFrontendHostInstance[name] = stub;
46
+ /**
47
+ * Installs the provided host bindings implementation as the globally used one by DevTools.
48
+ *
49
+ * - In non-hosted mode this is provided by `devtools_compatibility.js`.
50
+ * - In hosted mode this tends to be the {@link InspectorFrontendHostStub}.
51
+ * - For the MCP server this is a custom node.js specific implementation.
52
+ *
53
+ * Note that missing methods will be copied over from the stub.
54
+ */
55
+ export function installInspectorFrontendHost(instance) {
56
+ globalThis.InspectorFrontendHost = InspectorFrontendHostInstance = instance;
57
+ if (!(instance instanceof InspectorFrontendHostStub)) {
58
+ // Add stubs for missing methods.
59
+ const proto = InspectorFrontendHostStub.prototype;
60
+ for (const name of Object.getOwnPropertyNames(proto)) {
61
+ const stub = proto[name];
62
+ if (typeof stub !== 'function' || InspectorFrontendHostInstance[name]) {
63
+ continue;
488
64
  }
65
+ console.error(`Incompatible embedder: method Host.InspectorFrontendHost.${name} is missing. Using stub instead.`);
66
+ // @ts-expect-error Global injected by devtools_compatibility.js
67
+ InspectorFrontendHostInstance[name] = stub;
489
68
  }
490
- // Attach the events object.
491
- InspectorFrontendHostInstance.events = new Common.ObjectWrapper.ObjectWrapper();
492
69
  }
70
+ // Attach the events object.
71
+ InspectorFrontendHostInstance.events = new Common.ObjectWrapper.ObjectWrapper();
72
+ }
73
+ (function () {
493
74
  // FIXME: This file is included into both apps, since the devtools_app needs the InspectorFrontendHostAPI only,
494
75
  // so the host instance should not be initialized there.
495
- initializeInspectorFrontendHost();
496
- // @ts-expect-error Global injected by devtools_compatibility.js
76
+ installInspectorFrontendHost(globalThis.InspectorFrontendHost ?? new InspectorFrontendHostStub());
497
77
  globalThis.InspectorFrontendAPI = new InspectorFrontendAPIImpl();
498
78
  })();
499
79
  export function isUnderTest(prefs) {
@@ -508,3 +88,5 @@ export function isUnderTest(prefs) {
508
88
  return Common.Settings.Settings.hasInstance() &&
509
89
  Common.Settings.Settings.instance().createSetting('isUnderTest', false).get();
510
90
  }
91
+ // The stub class used to be declared here so for backwards compatibility we re-export it from here.
92
+ export { InspectorFrontendHostStub };