Open sbettego opened 1 year ago
I am facing the same problem using the same versions of lighthouse and playwright-lighthouse. Would love to see some solution for this.
Hello,
Would love to have this feature as well, i.e. don't close the page automatically once the playAudit function completes. May be an optional additional argument to this function to decide whether to close or leave the page open would be great.
@abhinaba-ghosh , can we have this optional argument within playAduit function to keep the browser alive so that the next user-action can take place and we can call the audit function again. This would help mostly when integrating playwright-lighthouse in existing E2E scripts strategically. keepBrowserAlive: true,. Please comment and let us know your thoughts for any work-arounds.
Any updates on this please?
I ran into this when when I was trying to attach the lighthouse report artifact to the Playwright report. playAudit
throws an error when the thresholds aren't met, which will fail the test and not execute the next step.
My workaround was the wrap the playAudit
call in a try/catch like this:
try {
await playAudit({ ... })
await testInfo.attach({..})
} catch (error) {
await testInfo.attach({..})
}
Alternatively, you might be able to adjust the score thresholds to a lower setting, so an error won't be raised (I haven't tested this).
await playAudit({
page: page,
thresholds: {
performance: 0,
accessibility: 0,
'best-practices': 0,
seo: 0,
pwa: 0,
},
port: 9222,
});
You can use as following await playAudit({ url: page.url(), page: await context.newPage(), }); It will run playAudit execution on the new tab
@abhinaba-ghosh , can we have this optional argument within playAduit function to keep the browser alive so that the next user-action can take place and we can call the audit function again. This would help mostly when integrating playwright-lighthouse in existing E2E scripts strategically. keepBrowserAlive: true,. Please comment and let us know your thoughts for any work-arounds.
hey @Swaroop-bgowda , good idea. would you mind raising a PR?
Hi All, we are trying to perform analysis on a single page application and we want to use Playwright-lighthouse as a utility by calling it in multiple stages within our test script.
Sample:
Before all { browser initiation }
test {
goto(url); await playaudit{} locator().click(); await playaudit{}
};
Problem is once the URL is opened and playaudit is performed the browser is automatically closing leading to which the locator().click() is throwing Error: locator.click: Target page, context or browser has been closed error.
I'm currently using downgraded version of lightHouse & playwright-lighthouse due to existing import issue in latest versions. "@playwright/test": "^1.35.1", "lighthouse": "^9.6.8", "playwright-lighthouse": "^2.2.2",