analyze_network_requests
Analyze network requests from web pages to identify API calls, track resource loading, and monitor data transfers for development and debugging purposes.
Instructions
Analyze all network requests made by a web page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL to analyze | |
| timeout | No | Analysis timeout in milliseconds |
Implementation Reference
- src/tools/api-discovery.ts:172-186 (handler)Handler logic for the 'analyze_network_requests' tool: extracts URL and timeout parameters, invokes APIScraper.analyzeNetworkRequests, formats and returns the list of network requests with key details.case 'analyze_network_requests': { const url = params.url as string; const timeout = params.timeout as number; const requests = await apiScraper.analyzeNetworkRequests(url, { timeout }); return { total: requests.length, requests: requests.map((r) => ({ url: r.url, method: r.method, status: r.status, type: r.type, responseTime: r.responseTime, })), }; }
- src/tools/api-discovery.ts:28-42 (schema)Input schema definition specifying required 'url' parameter and optional 'timeout' for the analyze_network_requests tool.inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'URL to analyze', }, timeout: { type: 'number', description: 'Analysis timeout in milliseconds', default: 30000, }, }, required: ['url'], },
- src/tools/api-discovery.ts:25-43 (registration)Registration of the 'analyze_network_requests' tool in the apiDiscoveryTools array, including name, description, and input schema.{ name: 'analyze_network_requests', description: 'Analyze all network requests made by a web page', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'URL to analyze', }, timeout: { type: 'number', description: 'Analysis timeout in milliseconds', default: 30000, }, }, required: ['url'], }, },
- src/scrapers/api-scraper.ts:132-175 (helper)Core helper method in APIScraper class that uses Playwright to launch a browser, navigate to the URL, monitor all network requests and responses, capture details like URL, method, status, type, and response time.async analyzeNetworkRequests(url: string, options?: { timeout?: number }): Promise<NetworkRequest[]> { if (!Validators.isValidUrl(url)) { throw new Error('Invalid URL'); } const browser = await this.getBrowser(); const page = await browser.newPage(); const requests: NetworkRequest[] = []; const startTime = Date.now(); try { page.on('request', (request) => { requests.push({ url: request.url(), method: request.method(), status: 0, statusText: '', headers: request.headers(), requestHeaders: request.headers(), }); }); page.on('response', (response) => { const request = requests.find((r) => r.url === response.url()); if (request) { request.status = response.status(); request.statusText = response.statusText(); request.type = response.headers()['content-type'] || ''; request.responseTime = Date.now() - startTime; } }); await page.goto(url, { waitUntil: 'networkidle', timeout: options?.timeout || 30000, }); await page.waitForTimeout(2000); return requests; } finally { await page.close(); } }