Skip to content

Chrome DevTools for coding agents

1.5 KB
Raw Blame
/**
 * @license
 * Copyright 2026 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import type {ScenarioArgs, ScenarioIterations, ToolCall} from '../types.ts';
import {uidsFromSnapshotResult} from '../utils.ts';

export function getNumIterations(): ScenarioIterations {
  return {
    iterations: 10,
    // V8 still compiles get_css_styles code after 10 warm-up iterations. That
    // compiled code shows as heap growth in the measured iterations.
    warmupIterations: 20,
  };
}

export function get(args: ScenarioArgs): ToolCall[] {
  const pageId = 1;
  const toolCalls: ToolCall[] = [
    {
      name: 'navigate_page',
      arguments: {
        pageId,
        type: 'url',
        url: args.targetUrl,
      },
    },
    {
      name: 'take_snapshot',
      arguments: {
        pageId,
      },
    },
  ];

  for (let index = 0; index < 25; index++) {
    toolCalls.push({
      name: 'get_css_styles',
      arguments: context => {
        const snapshotResult = context.results[1];
        const uids = uidsFromSnapshotResult(snapshotResult);
        const uid = uids[index % uids.length];
        if (!uid) {
          throw new Error(
            `No element UID available in snapshot for index ${index}`,
          );
        }
        const pagination =
          index % 3 === 0
            ? {pageSize: 3, pageIdx: 0}
            : index % 3 === 1
              ? {pageSize: 3, pageIdx: 1}
              : {};
        return {
          pageId,
          uid,
          ...pagination,
        };
      },
    });
  }

  return toolCalls;
}