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, mwNow, isCompatible, $VARS, $CODE */
10 // Define now() here to ensure valid comparison with mediaWikiLoadEnd (T153819).
11 window
.mwNow
= ( function () {
12 var perf
= window
.performance
,
13 navStart
= perf
&& perf
.timing
&& perf
.timing
.navigationStart
;
14 return navStart
&& typeof perf
.now
=== 'function' ?
15 function () { return navStart
+ perf
.now(); } :
16 function () { return Date
.now(); };
20 * See <https://www.mediawiki.org/wiki/Compatibility#Browsers>
22 * Capabilities required for modern run-time:
24 * - DOM Level 4 & Selectors API Level 1
25 * - HTML5 & Web Storage
26 * - DOM Level 2 Events
28 * Browsers we support in our modern run-time (Grade A):
34 * - Mobile Safari 6.0+ (iOS 6+)
37 * Browsers we support in our no-javascript run-time (Grade C):
43 * - Mobile Safari 5.0+ (iOS 4+)
47 * - Symbian-based browsers
48 * - NetFront-based browser
50 * - Nokia's Ovi Browser
53 * - UC Mini (speed mode on)
55 * Other browsers that pass the check are considered Grade X.
57 * @param {string} [str] User agent, defaults to navigator.userAgent
58 * @return {boolean} User agent is compatible with MediaWiki JS
60 window
.isCompatible = function ( str
) {
61 var ua
= str
|| navigator
.userAgent
;
63 // https://caniuse.com/#feat=es5
64 // https://caniuse.com/#feat=use-strict
65 // https://caniuse.com/#feat=json / https://phabricator.wikimedia.org/T141344#2784065
68 return !this && !!Function
.prototype.bind
&& !!window
.JSON
;
71 // https://caniuse.com/#feat=queryselector
72 'querySelector' in document
&&
74 // https://caniuse.com/#feat=namevalue-storage
75 // https://developer.blackberry.com/html5/apis/v1_0/localstorage.html
76 // https://blog.whatwg.org/this-week-in-html-5-episode-30
77 'localStorage' in window
&&
79 // https://caniuse.com/#feat=addeventlistener
80 'addEventListener' in window
&&
82 // Hardcoded exceptions for browsers that pass the requirement but we don't want to
83 // support in the modern run-time.
84 // Note: Please extend the regex instead of adding new ones
86 ua
.match( /MSIE 10|webOS\/1\.[0-4]|SymbianOS|Series60|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass|^Mozilla\/5\.0 .+ Gecko\/$|googleweblight/ ) ||
87 ua
.match( /PlayStation/i )
92 // Conditional script injection
95 if ( !isCompatible() ) {
96 // Undo class swapping in case of an unsupported browser.
97 // See ResourceLoaderClientHtml::getDocumentAttributes().
98 document
.documentElement
.className
= document
.documentElement
.className
99 .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
101 NORLQ
= window
.NORLQ
|| [];
102 while ( NORLQ
.length
) {
106 push: function ( fn
) {
111 // Clear and disable the other queue
121 * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
124 mw
.config
= new mw
.Map( $VARS
.wgLegacyJavaScriptGlobals
);
126 $CODE
.registrations();
128 mw
.config
.set( $VARS
.configuration
);
130 // Must be after mw.config.set because these callbacks may use mw.loader which
131 // needs to have values 'skin', 'debug' etc. from mw.config.
132 // eslint-disable-next-line vars-on-top
133 var RLQ
= window
.RLQ
|| [];
134 while ( RLQ
.length
) {
138 push: function ( fn
) {
143 // Clear and disable the other queue
150 window
.mediaWikiLoadStart
= mwNow();
151 if ( window
.performance
&& performance
.mark
) {
152 performance
.mark( 'mwStartup' );
154 script
= document
.createElement( 'script' );
155 script
.src
= $VARS
.baseModulesUri
;
156 script
.onload = function () {
158 script
.onload
= null;
163 document
.head
.appendChild( script
);