I have been using PerformanceObserver
API with PlayWright
to capture several metrics in my application which. My application has multiple browser instances on Button/link clicks. Metrics like FCP
, LCP
, TTFB
are getting captured while the pages are navigated for first time. Metrics like LongTask
and CLS
are getting updated whenever the page is reloaded.
For example once I login to the application, for the home page I have captured FCP
, LCP
and TTFB
. There is a link on the home page on clicking it, another browser window opens, after filling details in that page and clicking on Finish button the home page refreshes. Here is the real problem. When I access the Metrics again in the home page, all the metric values are same apart from LongTask
and CLS
. So in this case how can I avoid capturing the metrics again if there is no change in their values?
I have created fixture
in PlayWright
to capture metrics which has all metrics to be captured. Below code is inside the function and gets called whenever a new page is opened or closed.
const perfMetrics = new PerformanceMetrics(page.mainFrame());
const pageLevelTotalBlockingTime = await perfMetrics.totalBlockingTime(transactionName);
const pagePaintTiming = await perfMetrics.paintTiming(transactionName);
const pageLevelLargeContentfulPaint = await perfMetrics.largestContentfulPaint(transactionName);
const pageNavigationTime = await perfMetrics.navigationTime(transactionName);
const resourceTiming = await perfMetrics.resourceTime(transactionName);
const pageLevelCLS = await perfMetrics.cumulativeShift(transactionName)