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 // eslint-disable-next-line no-unused-vars
10 var mediaWikiLoadStart = ( new Date() ).getTime(),
11 mwPerformance = ( window.performance && performance.mark ) ? performance : {
15 mwPerformance.mark( 'mwLoadStart' );
18 * See <https://www.mediawiki.org/wiki/Compatibility#Browsers>
20 * Capabilities required for modern run-time:
21 * - DOM Level 4 & Selectors API Level 1
22 * - HTML5 & Web Storage
23 * - DOM Level 2 Events
26 * Browsers we support in our modern run-time (Grade A):
32 * - Mobile Safari (iOS 4+)
35 * Browsers we support in our no-javascript run-time (Grade C):
43 * - Symbian-based browsers
44 * - NetFront-based browser
46 * - Nokia's Ovi Browser
49 * - UC Mini (speed mode on)
51 * Other browsers that pass the check are considered Grade X.
53 * @param {string} [str] User agent, defaults to navigator.userAgent
54 * @return {boolean} User agent is compatible with MediaWiki JS
56 function isCompatible( str ) {
57 var ua = str || navigator.userAgent;
59 // http://caniuse.com/#feat=queryselector
60 'querySelector' in document &&
62 // http://caniuse.com/#feat=namevalue-storage
63 // https://developer.blackberry.com/html5/apis/v1_0/localstorage.html
64 // https://blog.whatwg.org/this-week-in-html-5-episode-30
65 'localStorage' in window &&
67 // http://caniuse.com/#feat=addeventlistener
68 'addEventListener' in window &&
70 // http://caniuse.com/#feat=json
71 // https://phabricator.wikimedia.org/T141344#2784065
72 ( window.JSON && JSON.stringify && JSON.parse ) &&
74 // Hardcoded exceptions for browsers that pass the requirement but we don't want to
75 // support in the modern run-time.
76 // Note: Please extend the regex instead of adding new ones
78 ua.match( /webOS\/1\.[0-4]|SymbianOS|Series60|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass|^Mozilla\/5\.0 .+ Gecko\/$|googleweblight/ ) ||
79 ua.match( /PlayStation/i )
84 // Conditional script injection
87 if ( !isCompatible() ) {
88 // Undo class swapping in case of an unsupported browser.
89 // See ResourceLoaderClientHtml::getDocumentAttributes().
90 document.documentElement.className = document.documentElement.className
91 .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
93 NORLQ = window.NORLQ || [];
94 while ( NORLQ.length ) {
98 push: function ( fn ) {
103 // Clear and disable the other queue
113 * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
116 mw.config = new mw.Map( $VARS.wgLegacyJavaScriptGlobals );
118 $CODE.registrations();
120 mw.config.set( $VARS.configuration );
122 // Must be after mw.config.set because these callbacks may use mw.loader which
123 // needs to have values 'skin', 'debug' etc. from mw.config.
124 // eslint-disable-next-line vars-on-top
125 var RLQ = window.RLQ || [];
126 while ( RLQ.length ) {
130 push: function ( fn ) {
135 // Clear and disable the other queue
142 script = document.createElement( 'script' );
143 script.src = $VARS.baseModulesUri;
144 script.onload = script.onreadystatechange = function () {
145 if ( !script.readyState || /loaded|complete/.test( script.readyState ) ) {
147 script.onload = script.onreadystatechange = null;
153 document.getElementsByTagName( 'head' )[ 0 ].appendChild( script );