-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathemulation.ts
More file actions
93 lines (89 loc) · 2.5 KB
/
emulation.ts
File metadata and controls
93 lines (89 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*
*/
import {zod, PredefinedNetworkConditions} from '../third_party/index.js';
import {ToolCategory} from './categories.js';
import {defineTool} from './ToolDefinition.js';
const throttlingOptions: [string, ...string[]] = [
'No emulation',
'Offline',
...Object.keys(PredefinedNetworkConditions),
];
export const emulate = defineTool({
name: 'emulate',
description: `Emulates various features.`,
annotations: {
category: ToolCategory.EMULATION,
readOnlyHint: false,
},
schema: {
networkConditions: zod
.enum(throttlingOptions)
.optional()
.describe(
`Throttle network. "No emulation" to disable. Omit to keep unchanged.`,
),
cpuThrottlingRate: zod
.number()
.min(1)
.max(20)
.optional()
.describe('CPU slowdown factor. 1 to disable. Omit to keep unchanged.'),
geolocation: zod
.object({
latitude: zod
.number()
.min(-90)
.max(90)
.describe('Latitude between -90 and 90.'),
longitude: zod
.number()
.min(-180)
.max(180)
.describe('Longitude between -180 and 180.'),
})
.nullable()
.optional()
.describe('Geolocation to emulate. null to clear override.'),
userAgent: zod
.string()
.nullable()
.optional()
.describe('User agent to emulate. null to clear override.'),
colorScheme: zod
.enum(['dark', 'light', 'auto'])
.optional()
.describe('Emulate dark or light mode. "auto" to reset.'),
viewport: zod
.object({
width: zod.number().int().min(0).describe('Page width (px).'),
height: zod.number().int().min(0).describe('Page height (px).'),
deviceScaleFactor: zod
.number()
.min(0)
.optional()
.describe('Device scale factor (dpr).'),
isMobile: zod
.boolean()
.optional()
.describe('Use meta viewport tag. Default: false.'),
hasTouch: zod
.boolean()
.optional()
.describe('Viewport supports touch. true for mobile.'),
isLandscape: zod
.boolean()
.optional()
.describe('Landscape mode. Default: false.'),
})
.nullable()
.optional()
.describe('Viewport to emulate. null to reset.'),
},
handler: async (request, _response, context) => {
await context.emulate(request.params);
},
});