getNetworkRequests
Capture and retrieve all network requests generated by a web page for debugging, monitoring, or analysis in browser automation workflows using Playwright.
Instructions
Get network requests made by the page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/controllers/playwright.ts:769-799 (handler)Core handler function that sets up Playwright listeners for network requests and responses, collects request data (url, method, status), and returns the list.async getNetworkRequests(): Promise<Array<{url: string, method: string, status?: number}>> { try { if (!this.isInitialized() || !this.state.page) { throw new Error('Browser not initialized'); } this.log('Getting network requests'); const requests: Array<{url: string, method: string, status?: number}> = []; // Listen to request events this.state.page.on('request', request => { requests.push({ url: request.url(), method: request.method() }); }); this.state.page.on('response', response => { const request = requests.find(req => req.url === response.url()); if (request) { request.status = response.status(); } }); this.log('Network requests retrieved'); return requests; } catch (error: any) { console.error('Get network requests error:', error); throw new BrowserError('Failed to get network requests', 'Network monitoring error'); } }
- src/server.ts:401-409 (schema)Tool schema definition with name, description, and empty input schema (no parameters required).const GET_NETWORK_REQUESTS_TOOL: Tool = { name: "getNetworkRequests", description: "Get network requests made by the page", inputSchema: { type: "object", properties: {}, required: [] } };
- src/server.ts:545-545 (registration)Registration of the tool in the tools object/map used by the MCP server.getNetworkRequests: GET_NETWORK_REQUESTS_TOOL,
- src/server.ts:906-911 (handler)Server-side dispatch handler that calls the controller's getNetworkRequests method and formats the response for MCP.case 'getNetworkRequests': { const requests = await playwrightController.getNetworkRequests(); return { content: [{ type: "text", text: JSON.stringify(requests, null, 2) }] }; }
- src/server.ts:562-563 (registration)Server initialization registers the tools object containing getNetworkRequests.tools, },