2 * Code in this file MUST work on even the most ancient of browsers!
4 * This file is where we decide whether to initialise the modern run-time.
7 /* global mw, $VARS, $CODE */
9 var mwPerformance
= ( window
.performance
&& performance
.mark
) ? performance
: {
12 // Define now() here to ensure valid comparison with mediaWikiLoadEnd (T153819).
13 mwNow
= ( function () {
14 var perf
= window
.performance
,
15 navStart
= perf
&& perf
.timing
&& perf
.timing
.navigationStart
;
16 return navStart
&& typeof perf
.now
=== 'function' ?
17 function () { return navStart
+ perf
.now(); } :
18 function () { return Date
.now(); };
20 // eslint-disable-next-line no-unused-vars
21 mediaWikiLoadStart
= mwNow();
23 mwPerformance
.mark( 'mwLoadStart' );
26 * See <https://www.mediawiki.org/wiki/Compatibility#Browsers>
28 * Capabilities required for modern run-time:
30 * - DOM Level 4 & Selectors API Level 1
31 * - HTML5 & Web Storage
32 * - DOM Level 2 Events
34 * Browsers we support in our modern run-time (Grade A):
40 * - Mobile Safari 5.1+ (iOS 5+)
43 * Browsers we support in our no-javascript run-time (Grade C):
49 * - Mobile Safari 5.0+ (iOS 4+)
53 * - Symbian-based browsers
54 * - NetFront-based browser
56 * - Nokia's Ovi Browser
59 * - UC Mini (speed mode on)
61 * Other browsers that pass the check are considered Grade X.
63 * @param {string} [str] User agent, defaults to navigator.userAgent
64 * @return {boolean} User agent is compatible with MediaWiki JS
66 function isCompatible( str
) {
67 var ua
= str
|| navigator
.userAgent
;
69 // http://caniuse.com/#feat=es5
70 // http://caniuse.com/#feat=use-strict
71 // http://caniuse.com/#feat=json / https://phabricator.wikimedia.org/T141344#2784065
74 return !this && !!Function
.prototype.bind
&& !!window
.JSON
;
77 // http://caniuse.com/#feat=queryselector
78 'querySelector' in document
&&
80 // http://caniuse.com/#feat=namevalue-storage
81 // https://developer.blackberry.com/html5/apis/v1_0/localstorage.html
82 // https://blog.whatwg.org/this-week-in-html-5-episode-30
83 'localStorage' in window
&&
85 // http://caniuse.com/#feat=addeventlistener
86 'addEventListener' in window
&&
88 // Hardcoded exceptions for browsers that pass the requirement but we don't want to
89 // support in the modern run-time.
90 // Note: Please extend the regex instead of adding new ones
92 ua
.match( /webOS\/1\.[0-4]|SymbianOS|Series60|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass|^Mozilla\/5\.0 .+ Gecko\/$|googleweblight/ ) ||
93 ua
.match( /PlayStation/i )
98 // Conditional script injection
101 if ( !isCompatible() ) {
102 // Undo class swapping in case of an unsupported browser.
103 // See ResourceLoaderClientHtml::getDocumentAttributes().
104 document
.documentElement
.className
= document
.documentElement
.className
105 .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
107 NORLQ
= window
.NORLQ
|| [];
108 while ( NORLQ
.length
) {
112 push: function ( fn
) {
117 // Clear and disable the other queue
127 * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
130 mw
.config
= new mw
.Map( $VARS
.wgLegacyJavaScriptGlobals
);
132 $CODE
.registrations();
134 mw
.config
.set( $VARS
.configuration
);
136 // Must be after mw.config.set because these callbacks may use mw.loader which
137 // needs to have values 'skin', 'debug' etc. from mw.config.
138 // eslint-disable-next-line vars-on-top
139 var RLQ
= window
.RLQ
|| [];
140 while ( RLQ
.length
) {
144 push: function ( fn
) {
149 // Clear and disable the other queue
156 script
= document
.createElement( 'script' );
157 script
.src
= $VARS
.baseModulesUri
;
158 script
.onload
= script
.onreadystatechange = function () {
159 if ( !script
.readyState
|| /loaded|complete/.test( script
.readyState
) ) {
161 script
.onload
= script
.onreadystatechange
= null;
167 document
.getElementsByTagName( 'head' )[ 0 ].appendChild( script
);