Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/319902

Change subject: Don't report stats when page visibility changes during page load
......................................................................

Don't report stats when page visibility changes during page load

Browsers sometime defer or deprioritize painting or executing code on
pages that load in the background (for example, in an inactive browser
tab). We don't want to report metrics in these cases, because a slow
page load is not necessarily a bad thing if it is invisible to the user
and if the slowdown is in service of making some operation that is
user-facing quicker.

I don't want to worry about vendor prefixes or visibility changes that
may happen before NavigationTiming has the chance to bind the handler.
The code in this patch should catch the common case, and we should be
able to tell from its impact (or lack thereof) on our metrics whether it
is worth the extra effort to control for visibility changes in all
possible cases.

Change-Id: I8e8ec96fc99f1e38d254f421c5f48cb313ba36e5
---
M modules/ext.navigationTiming.js
1 file changed, 10 insertions(+), 1 deletion(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/NavigationTiming 
refs/changes/02/319902/1

diff --git a/modules/ext.navigationTiming.js b/modules/ext.navigationTiming.js
index 5c45e64..42908a9 100644
--- a/modules/ext.navigationTiming.js
+++ b/modules/ext.navigationTiming.js
@@ -9,12 +9,21 @@
        'use strict';
 
        var timing, navigation, mediaWikiLoadEnd,
+               visibilityChanged = false,
                TYPE_NAVIGATE = 0;
+
 
        if ( window.performance ) {
                timing = performance.timing;
                navigation = performance.navigation;
        }
+
+       // Don't report measurements for pages that have loaded in the 
background.
+       // Browsers defer or deprioritize loading background pages, causing 
them to
+       // take longer to load, which throws off our measurements.
+       $( document ).one( 'visibilitychange', function () {
+               visibilityChanged = true;
+       } );
 
        function inSample() {
                var factor = mw.config.get( 'wgNavigationTimingSamplingFactor' 
);
@@ -234,7 +243,7 @@
 
        // Ensure we run after loadEventEnd.
        onLoadComplete( function () {
-               if ( inSample() ) {
+               if ( inSample() && !visibilityChanged ) {
                        emitNavigationTiming();
                }
                mw.hook( 'postEdit' ).add( emitSaveTiming );

-- 
To view, visit https://gerrit.wikimedia.org/r/319902
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8e8ec96fc99f1e38d254f421c5f48cb313ba36e5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/NavigationTiming
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to