Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/tool-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions src/McpResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ export class McpResponse implements Response {
extensionPages?: object[];
errorMessage?: string;
navigatedToUrl?: string;
geolocation?: {latitude: number; longitude: number};
} = {};

const response = [];
Expand Down Expand Up @@ -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)}`);
Expand Down
2 changes: 1 addition & 1 deletion src/bin/chrome-devtools-cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/ToolDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/tools/emulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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');
},
});
2 changes: 1 addition & 1 deletion tests/tools/emulation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
Loading