Skip to content

Chrome DevTools for coding agents

8.2 KB
Raw Blame
# Copyright 2026 Google LLC
# SPDX-License-Identifier: Apache-2.0

import("//third_party/devtools-frontend/scripts/build/ninja/bundle.gni")
import("//third_party/devtools-frontend/scripts/build/ninja/copy.gni")
import(
    "//third_party/devtools-frontend/scripts/build/typescript/typescript.gni")

copy_to_gen("lighthouse_bundle") {
  sources = [ "third_party/lighthouse-devtools-mcp-bundle.js" ]
}

action("issue_descriptions") {
  script = "//third_party/node/node.py"
  _script = "//scripts/copy-issue-descriptions.ts"
  _src_dir = "$root_gen_dir/third_party/devtools-frontend/front_end/models/issues_manager/descriptions"
  _dest_dir = "$target_gen_dir/third_party/issue-descriptions"
  _stamp = "$target_gen_dir/third_party/issue-descriptions.stamp"

  deps = [ "//third_party/devtools-frontend/front_end/models/issues_manager:descriptions" ]
  inputs = [ _script ]
  outputs = [ _stamp ]

  args = [
    rebase_path(_script, root_build_dir),
    rebase_path(_src_dir, root_build_dir),
    rebase_path(_dest_dir, root_build_dir),
    rebase_path(_stamp, root_build_dir),
  ]
}

ts_library("third_party") {
  runs_in = "node"

  # The bundles below replace the JavaScript that tsc emits.
  no_js_emit = true

  sources = [
    "third_party/cli.ts",
    "third_party/devtools-formatter-worker.ts",
    "third_party/devtools-heap-snapshot-worker.ts",
    "third_party/index.ts",
    "third_party/lighthouse-devtools-mcp-bundle.d.ts",
    "third_party/zod.ts",
  ]

  ts_deps = [
    "//third_party/devtools-frontend/front_end/core/root:bundle",
    "//third_party/devtools-frontend/front_end/entrypoints/formatter_worker:worker_entrypoint",
    "//third_party/devtools-frontend/front_end/entrypoints/heap_snapshot_worker:worker_entrypoint",
    "//third_party/devtools-frontend/mcp",
  ]

  deps = [
    ":issue_descriptions",
    ":lighthouse_bundle",
  ]
}

# Bundles one src/third_party entrypoint with its npm and DevTools imports.
template("third_party_bundle") {
  bundle(target_name) {
    entrypoint = "third_party/${invoker.entrypoint_name}.ts"
    output_file_location =
        "$target_gen_dir/third_party/${invoker.entrypoint_name}.js"
    metafile = "$target_gen_dir/$target_name.meta.json"
    bundle_all = true
    platform = "node"
    deps = [
      ":third_party",
      ":third_party_sources",
    ]
    forward_variables_from(invoker,
                           [
                             "external",
                             "node_require_shim",
                           ])
  }
}

third_party_bundle("third_party_index_bundle") {
  entrypoint_name = "index"
  node_require_shim = true
  external = [
    # Puppeteer loads WebDriver BiDi support only on request. The path is
    # relative to src/third_party, like every relative entry.
    "../../node_modules/puppeteer-core/lib/puppeteer/bidi/bidi.js",

    # Separate files in the same directory.
    "./cli.js",
    "./lighthouse-devtools-mcp-bundle.js",

    # Optional peer dependencies.
    "@blackwell-systems/gcf",
    "@toon-format/toon",

    # Imports of @puppeteer/browsers code paths that the server never runs.
    "modern-tar",
    "proxy-agent",
    "yargs",
    "yauzl",
  ]
}

third_party_bundle("third_party_cli_bundle") {
  entrypoint_name = "cli"
  node_require_shim = true
}

third_party_bundle("third_party_formatter_worker_bundle") {
  entrypoint_name = "devtools-formatter-worker"
}

third_party_bundle("third_party_heap_snapshot_worker_bundle") {
  entrypoint_name = "devtools-heap-snapshot-worker"
}

# Lists the licenses of the files in the bundles. The files come from the
# metafiles that the `bundle` template writes next to each target.
action("third_party_notices") {
  script = "//third_party/node/node.py"
  _script = "//scripts/generate-third-party-notices.ts"
  _third_party_gen_dir = "$target_gen_dir/third_party"
  _bundles = [
    "third_party_cli_bundle",
    "third_party_formatter_worker_bundle",
    "third_party_heap_snapshot_worker_bundle",
    "third_party_index_bundle",
  ]

  inputs = [
    _script,
    "//package-lock.json",
    "//package.json",
    "third_party/LIGHTHOUSE_MCP_BUNDLE_THIRD_PARTY_NOTICES",
  ]
  deps = []
  outputs = [
    "$_third_party_gen_dir/THIRD_PARTY_NOTICES",
    "$_third_party_gen_dir/bundled-packages.json",
  ]

  args = [ rebase_path(_script, root_build_dir) ]
  foreach(_bundle, _bundles) {
    _metafile = "$target_gen_dir/$_bundle.meta.json"
    deps += [ ":$_bundle" ]
    inputs += [ _metafile ]
    args += [
      "--metafile",
      rebase_path(_metafile, root_build_dir),
    ]
  }
  args += [
    "--notices",
    rebase_path(outputs[0], root_build_dir),
    "--bundled-packages",
    rebase_path(outputs[1], root_build_dir),
  ]
}

