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
Reporting CLS and LCP in a lab environment using Playwright is flakey / unreliable #180
Comments
This is expected, see this explanation in the README. CLS is measured through the lifespan of the page, so it's impossible to know the final CLS value until the page is unloaded. For more context on why LCP is reported after user interactions, see: When is largest contentful paint reported. My suggestion is to initiate page unload, and that should trigger reporting of all the metrics. |
@philipwalton thanks for pointing me in the right direction. If I extend the above example with the code beneath it seems to help a lot. The ...
await page.goto("https://checklyhq.com")
await page.close({ runBeforeUnload: true })
await page.waitForTimeout(100)
await browser.close() output:
|
FYI, if you're curious, you can read more here about why we use |
@tnolet Hi, |
@AndreyMelnichenko this is quite a bit of code, now part of our private code base. In essence, most Playwright or Puppeteer sessions are too quick. Maybe @danielpaulus could chime in here, as he coded most of our solution. |
@philipwalton, Hello! Looks like pagehide and visibilitychange have different order - whatwg/html#3957 And, if we send beacon in So, what is the recommended and crossbrowser way to collect all metrics, when page just was closed? |
As I understand right, and with |
You should be reporting data when the callback is invoked, not separately from when the callback is invoked. If you want to just report yourself and not depend on the |
Our approach is close to this reciepe with batching - https://github.com/GoogleChrome/web-vitals#batch-multiple-reports-together, it will be work together only with And is there any disadvantages if we will use |
That approach will work fine with |
Thanks a lot for the answer, and of course for the great library) |
Maybe found a one problem - with And the problem is that after, CLS never called. |
Note that CLS should not be reported if FCP hasn't been reported (including when pages are opened in a background tab), so this is working as intended. I don't think the behavior here is different between when |
With If it is wrong behaviour, can try to make a reproduction repo) |
For me it is wrong, because no chance to measure CLS, if CLS called before FCP for some reasons |
Found, it was because I also add |
I'm trying to repro this cannot. Can you confirm that you're running the latest version (3.1.0)? |
Yes, 3.1.0 version. It was hard to investigate, problem is not in Steps to reproduce:
First CLS will be calculated before FCP, this code will be called and nothing reported because FCP is After, this code will be called and CLS value is larger than Here is reproduction: https://codesandbox.io/s/cranky-snyder-6lvs5f?file=/src/routes/index.tsx |
Thanks for the repro! I was also able to repro this on my own test pages using your instructions. Looks like the missing test case was waiting until after paint and the first shift to invoke the I've been experimenting with a fix and can hopefully publish it in the next few days. |
Thanks a lot!) |
Hi,
we are bumping into an issue where we want to gather some web vitals using this library in a lab environment. We are using Playwright for this and injecting the
web-vitals
code into the browser context. Injecting and instrumenting works fine, but we are getting intermittent issues with some metrics not reporting.Specifically:
Conversely, FCP and TTFB are pretty reliable.
My question is: is this expected, or are we missing something? Could this be some race condition we can avoid?
Here is an reproducable example. The
web-vitals
UMD module is inlined. The only external dependency is PlaywrightThe typical output from this code looks like:
The text was updated successfully, but these errors were encountered: