emulate_network
Simulate various network conditions like offline mode or throttled speeds (3G/4G) on a Chrome page to test performance and offline behavior.
Instructions
Emulates network conditions such as throttling or offline mode on the selected page.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| throttlingOption | Yes | The network throttling option to emulate. Available throttling options are: No emulation, Offline, Slow 3G, Fast 3G, Slow 4G, Fast 4G. Set to "No emulation" to disable. Set to "Offline" to simulate offline network conditions. |
Implementation Reference
- src/tools/emulation.ts:33-62 (handler)The handler function that executes the network emulation logic by applying Puppeteer network conditions based on the selected throttling option.handler: async (request, _response, context) => { const page = context.getSelectedPage(); const conditions = request.params.throttlingOption; if (conditions === 'No emulation') { await page.emulateNetworkConditions(null); context.setNetworkConditions(null); return; } if (conditions === 'Offline') { await page.emulateNetworkConditions({ offline: true, download: 0, upload: 0, latency: 0, }); context.setNetworkConditions('Offline'); return; } if (conditions in PredefinedNetworkConditions) { const networkCondition = PredefinedNetworkConditions[ conditions as keyof typeof PredefinedNetworkConditions ]; await page.emulateNetworkConditions(networkCondition); context.setNetworkConditions(conditions); } },
- src/tools/emulation.ts:26-32 (schema)Zod schema defining the input parameter 'throttlingOption' with available enum values.schema: { throttlingOption: z .enum(throttlingOptions) .describe( `The network throttling option to emulate. Available throttling options are: ${throttlingOptions.join(', ')}. Set to "No emulation" to disable. Set to "Offline" to simulate offline network conditions.`, ), },
- src/tools/emulation.ts:19-63 (registration)The complete tool definition and registration using defineTool, specifying name, description, annotations, schema, and handler.export const emulateNetwork = defineTool({ name: 'emulate_network', description: `Emulates network conditions such as throttling or offline mode on the selected page.`, annotations: { category: ToolCategories.EMULATION, readOnlyHint: false, }, schema: { throttlingOption: z .enum(throttlingOptions) .describe( `The network throttling option to emulate. Available throttling options are: ${throttlingOptions.join(', ')}. Set to "No emulation" to disable. Set to "Offline" to simulate offline network conditions.`, ), }, handler: async (request, _response, context) => { const page = context.getSelectedPage(); const conditions = request.params.throttlingOption; if (conditions === 'No emulation') { await page.emulateNetworkConditions(null); context.setNetworkConditions(null); return; } if (conditions === 'Offline') { await page.emulateNetworkConditions({ offline: true, download: 0, upload: 0, latency: 0, }); context.setNetworkConditions('Offline'); return; } if (conditions in PredefinedNetworkConditions) { const networkCondition = PredefinedNetworkConditions[ conditions as keyof typeof PredefinedNetworkConditions ]; await page.emulateNetworkConditions(networkCondition); context.setNetworkConditions(conditions); } }, });
- src/tools/emulation.ts:13-17 (helper)Helper constant defining the list of available network throttling options used in the schema enum.const throttlingOptions: [string, ...string[]] = [ 'No emulation', 'Offline', ...Object.keys(PredefinedNetworkConditions), ];