Chrome DevTools for coding agents
fix: improve geolocation emulation (#2036)
Alex Rudenko213720b69cdc
diff --git a/docs/tool-reference.md b/docs/tool-reference.mdindex 578fae1a..79596def 100644--- a/docs/tool-reference.md+++ b/docs/tool-reference.md@@ -256,7 +256,7 @@- **colorScheme** (enum: "dark", "light", "auto") _(optional)_: [`Emulate`](#emulate) the dark or the light mode. Set to "auto" to reset to the default.- **cpuThrottlingRate** (number) _(optional)_: Represents the CPU slowdown factor. Omit or set the rate to 1 to disable throttling-- **geolocation** (string) _(optional)_: Geolocation (`<latitude>x<longitude>`) to [`emulate`](#emulate). Latitude between -90 and 90. Longitude between -180 and 180. Omit to clear the geolocation override.+- **geolocation** (string) _(optional)_: Geolocation (`<latitude>,<longitude>`) to [`emulate`](#emulate). Latitude between -90 and 90. Longitude between -180 and 180. Omit to clear the geolocation override.- **networkConditions** (enum: "Offline", "Slow 3G", "Fast 3G", "Slow 4G", "Fast 4G") _(optional)_: Throttle network. Omit to disable throttling.- **userAgent** (string) _(optional)_: User agent to [`emulate`](#emulate). Set to empty string to clear the user agent override.- **viewport** (string) _(optional)_: [`Emulate`](#emulate) device viewports '<width>x<height>x<devicePixelRatio>[,mobile][,touch][,landscape]'. 'touch' and 'mobile' to [`emulate`](#emulate) mobile devices. 'landscape' to [`emulate`](#emulate) landscape mode.diff --git a/src/McpResponse.ts b/src/McpResponse.tsindex 64404bca..ec685741 100644--- a/src/McpResponse.ts+++ b/src/McpResponse.ts@@ -746,6 +746,7 @@ export class McpResponse implements Response {extensionPages?: object[];errorMessage?: string;navigatedToUrl?: string;+ geolocation?: {latitude: number; longitude: number};} = {};const response = [];@@ -773,6 +774,14 @@ export class McpResponse implements Response {structuredContent.navigationTimeout = timeout;}+ const geolocation = this.#page?.geolocation;+ if (geolocation) {+ response.push(+ `Emulating geolocation: latitude=${geolocation.latitude}, longtitude=${geolocation.longitude}`,+ );+ structuredContent.geolocation = geolocation;+ }+const viewport = this.#page?.viewport;if (viewport) {response.push(`Emulating viewport: ${JSON.stringify(viewport)}`);diff --git a/src/bin/chrome-devtools-cli-options.ts b/src/bin/chrome-devtools-cli-options.tsindex 60418088..55f4af01 100644--- a/src/bin/chrome-devtools-cli-options.ts+++ b/src/bin/chrome-devtools-cli-options.ts@@ -142,7 +142,7 @@ export const commands: Commands = {name: 'geolocation',type: 'string',description:- 'Geolocation (`<latitude>x<longitude>`) to emulate. Latitude between -90 and 90. Longitude between -180 and 180. Omit to clear the geolocation override.',+ 'Geolocation (`<latitude>,<longitude>`) to emulate. Latitude between -90 and 90. Longitude between -180 and 180. Omit to clear the geolocation override.',required: false,},userAgent: {diff --git a/src/tools/ToolDefinition.ts b/src/tools/ToolDefinition.tsindex 5027c6cd..66b6c353 100644--- a/src/tools/ToolDefinition.ts+++ b/src/tools/ToolDefinition.ts@@ -417,7 +417,7 @@ export function geolocationTransform(arg: string | undefined) {if (!arg) {return undefined;}- const [latitude, longitude] = arg.split('x').map(Number) as [number, number];+ const [latitude, longitude] = arg.split(',').map(Number) as [number, number];return {latitude,longitude,diff --git a/src/tools/emulation.ts b/src/tools/emulation.tsindex 2dbb026f..7eebe920 100644--- a/src/tools/emulation.ts+++ b/src/tools/emulation.ts@@ -44,7 +44,7 @@ export const emulate = definePageTool({.optional().transform(geolocationTransform).describe(- 'Geolocation (`<latitude>x<longitude>`) to emulate. Latitude between -90 and 90. Longitude between -180 and 180. Omit to clear the geolocation override.',+ 'Geolocation (`<latitude>,<longitude>`) to emulate. Latitude between -90 and 90. Longitude between -180 and 180. Omit to clear the geolocation override.',),userAgent: zod.string()@@ -67,8 +67,9 @@ export const emulate = definePageTool({),},blockedByDialog: true,- handler: async (request, _response, context) => {+ handler: async (request, response, context) => {const page = request.page;await context.emulate(request.params, page.pptrPage);+ response.appendResponseLine('Emulation configured successfully');},});diff --git a/tests/tools/emulation.test.ts b/tests/tools/emulation.test.tsindex 721505fc..b1a19a90 100644--- a/tests/tools/emulation.test.ts+++ b/tests/tools/emulation.test.ts@@ -75,7 +75,7 @@ describe('emulation', () => {});it('parses latitude and longitude', () => {- assert.deepStrictEqual(geolocationTransform('48.137154x11.576124'), {+ assert.deepStrictEqual(geolocationTransform('48.137154,11.576124'), {latitude: 48.137154,longitude: 11.576124,});