wait_for_network_idle
Wait for network activity to settle (no connections for 500ms). Returns idle state confirmation and actual wait duration. Useful for AJAX calls or dynamic content loading.
Instructions
Wait for network activity to settle. Waits until there are no network connections for at least 500ms. Better than fixed delays when waiting for AJAX calls or dynamic content loading. Returns actual wait duration and confirmation of idle state.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timeout | No | Maximum time to wait in milliseconds (default: 10000) |
Implementation Reference
- The execute method that calls page.waitForLoadState('networkidle') to wait for network activity to settle, returning duration and success/error info.
async execute(args: WaitForNetworkIdleArgs, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async (page) => { const { timeout = 10000 } = args; const startTime = Date.now(); try { // Wait for network to be idle (no network connections for at least 500ms) await page.waitForLoadState('networkidle', { timeout }); const duration = Date.now() - startTime; return { content: [{ type: 'text', text: `✓ Network idle after ${duration}ms, 0 pending requests` }], isError: false, }; } catch (error) { const duration = Date.now() - startTime; const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: 'text', text: `✗ Timeout after ${duration}ms waiting for network idle\nError: ${errorMessage}` }], isError: true, }; } }); } } - TypeScript interface defining the args for wait_for_network_idle: optional timeout number.
export interface WaitForNetworkIdleArgs { timeout?: number; } - src/tools/browser/register.ts:101-103 (registration)WaitForNetworkIdleTool is registered in the BROWSER_TOOL_CLASSES array.
// Waiting (2) WaitForElementTool, WaitForNetworkIdleTool, - src/tools/browser/register.ts:51-51 (registration)Import statement for WaitForNetworkIdleTool in the registration file.
import { WaitForNetworkIdleTool } from './waiting/wait_for_network_idle.js'; - getMetadata method providing the tool's name, description, and input schema definition.
static getMetadata(sessionConfig?: SessionConfig): ToolMetadata { return { name: "wait_for_network_idle", description: "Wait for network activity to settle. Waits until there are no network connections for at least 500ms. Better than fixed delays when waiting for AJAX calls or dynamic content loading. Returns actual wait duration and confirmation of idle state.", annotations: ANNOTATIONS.readOnly, inputSchema: { type: "object", properties: { timeout: { type: "number", description: "Maximum time to wait in milliseconds (default: 10000)" } }, required: [], }, }; }