harlan-zw / unlighthouse

Scan your entire site with Google Lighthouse in 2 minutes (on average). Open source, fully configurable with minimal setup.
https://unlighthouse.dev
MIT License
3.65k stars 105 forks source link

Cookies are missing during lighthouse scan #197

Open lutejka opened 3 months ago

lutejka commented 3 months ago

Describe the bug

I set some cookies in the configuration. During the startup, those cookies are used, however they are missing in the actuall scan.

To heck this, I used the following set up:

server.js

import http from 'http'

function parseCookies (request) {
    const list = {};
    const cookieHeader = request.headers?.cookie;
    if (!cookieHeader) return list;

    cookieHeader.split(`;`).forEach(function(cookie) {
        let [ name, ...rest] = cookie.split(`=`);
        name = name?.trim();
        if (!name) return;
        const value = rest.join(`=`).trim();
        if (!value) return;
        list[name] = decodeURIComponent(value);
    });

    return list;
}

const server = http.createServer(function (request, response) {
    // To Read a Cookie
    const cookies = parseCookies(request);
    console.log(cookies)

    response.writeHeader(200, {"Content-Type": "text/html"});
    response.write('<div>test</div>');
    response.end();
}).listen(8080);

const {address, port} = server.address();
console.log(`Server running at http://${address}:${port}`);

run ´node server.js´

run unlghthouse with the follwoing config

export default {
  site: 'http://localhost:8080',
  cookies: [
    {
      name: 'test',
      value:'2023-07-06T12:01:40.453Z'
    },
  ],
}

In the output of node server.js the used cookies should be logged, but they are missing.

Reproduction

No response

System / Nuxt Info

No response

harlan-zw commented 2 months ago

Hi, thanks for providing the reproduction code. I've tried it locally and it seems to be outputting the headers. Can you confirm which version you're using?

lutejka commented 2 months ago

I cant remember it was either 0.10. or 0.11. I also just tested it with 0.12.0 and it still happens

image

lutejka commented 2 months ago

When testing a other side I also got these errors a bunch

 ERROR  Failed to set cookies Protocol error (Network.deleteCookies): Target closed                                                                                                                      Unlighthouse 10:38:48 PM

  at CallbackRegistry.clear (/Users/lukas.matejka/.npm/_npx/944abecbf21dfffb/node_modules/puppeteer-core/lib/esm/puppeteer/common/CallbackRegistry.js:69:36)
  at CdpCDPSession._onClosed (/Users/lukas.matejka/.npm/_npx/944abecbf21dfffb/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/CDPSession.js:98:25)
  at Connection.onMessage (/Users/lukas.matejka/.npm/_npx/944abecbf21dfffb/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/Connection.js:118:25)
  at Immediate.<anonymous> (/Users/lukas.matejka/.npm/_npx/944abecbf21dfffb/node_modules/puppeteer-core/lib/esm/puppeteer/node/NodeWebSocketTransport.js:37:36)
  at process.processImmediate (node:internal/timers:478:21)