Bug 1496226 - Be sure raptor's capturing of first-contentful-paint in google chrome is the correct entry; r=jmaher
authorRob Wood <rwood@mozilla.com>
Mon, 15 Oct 2018 15:43:13 +0000
changeset 489674 e742cc754ebc1a989ab174e26ba29001fecfef7a
parent 489657 84ceb42728e4509c23f5167eb0ef166986efad4a
child 489675 ddd7b581697d9ccff863b6901ef9e01e5772b2e4
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjmaher
bugs1496226
milestone64.0a1
Bug 1496226 - Be sure raptor's capturing of first-contentful-paint in google chrome is the correct entry; r=jmaher Differential Revision: https://phabricator.services.mozilla.com/D8731
testing/raptor/webext/raptor/measure.js
--- a/testing/raptor/webext/raptor/measure.js
+++ b/testing/raptor/webext/raptor/measure.js
@@ -76,17 +76,17 @@ function setup(settings) {
       measureDCF();
     }
   }
 
   if (settings.measure.fcp !== undefined) {
     getFCP = settings.measure.fcp;
     if (getFCP) {
       console.log("will be measuring first-contentful-paint");
-      measureFirstContentfulPaint();
+      measureFCP();
     }
   }
 
   if (settings.measure.hero !== undefined) {
     if (settings.measure.hero.length !== 0) {
       getHero = true;
       heroesToCapture = settings.measure.hero;
       console.log("hero elements to measure: " + heroesToCapture);
@@ -219,38 +219,38 @@ function measureTTFI() {
       window.setTimeout(measureTTFI, 200);
     } else {
       // unable to get a value for TTFI - filter out later
       sendResult("ttfi", 0);
     }
   }
 }
 
-function measureFirstContentfulPaint() {
+function measureFCP() {
   // see https://developer.mozilla.org/en-US/docs/Web/API/PerformancePaintTiming
   var resultType = "fcp";
   var result = 0;
 
-  let performanceEntries = perfData.getEntriesByType("paint");
+  let perfEntries = perfData.getEntriesByType("paint");
 
-  if (performanceEntries.length >= 2) {
-    if (performanceEntries[1].startTime != undefined)
-      result = performanceEntries[1].startTime;
+  if (perfEntries.length >= 2) {
+    if (perfEntries[1].name == "first-contentful-paint" && perfEntries[1].startTime != undefined)
+      result = perfEntries[1].startTime;
   }
 
   if (result > 0) {
     console.log("got time to first-contentful-paint");
     sendResult(resultType, result);
     perfData.clearMarks();
     perfData.clearMeasures();
   } else {
     gRetryCounter += 1;
     if (gRetryCounter <= 10) {
       console.log("\ntime to first-contentful-paint is not yet available (0), retry number " + gRetryCounter + "...\n");
-      window.setTimeout(measureFirstContentfulPaint, 100);
+      window.setTimeout(measureFCP, 100);
     } else {
       console.log("\nunable to get a value for time-to-fcp after " + gRetryCounter + " retries\n");
     }
   }
 }
 
 function sendResult(_type, _value) {
   // send result back to background runner script