safari_get_performance_metrics
Retrieve page performance metrics from Safari to analyze loading times, resource usage, and browser performance data for optimization.
Instructions
Get page performance metrics
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"sessionId": "<sessionId>"
},
"name": "safari_get_performance_metrics"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session identifier |
Implementation Reference
- src/safari-driver.ts:351-376 (handler)Core handler implementation in SafariDriverManager that executes JavaScript to fetch browser performance metrics using the Performance Timing API and paint entries.
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:374-385 (handler)MCP server handler method that extracts the sessionId from arguments, calls the driver manager, and formats the metrics as a text response.
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:176-186 (registration)Tool registration entry in the MCP server's tool list, including the 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:176-186 (schema)Input schema definition for the tool, specifying the required sessionId parameter.
{ name: 'safari_get_performance_metrics', description: 'Get page performance metrics', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Session identifier' } }, required: ['sessionId'] } },