on_page_lighthouse
Analyze web page quality using Google's Lighthouse metrics to measure performance, accessibility, SEO, and best practices for optimization.
Instructions
The OnPage Lighthouse API is based on Google’s open-source Lighthouse project for measuring the quality of web pages and web apps.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accept_language | No | Accept-Language header value | |
| custom_js | No | Custom JavaScript code to execute | |
| custom_user_agent | No | Custom User-Agent header | |
| enable_javascript | No | Enable JavaScript rendering | |
| url | Yes | URL of the page to parse |
Implementation Reference
- Implements the core tool logic: sends POST request to DataForSEO /v3/on_page/lighthouse/live/json with parameters and processes response or error.async handle(params: any): Promise<any> { try { const response = await this.dataForSEOClient.makeRequest('/v3/on_page/lighthouse/live/json', 'POST', [{ url: params.url, enable_javascript: params.enable_javascript, custom_js: params.custom_js, custom_user_agent: params.custom_user_agent, accept_language: params.accept_language, }]); return this.validateAndFormatResponse(response); } catch (error) { return this.formatErrorResponse(error); } }
- Defines Zod schema for input parameters: url (required), and optional flags for JS, custom JS, user agent, language.getParams(): z.ZodRawShape { return { url: z.string().describe("URL of the page to parse"), enable_javascript: z.boolean().optional().describe("Enable JavaScript rendering"), custom_js: z.string().optional().describe("Custom JavaScript code to execute"), custom_user_agent: z.string().optional().describe("Custom User-Agent header"), accept_language: z.string().optional().describe("Accept-Language header value"), }; }
- src/core/modules/onpage/onpage-api.module.ts:9-25 (registration)Instantiates LighthouseTool and registers it in the tools map using its name 'on_page_lighthouse', description, params schema, and handle method as handler.getTools(): Record<string, ToolDefinition> { const tools = [ new ContentParsingTool(this.dataForSEOClient), new InstantPagesTool(this.dataForSEOClient), new LighthouseTool(this.dataForSEOClient), // Add more tools here ]; return tools.reduce((acc, tool) => ({ ...acc, [tool.getName()]: { description: tool.getDescription(), params: tool.getParams(), handler: (params: any) => tool.handle(params), }, }), {}); }