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
4 changes: 2 additions & 2 deletions docs/tool-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@

### `emulate_network`

**Description:** Emulates network conditions such as throttling on the selected page.
**Description:** Emulates network conditions such as throttling or offline mode on the selected page.

**Parameters:**

- **throttlingOption** (enum: "No emulation", "Slow 3G", "Fast 3G", "Slow 4G", "Fast 4G") **(required)**: The network throttling option to emulate. Available throttling options are: No emulation, Slow 3G, Fast 3G, Slow 4G, Fast 4G. Set to "No emulation" to disable.
- **throttlingOption** (enum: "No emulation", "Offline", "Slow 3G", "Fast 3G", "Slow 4G", "Fast 4G") **(required)**: 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.

---

Expand Down
20 changes: 9 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
"@modelcontextprotocol/sdk": "1.19.1",
"core-js": "3.45.1",
"debug": "4.4.3",
"puppeteer-core": "24.23.0",
"yargs": "18.0.0"
"puppeteer-core": "^24.23.0",
"yargs": "18.0.0",
"zod": "^3.25.76"
},
"devDependencies": {
"@eslint/js": "^9.35.0",
Expand Down
16 changes: 14 additions & 2 deletions src/tools/emulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import {defineTool} from './ToolDefinition.js';

const throttlingOptions: [string, ...string[]] = [
'No emulation',
'Offline',
...Object.keys(PredefinedNetworkConditions),
];

export const emulateNetwork = defineTool({
name: 'emulate_network',
description: `Emulates network conditions such as throttling on the selected page.`,
description: `Emulates network conditions such as throttling or offline mode on the selected page.`,
annotations: {
category: ToolCategories.EMULATION,
readOnlyHint: false,
Expand All @@ -26,7 +27,7 @@ export const emulateNetwork = defineTool({
throttlingOption: z
.enum(throttlingOptions)
.describe(
`The network throttling option to emulate. Available throttling options are: ${throttlingOptions.join(', ')}. Set to "No emulation" to disable.`,
`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) => {
Expand All @@ -39,6 +40,17 @@ export const emulateNetwork = defineTool({
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[
Expand Down
15 changes: 15 additions & 0 deletions tests/tools/emulation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ import {withBrowser} from '../utils.js';

describe('emulation', () => {
describe('network', () => {
it('emulates offline network conditions', async () => {
await withBrowser(async (response, context) => {
await emulateNetwork.handler(
{
params: {
throttlingOption: 'Offline',
},
},
response,
context,
);

assert.strictEqual(context.getNetworkConditions(), 'Offline');
});
});
it('emulates network throttling when the throttling option is valid ', async () => {
await withBrowser(async (response, context) => {
await emulateNetwork.handler(
Expand Down