2 * This file is where we decide whether to initialise the Grade A run-time.
4 * - Beware: This file MUST parse without errors on even the most ancient of browsers!
5 * - Beware: Do not call mwNow before the isCompatible() check.
8 /* global mw, $VARS, $CODE */
10 var mwPerformance
= ( window
.performance
&& performance
.mark
) ? performance
: {
13 // Define now() here to ensure valid comparison with mediaWikiLoadEnd (T153819).
14 mwNow
= ( function () {
15 var perf
= window
.performance
,
16 navStart
= perf
&& perf
.timing
&& perf
.timing
.navigationStart
;
17 return navStart
&& typeof perf
.now
=== 'function' ?
18 function () { return navStart
+ perf
.now(); } :
19 function () { return Date
.now(); };
21 // eslint-disable-next-line no-unused-vars
25 * See <https://www.mediawiki.org/wiki/Compatibility#Browsers>
27 * Capabilities required for modern run-time:
29 * - DOM Level 4 & Selectors API Level 1
30 * - HTML5 & Web Storage
31 * - DOM Level 2 Events
33 * Browsers we support in our modern run-time (Grade A):
39 * - Mobile Safari 5.1+ (iOS 5+)
42 * Browsers we support in our no-javascript run-time (Grade C):
48 * - Mobile Safari 5.0+ (iOS 4+)
52 * - Symbian-based browsers
53 * - NetFront-based browser
55 * - Nokia's Ovi Browser
58 * - UC Mini (speed mode on)
60 * Other browsers that pass the check are considered Grade X.
62 * @param {string} [str] User agent, defaults to navigator.userAgent
63 * @return {boolean} User agent is compatible with MediaWiki JS
65 function isCompatible( str
) {
66 var ua
= str
|| navigator
.userAgent
;
68 // http://caniuse.com/#feat=es5
69 // http://caniuse.com/#feat=use-strict
70 // http://caniuse.com/#feat=json / https://phabricator.wikimedia.org/T141344#2784065
73 return !this && !!Function
.prototype.bind
&& !!window
.JSON
;
76 // http://caniuse.com/#feat=queryselector
77 'querySelector' in document
&&
79 // http://caniuse.com/#feat=namevalue-storage
80 // https://developer.blackberry.com/html5/apis/v1_0/localstorage.html
81 // https://blog.whatwg.org/this-week-in-html-5-episode-30
82 'localStorage' in window
&&
84 // http://caniuse.com/#feat=addeventlistener
85 'addEventListener' in window
&&
87 // Hardcoded exceptions for browsers that pass the requirement but we don't want to
88 // support in the modern run-time.
89 // Note: Please extend the regex instead of adding new ones
91 ua
.match( /webOS\/1\.[0-4]|SymbianOS|Series60|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass|^Mozilla\/5\.0 .+ Gecko\/$|googleweblight/ ) ||
92 ua
.match( /PlayStation/i )
97 // Conditional script injection
100 if ( !isCompatible() ) {
101 // Undo class swapping in case of an unsupported browser.
102 // See ResourceLoaderClientHtml::getDocumentAttributes().
103 document
.documentElement
.className
= document
.documentElement
.className
104 .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
106 NORLQ
= window
.NORLQ
|| [];
107 while ( NORLQ
.length
) {
111 push: function ( fn
) {
116 // Clear and disable the other queue
126 * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
129 mw
.config
= new mw
.Map( $VARS
.wgLegacyJavaScriptGlobals
);
131 $CODE
.registrations();
133 mw
.config
.set( $VARS
.configuration
);
135 // Must be after mw.config.set because these callbacks may use mw.loader which
136 // needs to have values 'skin', 'debug' etc. from mw.config.
137 // eslint-disable-next-line vars-on-top
138 var RLQ
= window
.RLQ
|| [];
139 while ( RLQ
.length
) {
143 push: function ( fn
) {
148 // Clear and disable the other queue
155 mediaWikiLoadStart
= mwNow();
156 mwPerformance
.mark( 'mwLoadStart' );
158 script
= document
.createElement( 'script' );
159 script
.src
= $VARS
.baseModulesUri
;
160 script
.onload
= script
.onreadystatechange = function () {
161 if ( !script
.readyState
|| /loaded|complete/.test( script
.readyState
) ) {
163 script
.onload
= script
.onreadystatechange
= null;
169 document
.getElementsByTagName( 'head' )[ 0 ].appendChild( script
);