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

PlayAudit function call is closing the browser automatically after analysis #53

Open
sbettego opened this issue Jul 26, 2023 · 7 comments

Comments

@sbettego
Copy link

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",

@geeky4u
Copy link

geeky4u commented Jul 27, 2023

I am facing the same problem using the same versions of lighthouse and playwright-lighthouse. Would love to see some solution for this.

@apahilajani-ontra
Copy link

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.

@Swaroop-bgowda
Copy link

@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.

@andrew-hossack
Copy link

Any updates on this please?

@kmcgon
Copy link

kmcgon commented Sep 12, 2023

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,
    });

@taohoangdn
Copy link

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

@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?

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

8 participants