safari_get_performance_metrics
Retrieve page performance metrics from Safari sessions using sessionId, enabling analysis of browser behavior and page efficiency for automation and debugging tasks.
Instructions
Get page performance metrics
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session identifier |
Implementation Reference
- src/safari-driver.ts:351-376 (handler)Core handler that retrieves performance metrics by executing JavaScript using the browser's Performance API to access navigation timing and paint events.async getPerformanceMetrics(sessionId: string): Promise<PerformanceMetrics> { const session = this.getSession(sessionId); if (!session) { throw new Error(`Session ${sessionId} not found`); } try { const metrics = await session.driver.executeScript(` const timing = performance.timing; const paintEntries = performance.getEntriesByType('paint'); return { navigationStart: timing.navigationStart, loadEventEnd: timing.loadEventEnd, domContentLoadedEventEnd: timing.domContentLoadedEventEnd, firstPaint: paintEntries.find(entry => entry.name === 'first-paint')?.startTime, firstContentfulPaint: paintEntries.find(entry => entry.name === 'first-contentful-paint')?.startTime }; `); return metrics; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Failed to get performance metrics: ${errorMessage}`); } }
- src/safari-mcp-server.ts:176-186 (schema)Tool registration entry including name, description, and input schema definition.{ name: 'safari_get_performance_metrics', description: 'Get page performance metrics', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Session identifier' } }, required: ['sessionId'] } },
- src/safari-mcp-server.ts:374-385 (handler)MCP server wrapper handler that calls the driver manager and formats the response as MCP content.private async getPerformanceMetrics(args: Record<string, any>): Promise<Array<{ type: string; text: string }>> { const { sessionId } = args; const metrics = await this.driverManager.getPerformanceMetrics(sessionId); return [ { type: 'text', text: `Performance Metrics:\n\n${JSON.stringify(metrics, null, 2)}` } ]; }
- src/safari-mcp-server.ts:252-253 (registration)Dispatch registration in the tool call switch statement routing to the specific handler.case 'safari_get_performance_metrics': return await this.getPerformanceMetrics(args);
- src/types.ts:44-50 (schema)TypeScript interface defining the structure of performance metrics returned by the tool.export interface PerformanceMetrics { navigationStart?: number; loadEventEnd?: number; domContentLoadedEventEnd?: number; firstPaint?: number; firstContentfulPaint?: number; }