diff --git i/modules/ext.wikimediaEvents.httpsSupport.js w/modules/ext.wikimediaEvents.httpsSupport.js index fee3b94265..8b174b2d8e 100644 --- i/modules/ext.wikimediaEvents.httpsSupport.js +++ w/modules/ext.wikimediaEvents.httpsSupport.js @@ -10,7 +10,7 @@ ( function ( mw, $ ) { 'use strict'; - var pixelSrc = '//upload.wikimedia.org/wikipedia/commons/c/c0/Blank.gif'; + var pixelSrc = '//performance.wikimedia.org/blank.gif'; function inSample() { var factor = mw.config.get( 'wgHttpsFeatureDetectionSamplingFactor' ); @@ -23,6 +23,15 @@ return Math.floor( Math.random() * factor ) === 0; } + // Return a deferred object that is resolved after `ms` milliseconds. + function sleep( ms ) { + var defer = $.Deferred(); + setTimeout( function () { + defer.resolve(); + }, ms ); + return defer; + } + function pingProtocol( proto, timeout ) { var $beacon = $( '' ), defer = $.Deferred(); @@ -34,24 +43,34 @@ $beacon.attr( 'src', proto + ':' + pixelSrc + '?' + new Date() ); return defer.then( function () { - var ok = this.type === 'load' && $beacon.prop( 'width' ) === 1; - return ok ? 'success' : this.type; + var status = {}, ok = this.type === 'load' && $beacon.prop( 'width' ) === 1; + status[proto + 'Status'] = ok ? 'success' : this.type; + return status; } ); } + // Log only if user is using HTTP and is included in the random sample. if ( window.location.protocol !== 'https:' && inSample() ) { mw.loader.using( 'schema.HttpsSupport', function () { + var protocols = [ 'http', 'https' ]; + + // Flip the order of tests 50% of the time. + if ( Math.floor( Math.random() * 2 ) ) { + protocols.reverse(); + } + $.when( - pingProtocol( 'http' ), - pingProtocol( 'https' ) - ).done( function ( httpStatus, httpsStatus ) { - var event = { - httpStatus : httpStatus, - httpsStatus : httpsStatus, + pingProtocol( protocols.pop() ), + pingProtocol( protocols.pop() ), + sleep( 6000 ) + ).done( function ( firstStatus, secondStatus ) { + console.log('in callback'); + var event = $.extend( { isAnon : mw.config.get( 'wgUserId' ) === null, userAgent : navigator.userAgent - }; + }, firstStatus, secondStatus ); + if ( mw.mobileFrontend && mw.config.exists( 'wgMFMode' ) ) { event.mobileMode = mw.config.get( 'wgMFMode' ); }