Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookies are missing during lighthouse scan #197

Closed
lutejka opened this issue Mar 7, 2024 · 6 comments
Closed

Cookies are missing during lighthouse scan #197

lutejka opened this issue Mar 7, 2024 · 6 comments

Comments

@lutejka
Copy link
Contributor

lutejka commented Mar 7, 2024

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
Copy link
Owner

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
Copy link
Contributor Author

lutejka commented Apr 24, 2024

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
Copy link
Contributor Author

lutejka commented Apr 24, 2024

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)

@criisv7
Copy link

criisv7 commented Aug 31, 2024

Facing the same issue. Is there a fix for it in place or any bypass. @harlan-zw

@olivoil
Copy link

olivoil commented Sep 5, 2024

I am seeing the same error message

ERROR Failed to set cookies Protocol error (Network.deleteCookies): Target closed

@harlan-zw
Copy link
Owner

So the issue with this error is that it's trying to deleteCookies after it has closed the tab. This can happen when the tab fails to initially open.

In v0.12.0 we have a soft error handler on this as it should be fine to fail.

If someone can provide a reproduction then I can investigate this further otherwise will need to close for now as cookies can be set.

@harlan-zw harlan-zw closed this as not planned Won't fix, can't repro, duplicate, stale Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants