Ori.livneh has uploaded a new change for review. https://gerrit.wikimedia.org/r/237320
Change subject: Small clean-ups ...................................................................... Small clean-ups * Fold getPaintTiming() into getNavTiming(). It's less code that way. * Don't check for window.timing in onLoadComplete, since we already have an alias for that in module scope (timing). * Remove check for Firefox 7/8. This bug was fixed in 2011 and any stragglers in the wild would fail the compliance check anyway. * Unroll the loop in inCompliant(). Change-Id: I62647b284d2728ed05b7d5532b36b1094018c99b --- M modules/ext.navigationTiming.js 1 file changed, 20 insertions(+), 58 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/NavigationTiming refs/changes/20/237320/1 diff --git a/modules/ext.navigationTiming.js b/modules/ext.navigationTiming.js index 72410cb..74824e1 100644 --- a/modules/ext.navigationTiming.js +++ b/modules/ext.navigationTiming.js @@ -27,58 +27,19 @@ function isCompliant() { // Tests derived from <http://w3c-test.org/web-platform-tests/ // master/navigation-timing/test_timing_attributes_order.html> - var attr, current, - last = 0, - order = [ - 'loadEventEnd', - 'loadEventStart', - 'domContentLoadedEventEnd', - 'domContentLoadedEventStart', - 'domInteractive', - 'responseEnd', - 'responseStart', - 'requestStart', - 'connectEnd', - 'connectStart' - ]; - - if ( !timing || !performance ) { - // Browser does not implement the Navigation Timing API. - return false; - } - - if ( /Firefox\/[78]\b/.test( navigator.userAgent ) ) { - // The Navigation Timing API is broken in Firefox 7 and 8 and reports - // inaccurate measurements. See <https://bugzilla.mozilla.org/691547>. - return false; - } - - while ( ( attr = order.pop() ) !== undefined ) { - current = timing[ attr ]; - if ( current < 0 || current < last ) { - return false; - } - last = current; - } - return true; - } - - function getPaintTiming() { - var firstPaint, relativeTo; - - if ( window.chrome && $.isFunction( chrome.loadTimes ) ) { - // Chrome - firstPaint = chrome.loadTimes().firstPaintTime * 1000; - relativeTo = chrome.loadTimes().startLoadTime * 1000; - } else if ( timing && timing.msFirstPaint ) { - // Internet Explorer 9+ (<http://msdn.microsoft.com/ff974719>) - firstPaint = timing.msFirstPaint; - relativeTo = timing.navigationStart; - } - - if ( firstPaint > relativeTo ) { - return { firstPaint: Math.round( firstPaint - relativeTo ) }; - } + return ( + timing + && timing.loadEventEnd >= timing.loadEventStart + && timing.loadEventStart >= timing.domContentLoadedEventEnd + && timing.domContentLoadedEventEnd >= timing.domContentLoadedEventStart + && timing.domContentLoadedEventStart >= timing.domInteractive + && timing.domInteractive >= timing.responseEnd + && timing.responseEnd >= timing.responseStart + && timing.responseStart >= timing.requestStart + && timing.requestStart >= timing.connectEnd + && timing.connectEnd >= timing.connectStart + && timing.connectStart >= 0 + ); } function getNavTiming() { @@ -123,7 +84,12 @@ timingData.redirecting = timing.redirectEnd - timing.redirectStart; } - $.extend( timingData, getPaintTiming() ); + if ( timing.msFirstPaint > navStart ) { + timingData.firstPaint = timing.msFirstPaint - navStart; + } else if ( window.chrome && $.isFunction( chrome.loadTimes ) ) { + timingData.firstPaint = Math.round( 1000 * + ( chrome.loadTimes().firstPaintTime - chrome.loadTimes().startLoadTime ) ); + } return timingData; } @@ -190,11 +156,7 @@ function onLoadComplete( callback ) { mw.hook( 'resourceloader.loadEnd' ).add( function () { var timer = setInterval( function () { - if ( - !window.performance || - !performance.timing || - performance.timing.loadEventEnd > 0 - ) { + if ( !timing || timing.loadEventEnd > 0 ) { clearInterval( timer ); callback(); } -- To view, visit https://gerrit.wikimedia.org/r/237320 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I62647b284d2728ed05b7d5532b36b1094018c99b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/NavigationTiming Gerrit-Branch: master Gerrit-Owner: Ori.livneh <o...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits