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 +new Date(); };
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:
29 * - DOM Level 4 & Selectors API Level 1
30 * - HTML5 & Web Storage
31 * - DOM Level 2 Events
34 * Browsers we support in our modern run-time (Grade A):
40 * - Mobile Safari (iOS 4+)
43 * Browsers we support in our no-javascript run-time (Grade C):
51 * - Symbian-based browsers
52 * - NetFront-based browser
54 * - Nokia's Ovi Browser
57 * - UC Mini (speed mode on)
59 * Other browsers that pass the check are considered Grade X.
61 * @param {string} [str] User agent, defaults to navigator.userAgent
62 * @return {boolean} User agent is compatible with MediaWiki JS
64 function isCompatible( str ) {
65 var ua = str || navigator.userAgent;
67 // http://caniuse.com/#feat=queryselector
68 'querySelector' in document &&
70 // http://caniuse.com/#feat=namevalue-storage
71 // https://developer.blackberry.com/html5/apis/v1_0/localstorage.html
72 // https://blog.whatwg.org/this-week-in-html-5-episode-30
73 'localStorage' in window &&
75 // http://caniuse.com/#feat=addeventlistener
76 'addEventListener' in window &&
78 // http://caniuse.com/#feat=json
79 // https://phabricator.wikimedia.org/T141344#2784065
80 ( window.JSON && JSON.stringify && JSON.parse ) &&
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( /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 script = document.createElement( 'script' );
151 script.src = $VARS.baseModulesUri;
152 script.onload = script.onreadystatechange = function () {
153 if ( !script.readyState || /loaded|complete/.test( script.readyState ) ) {
155 script.onload = script.onreadystatechange = null;
161 document.getElementsByTagName( 'head' )[ 0 ].appendChild( script );