ts_library("mcp_lib") {
  runs_in = "node"

  sources = [
    "BrowserManager.ts",
    "LogpointManager.ts",
    "McpContext.ts",
    "McpPage.ts",
    "McpResponse.ts",
    "McpWorker.ts",
    "NetworkOverrideManager.ts",
    "SlimMcpResponse.ts",
    "TextSnapshot.ts",
    "ToolHandler.ts",
    "collectors/PageCollector.ts",
    "collectors/ServiceWorkerCollector.ts",
    "collectors/constants.ts",
    "config/ConfigLocator.ts",
    "config/ConfigParser.ts",
    "config/ConfigWatcher.ts",
    "config/ServerConfig.ts",
    "config/browser-options.ts",
    "config/category-options.ts",
    "config/cli-commands.ts",
    "config/cli-options.ts",
    "config/mcp-options.ts",
    "config/puppeteer-options.ts",
    "config/tool-options.ts",
    "daemon/client.ts",
    "daemon/daemon.ts",
    "daemon/types.ts",
    "daemon/utils.ts",
    "devtools/DevToolsCommentBridge.ts",
    "devtools/DevtoolsUtils.ts",
    "devtools/McpHostBindingAdapter.ts",
    "devtools/devtools.d.ts",
    "devtools/issueDescriptions.ts",
    "formatters/CommentFormatter.ts",
    "formatters/ConsoleFormatter.ts",
    "formatters/CssFormatter.ts",
    "formatters/HeapSnapshotFormatter.ts",
    "formatters/IssueFormatter.ts",
    "formatters/LogpointFormatter.ts",
    "formatters/NetworkFormatter.ts",
    "formatters/NetworkOverridesFormatter.ts",
    "formatters/RemoteObjectFormatter.ts",
    "formatters/SnapshotFormatter.ts",
    "formatters/WebAuthnFormatter.ts",
    "index.ts",
    "processors/ChunkedTraceParser.ts",
    "processors/HeapSnapshotManager.ts",
    "processors/PerformanceTrace.ts",
    "telemetry/ClearcutLogger.ts",
    "telemetry/WatchdogClient.ts",
    "telemetry/errors.ts",
    "telemetry/flagUtils.ts",
    "telemetry/metricsRegistry.ts",
    "telemetry/persistence.ts",
    "telemetry/transformation.ts",
    "telemetry/types.ts",
    "telemetry/watchdog/ClearcutSender.ts",
    "telemetry/watchdog/main.ts",
    "tools/ToolDefinition.ts",
    "tools/categories.ts",
    "tools/comments.ts",
    "tools/console.ts",
    "tools/css.ts",
    "tools/emulation.ts",
    "tools/extensions.ts",
    "tools/input.ts",
    "tools/lighthouse.ts",
    "tools/logpoints.ts",
    "tools/memory.ts",
    "tools/network.ts",
    "tools/pages.ts",
    "tools/performance.ts",
    "tools/pwa.ts",
    "tools/screencast.ts",
    "tools/screenshot.ts",
    "tools/script.ts",
    "tools/slim/tools.ts",
    "tools/snapshot.ts",
    "tools/thirdPartyDeveloper.ts",
    "tools/toolNames.ts",
    "tools/tools.ts",
    "tools/webauthn.ts",
    "tools/webmcp.ts",
    "types.ts",
    "utils/TaskRunner.ts",
    "utils/WaitForHelper.ts",
    "utils/bytes.ts",
    "utils/check-for-updates.ts",
    "utils/disclaimers.ts",
    "utils/errorHandling.ts",
    "utils/files.ts",
    "utils/id.ts",
    "utils/keyboard.ts",
    "utils/logger.ts",
    "utils/network.ts",
    "utils/pagination.ts",
    "utils/polyfill.ts",
    "utils/raceWithSignal.ts",
    "utils/resourceType.ts",
    "utils/text.ts",
    "utils/timeout.ts",
    "utils/url.ts",
    "version.ts",
  ]

  ts_deps = [ ":third_party" ]
}

ts_library("bin") {
  runs_in = "node"

  sources = [
    "bin/check-latest-version.ts",
    "bin/chrome-devtools-mcp-main.ts",
    "bin/chrome-devtools-mcp.ts",
    "bin/chrome-devtools.ts",
  ]

  ts_deps = [
    ":mcp_lib",
    ":third_party",
  ]
}

group("all") {
  public_deps = [
    ":bin",
    ":issue_descriptions",
    ":lighthouse_bundle",
    ":mcp_lib",
    ":third_party",
    ":third_party_cli_bundle",
    ":third_party_formatter_worker_bundle",
    ":third_party_heap_snapshot_worker_bundle",
    ":third_party_index_bundle",
    ":third_party_notices",
  ]
}