treosh / lighthouse-ci-action

Audit URLs using Lighthouse and test performance with Lighthouse CI.
MIT License
1.15k stars 81 forks source link

Adding a cookie to the request #133

Open arishoham opened 11 months ago

arishoham commented 11 months ago

I need to add a cookie to the page request when lighthouse runs, I tried using extraHeaders in lighthouserc.json like so, but it seems to have no effect. Is there another way to accomplish this?

{
  "ci": {
    "collect": {
      "settings": {
        "chromeFlags": "--no-sandbox --no-zygote --headless --ignore-certificate-errors --disable-dev-shm-usage --max-wait-for-load=30000",
        "extraHeaders": "{\"Cookie\": \"foo=true\"}",
      }
    }
  }
}
KaiDoering commented 11 months ago

You could also try to use a puppeteer script for this like

/**
 * @param {puppeteer.Browser} browser
 * @param  context
 */
module.exports = async (browser, context) => {
    const page = await browser.newPage();
    await page.setCookie({
        name: 'cookie-test',
        value: 'true',
        domain: 'example.com',
    });
    await page.close();
};
JackG102 commented 2 months ago

I was able to send a cookie value using lighthouserc.json. In a non-prod environment, we check for the presence of a certain cookie and a value to allow access to the website. The code below allowed lighthouse to do the scans. If it had no effect, I also would double check in the Github Actions workflow that the config path to the json file is set up: configPath: .github/workflows/lighthouserc.json under the with: key

{
  "ci": {
    "collect": {
      "settings": {
        "extraHeaders": {
          "COOKIE": "cookie_name=value_of_cookie"
        }
      }
    },
    "assert": {

    },
    "upload": {

    },
    "server": {

    },
    "wizard": {

    }
  }
}