abhinaba-ghosh / playwright-lighthouse

:performing_arts:: Playwright Lighthouse Audit
https://www.npmjs.com/package/playwright-lighthouse
MIT License
250 stars 28 forks source link

Second browser window is opening. #82

Open ZurabKV opened 6 months ago

ZurabKV commented 6 months ago

Hello. We were trying to update version of playwright-lighthouse from 2.2.2 to 4.0.0. Older version of the package ran lighthouse audit in the same browser window and it worked well. New version of lighthouse additionally openes new browser window when running function playAudit(). Is there a way to prevent this from happening and perform the audit in the initial browser window?

New browser window doesn't have necessary cookies (and maybe some other storage data?) which causes the page to open with errors. I found a way to pass necessary cookies to the second browser: return playAudit({

return playAudit({
  ...
  opts: {
    logLevel: 'debug',
    extraHeaders: {
      Cookie: 'cookie1=val1;cookie2=val2...'
    }
  }
  ...
}); 

And it did partially help to resolve the issue. Partially, because it passed all the cookies, apart from one. My guess is it is because that specific cookie contained = sybol inside its value, perhaps this somehow prevents the cookie to be added to the 2nd browser?

gurjitmehta03 commented 6 months ago

@ZurabKV Facing the same issue

veritoneadam commented 4 months ago

Same issue, additional consequences.

I'm running a11y audits on a page generated from a form submission (POST). Because playAudit is re-loading the page itself, it does a GET to the url and loses the form context.

await page.route('https://example.com/form-endpoint', (route, request) => {
  const method = 'POST';
  const postData = 'key=value';
  route.continue({ method, postData });
});

await page.goto('https://example.com/form-endpoint'); // works ok
await playAudit({
  page,
  thresholds: {accessibility: 99},
  opts: {onlyCategories: ['accessibility']},
}); // does GET request & reloads the page

It's like running lighthouse in chrome in 'Navigation' mode instead of 'Snapshot'? Could this be fixed via https://github.com/abhinaba-ghosh/playwright-lighthouse/pull/44 ?

alphonse92 commented 3 months ago

Facing the same issue, this repo seems poor maintained

mckeckers commented 1 month ago

Same issue here. Sadly, this makes temporal testing impossible with Playwright which, for me, is the big selling point of LightHouse. I had to revert back several versions to get this working.

"lighthouse": "^9.6.8", "@lighthousejs/types": "^0.0.3", "playwright-lighthouse": "^2.2.2",

As Playwright is now the most popular test framework, it would be good to see the Lighthouse plugin maintained for this.