Ori.livneh has uploaded a new change for review. https://gerrit.wikimedia.org/r/100951
Change subject: Add 'mediaWikiLoadComplete' measurement ...................................................................... Add 'mediaWikiLoadComplete' measurement Log the time from mediaWikiLoadStart to first script execution yield following $( window ).load. Depends on changes I3d5bcf10e and I8c7af097e in MediaWiki. Also bumps schema version to 6703470. Change-Id: I933a1e3a20c1c2e03955c310ff62d9b8b44ca7d1 --- M .jshintrc M NavigationTiming.php M modules/ext.navigationTiming.js 3 files changed, 53 insertions(+), 31 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/NavigationTiming refs/changes/51/100951/1 diff --git a/.jshintrc b/.jshintrc index d6cc052..1473c66 100644 --- a/.jshintrc +++ b/.jshintrc @@ -4,6 +4,7 @@ "QUnit", "jQuery", "mediaWiki", + "mediaWikiStart", "performance" ], diff --git a/NavigationTiming.php b/NavigationTiming.php index 2f0a687..8eb9768 100644 --- a/NavigationTiming.php +++ b/NavigationTiming.php @@ -35,7 +35,7 @@ 'schema.NavigationTiming' => array( 'class' => 'ResourceLoaderSchemaModule', 'schema' => 'NavigationTiming', - 'revision' => 5832704, + 'revision' => 6703470, 'targets' => array( 'desktop', 'mobile' ), ), 'ext.navigationTiming' => array( diff --git a/modules/ext.navigationTiming.js b/modules/ext.navigationTiming.js index f17f4bf..c6e196d 100644 --- a/modules/ext.navigationTiming.js +++ b/modules/ext.navigationTiming.js @@ -35,6 +35,17 @@ 'connectStart' ]; + if ( !timing ) { + // Browser does not implement the Navigation Timing API. + return false; + } + + if ( /Firefox\/[78]/.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 ) { @@ -45,25 +56,12 @@ return true; } - function emitTiming() { + function getNavTiming() { // Workaround for IE 9 bug: IE 9 sets a default value of zero for // navigationStart, rather than use fetchStart as the specification // requires. See <https://bugzilla.wikimedia.org/46474> for details. var navStart = timing.navigationStart || timing.fetchStart, - event = { - userAgent : navigator.userAgent, - isHttps : location.protocol === 'https:', - isAnon : mw.config.get( 'wgUserId' ) === null - }, - page = { - pageId : mw.config.get( 'wgArticleId' ), - revId : mw.config.get( 'wgCurRevisionId' ), - action : mw.config.get( 'wgAction' ) // view, submit, etc. - }; - - if ( $.isPlainObject( window.Geo ) && typeof Geo.country === 'string' ) { - event.originCountry = Geo.country; - } + timingData = {}; $.each( [ 'connectEnd', @@ -79,19 +77,42 @@ ], function ( _, marker ) { var measure = timing[marker] - navStart; if ( $.isNumeric( measure ) && measure > 0 ) { - event[ marker ] = measure; + timingData[ marker ] = measure; } } ); if ( timing.domainLookupStart ) { - event.dnsLookup = timing.domainLookupEnd - timing.domainLookupStart; + timingData.dnsLookup = timing.domainLookupEnd - timing.domainLookupStart; } if ( timing.redirectStart ) { - event.redirectCount = performance.navigation.redirectCount; - event.redirecting = timing.redirectEnd - timing.redirectStart; + timingData.redirectCount = performance.navigation.redirectCount; + timingData.redirecting = timing.redirectEnd - timing.redirectStart; } + return timingData; + } + + function emitTiming() { + var event = { + userAgent : navigator.userAgent, + isHttps : location.protocol === 'https:', + isAnon : mw.config.get( 'wgUserId' ) === null + }, + page = { + pageId : mw.config.get( 'wgArticleId' ), + revId : mw.config.get( 'wgCurRevisionId' ), + action : mw.config.get( 'wgAction' ) // view, submit, etc. + }; + + if ( window.mediaWikiLoadStart ) { + event.mediaWikiLoadComplete = mw.now() - mediaWikiLoadStart; + } + + if ( $.isPlainObject( window.Geo ) && typeof Geo.country === 'string' ) { + event.originCountry = Geo.country; + } + // Omit page information for special pages: they don't have real page // IDs or revisions. (They appear as 0 to client-side code.) if ( page.revId ) { @@ -102,23 +123,23 @@ event.mobileMode = mw.config.get( 'wgMFMode' ); } - if ( isCompliant() ) { - mw.eventLog.logEvent( 'NavigationTiming', event ); + // The Navigation Timing API provides an attribute that can be used to + // know if a page load was triggered by link click or manual URL entry + // vs. by using the back/forward button or by reloading the page. A + // value of 0 corresponds with TYPE_NAVIGATENEXT, which indicates a + // normal page load. + if ( isCompliant() && performance.navigation.type === 0 ) { + $.extend( event, getNavTiming() ); } + + mw.eventLog.logEvent( 'NavigationTiming', event ); } - // The Navigation Timing API is broken in Firefox 7 and 8 and reports - // inaccurate measurements. See <https://bugzilla.mozilla.org/691547>. - - if ( timing - && performance.navigation.type === 0 - && inSample() - && !/Firefox\/[78]/.test( navigator.userAgent ) - ) { + if ( inSample() ) { // ensure we run after loadEventEnd. $( window ).load( function () { setTimeout( emitTiming, 0 ); } ); } -} ( mediaWiki, jQuery ) ); +} ( mediaWiki, jQuery ) ) -- To view, visit https://gerrit.wikimedia.org/r/100951 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I933a1e3a20c1c2e03955c310ff62d9b8b44ca7d1 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