Skip to content

Commit f7e5613

Browse files
authored
Merge pull request element-hq#12232 from vector-im/t3chguy/modernizr
Improve Browser checks
2 parents c3e6a30 + 7d49078 commit f7e5613

4 files changed

Lines changed: 30 additions & 12 deletions

File tree

‎.modernizr.json‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
"test/css/objectfit",
1212
"test/storage/localstorage",
1313
"test/workers/webworkers",
14-
"test/indexeddb"
14+
"test/indexeddb",
15+
"test/es6/array",
16+
"test/es6/collections",
17+
"test/es6/promises",
18+
"test/serviceworker",
19+
"test/svg",
20+
"test/svg/asimg",
21+
"test/svg/filters",
22+
"test/css/animations",
23+
"test/css/filters",
24+
"test/network/fetch"
1525
]
1626
}

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"highlight.js": "^9.13.1",
6868
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop",
6969
"matrix-react-sdk": "github:matrix-org/matrix-react-sdk#develop",
70-
"modernizr": "^3.6.0",
7170
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz",
7271
"postcss-easings": "^2.0.0",
7372
"prop-types": "^15.7.2",
@@ -131,6 +130,7 @@
131130
"mini-css-extract-plugin": "^0.8.0",
132131
"minimist": "^1.2.0",
133132
"mkdirp": "^0.5.1",
133+
"modernizr": "^3.6.0",
134134
"optimize-css-assets-webpack-plugin": "^5.0.3",
135135
"postcss-extend": "^1.0.5",
136136
"postcss-import": "^12.0.1",

‎src/vector/app.js‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,23 @@ import CallHandler from 'matrix-react-sdk/src/CallHandler';
5353

5454
let lastLocationHashSet = null;
5555

56-
function checkBrowserFeatures(featureList) {
56+
function checkBrowserFeatures() {
5757
if (!window.Modernizr) {
5858
console.error("Cannot check features - Modernizr global is missing.");
5959
return false;
6060
}
61+
62+
// custom checks atop Modernizr because it doesn't have ES2018/ES2019 checks in it for some features we depend on,
63+
// Modernizr requires rules to be lowercase with no punctuation:
64+
// ES2018: http://www.ecma-international.org/ecma-262/9.0/#sec-promise.prototype.finally
65+
window.Modernizr.addTest("promiseprototypefinally", () =>
66+
window.Promise && window.Promise.prototype && typeof window.Promise.prototype.finally === "function");
67+
// ES2019: http://www.ecma-international.org/ecma-262/10.0/#sec-object.fromentries
68+
window.Modernizr.addTest("objectfromentries", () =>
69+
window.Object && typeof window.Object.fromEntries === "function");
70+
71+
const featureList = Object.keys(window.Modernizr);
72+
6173
let featureComplete = true;
6274
for (let i = 0; i < featureList.length; i++) {
6375
if (window.Modernizr[featureList[i]] === undefined) {
@@ -69,8 +81,7 @@ function checkBrowserFeatures(featureList) {
6981
}
7082
if (window.Modernizr[featureList[i]] === false) {
7183
console.error("Browser missing feature: '%s'", featureList[i]);
72-
// toggle flag rather than return early so we log all missing features
73-
// rather than just the first.
84+
// toggle flag rather than return early so we log all missing features rather than just the first.
7485
featureComplete = false;
7586
}
7687
}
@@ -260,10 +271,7 @@ export async function loadApp() {
260271
return;
261272
}
262273

263-
const validBrowser = checkBrowserFeatures([
264-
"displaytable", "flexbox", "es5object", "es5function", "localstorage",
265-
"objectfit", "indexeddb", "webworkers",
266-
]);
274+
const validBrowser = checkBrowserFeatures();
267275

268276
const acceptInvalidBrowser = window.localStorage && window.localStorage.getItem('mx_accepts_unsupported_browser');
269277

0 commit comments

Comments
 (0)