jmarantz commented on a change in pull request #1802: Prefer Paint Timing API 
over chrome.loadTimes()
URL: 
https://github.com/apache/incubator-pagespeed-mod/pull/1802#discussion_r225510986
 
 

 ##########
 File path: net/instaweb/rewriter/add_instrumentation.js
 ##########
 @@ -88,21 +88,30 @@ pagespeed.AddInstrumentation.prototype.sendBeacon = 
function() {
         timingApi['responseEnd'] - timingApi['responseStart']);
     url += '&dom_c=' + (timingApi['domContentLoadedEventStart'] - 
navStartTime);
 
-    if (window['performance']['navigation']) {
-      url += '&nt=' + window['performance']['navigation']['type'];
+    if (winPerf['navigation']) {
+      url += '&nt=' + winPerf['navigation']['type'];
     }
     var firstPaintTime = -1;
+    var paintEntries, loadTimes;
     if (timingApi['msFirstPaint']) {
       // IE.
       firstPaintTime = timingApi['msFirstPaint'];
-    } else if (window['chrome'] && window['chrome']['loadTimes']) {
+    } else if (winPerf['timeOrigin'] &&
+        winPerf['getEntriesByType'] &&
+        (paintEntries = winPerf['getEntriesByType']('paint')).length > 0) {
+        // Paint Timing API
+        // Note that getEntriesByType('paint') is sorted chronologically
+        firstPaintTime = Math.round(
+            winPerf['timeOrigin'] +
+            paintEntries[0]['startTime']);
+    } else if ((loadTimes = window['chrome']) && (loadTimes = 
loadTimes['loadTimes'])) {
       // Chrome. Note that window.chrome.loadTimes returns a time in seconds.
-      firstPaintTime = Math.floor(
-          window['chrome']['loadTimes']()['firstPaintTime'] * 1000);
+      firstPaintTime = Math.round(
+          loadTimes()['firstPaintTime'] * 1000);
     }
-    firstPaintTime = firstPaintTime - requestStartTime;
-    if (firstPaintTime >= 0) {
-      url += '&fp=' + firstPaintTime;
+    timeToFirstPaint = firstPaintTime - requestStartTime;
 
 Review comment:
   var

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to