I’m curious if running an FPS counter in a Playwright/Puppeteer test suite that throws when the FPS drops below a threshold, like 60fps, is that a useful canary to alert when a part of the interface needs performance work.
Here’s an example of something like the FPS counter I’m wanting to implement within the browser context:
// Options
const decimalPlaces    = 2;
const updateEachSecond = 1;
// Cache values
const decimalPlacesRatio = Math.pow(10, decimalPlaces);
let timeMeasurements     = [];
// Final output
let fps = 0;
const tick = function() {
  timeMeasurements.push(performance.now());
  const msPassed = timeMeasurements[timeMeasurements.length - 1] - timeMeasurements[0];
  if (msPassed >= updateEachSecond * 1000) {
    fps = Math.round(timeMeasurements.length / msPassed * 1000 * decimalPlacesRatio) / decimalPlacesRatio;
    timeMeasurements = [];
  }
  if ( fps > 60 ) {
      // Throw to Puppeteer or Playwright
  }
  requestAnimationFrame(() => {
    tick();
  });
}
tick();
Original: https://stackoverflow.com/a/52727222/1397641
Ideally I’d love an FPS counter on as many tests as possible that tells me when a part of the user experience is too sluggish before it gets deployed to the user.
I know using performance.now() is better than Date.now(), but I'm uncertain how to make sure the test environment is similar or slightly slower than a target user device.
For example: Is puppeteer running on a build process like Netlify or Vercel comparable to a user device like a 5 year old Android device?
Can I add throttles to make the test more realistic or even less powerful than a user device so that the FPS test fails slightly before users devices would?
It might be useful depending on what kind of app/site you are testing. Such a feature probably does not need to be enabled by default. How it can be implemented:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With