diff --git a/Report/lighthouse/lighthouse.ts b/Report/lighthouse/lighthouse.ts index c83d87e..d869a0c 100644 --- a/Report/lighthouse/lighthouse.ts +++ b/Report/lighthouse/lighthouse.ts @@ -6,7 +6,9 @@ import { screenEmulationMetrics, userAgents} from 'lighthouse/core/config/consta const MAX_WAIT_FOR_LOAD = 30 * 1000; //seconds const MAX_WAIT_FOR_FCP = 15 * 1000; //seconds -const SKIP_RESOURCES = ['stylesheet', 'font', 'image', 'imageset', 'media', 'ping', 'fetch', 'prefetch', 'preflight', 'websocket'] +const SKIP_RESOURCES = ['stylesheet', 'font', 'image', 'imageset', 'media', 'ping', 'fetch', 'prefetch', 'preflight', 'websocket']; +const base64Font = "d09GMgABAAAAAANMAA4AAAAAB5wAAALzAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP0ZGVE0cGh4GYACCQggEEQgKghCCBQsKAAE2AiQDEAQgBYVoBzQbkgZRlA3KLrKPwziGXKIIJZRhWeKjhaW5iHc8D+337dyZeX8XM0tqCa+b0BAJWSUTRSOESKRDer+Elf/fP73/pxBepXCrtIUq9XPyX1N40yxPPd20eYM4w2v+53J6YxJ8phOZw26LHd01NmV5hIHdyxbInCB5FA2xiENuQG8T/JF1eSoE/n6IGgX8f9FGc7MmMBOLgSKqKhoKWu3zVEd5QP7CQyCTf/aFhOLqKm7y8u2cEtgYGqpXzVU09aPXCADWIlBRsRIBjmAIVrKwFmiaMDQ1Rb55aYUAGRBACgrUjxPIF1pXmgBkagoJGhhFh9PAGAANu5GgtjZr1jp7y1ntpn03PdHSu3fWeb7fd3jZdXHg6Fi5vtfD40x2dqa4UHgNLM12evZ7ep7Lz1+Vl0rvQe/RrrmQEdv3PdpUbTJdpCgwMiBDEJDplewVmCkIzPBaDzKQjAbPScwrvD6WxcLy2JLoK7I0sjxKzH83T33Em91k3YXaZmYDE4qJ3cwpyMuWhz7FvwN8C1bygnWDN+68VXfHso7XwgdhFev4iHCQcRrPMxMI3zf5HHM+8jdqX4cdfiSYel/7uhbAqAKik9qQsrf2rG0YeNaFS/KfEzSHMUDBdNMxhQnAfA8COKQGAWLUTwHFiD8CqlG9gGY0RUBnRjYAAQZGcxIIMN2OzAiYYUH+VWnTcB/YEHPNQDHbb6jmOkcb+QmdxbGHgblhwXQ3c2kfM2zOgdMoBk2MKpWrgCHRssRAuNi4eJAiTRAqRXGlOoVqIIXqYRWhr6Mh6ZAylDpYqRo1KEzFKLXgD0bjrBj0vX/aKqycRs3057/ijkScqbtDWS5EDQe4qlS5ejUKGcFL3DpN3nlw+U2ljGiV0dUIBxMbnP/65zDZWdHzZl32WKFIt6TOPgrNpBwXhpVByhhRaiG5RSWIIfyeKqWKYUzw8CBNm8q5GJedGJ3catUXCj8iwF0YZpCIhdUKyoa+RR0PpgCmT7gFDVFSpt2qpRLWXwAAAA=="; +const base64Image = "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/wAALCAABAAEBAREA/8QAFAABAAAAAAAAAAAAAAAAAAAACf/EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAD8AKp//2Q=="; const audit = async (page: any, url: string, desktop?: boolean) => { @@ -133,14 +135,46 @@ async function execute() { page.on('dialog', dialog => { dialog.dismiss(); }); + page.on('request', (req) => { - if(SKIP_RESOURCES.some((type) => req.resourceType() == type)){ - // req.abort(); - req.respond({ - status: 200, - contentType: 'text/plain', - body: 'success' - }); + const resourceType = req.resourceType(); + if (SKIP_RESOURCES.some((type) => resourceType == type)){ + switch (resourceType) { + case 'image': + req.respond( + { + status: 200, + contentType: 'image/jpeg', + body: Buffer.from(base64Image, 'base64'), + }); + break; + case 'font': + req.respond( + { + status: 200, + contentType: 'font/woff2', + body: Buffer.from(base64Font, 'base64'), + + }); + break; + case 'fetch': + if (req.method() == 'GET') + req.respond({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ success: true, message: "Intercepted fetch request" }), + }); + else + req.continue(); + break; + default: + req.respond({ + status: 200, + contentType: 'text/plain', + body: '{"success": true}', + }); + break; + } } else req.continue();