From 1a9d9208849c18ae8e4cab27072e74d3300807d4 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Sat, 28 Jan 2023 19:41:39 -0800 Subject: [PATCH] Detect old browser JS engines --- package.json | 2 +- www/js/data.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 3abee162..a452d9ab 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.85.0", + "version": "3.85.1", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/www/js/data.js b/www/js/data.js index 2c107ae5..b041f8e2 100644 --- a/www/js/data.js +++ b/www/js/data.js @@ -1,4 +1,55 @@ /*eslint no-unused-vars: "off"*/ + +(function() { + /** + * Test whether the browser supports nullish-coalescing operator. + * + * Users with old browsers will probably fail to load the client correctly + * because parsing this operator in older browsers results in a SyntaxError + * that aborts compilation of the entire script (not just an exception where + * it is used). In particular, as of 2023-01-28, Utherverse ships with + * a rather old browser version (Chrome 76) and several users have reported + * it not working. + */ + try { + try { + new Function('x?.y'); + } catch (e) { + if (e.name === 'SyntaxError') { + /** + * If we're at this point, we can't be sure what scripts have + * actually loaded, so construct the error alert the old + * fashioned way. + */ + var wrap = document.createElement('div'); + wrap.className = 'col-md-12'; + var al = document.createElement('div'); + al.className = 'alert alert-danger'; + var title = document.createElement('strong'); + title.textContent = 'Unsupported Browser'; + var msg = document.createElement('p'); + msg.textContent = 'It looks like your browser does not support ' + + 'the required JavaScript features to run ' + + 'CyTube. This is usually caused by ' + + 'using an outdated browser version. Please '+ + 'check if an update is available. Your ' + + 'browser version is reported as:'; + var version = document.createElement('tt'); + version.textContent = navigator.userAgent; + + wrap.appendChild(al); + al.appendChild(title); + al.appendChild(msg); + al.appendChild(document.createElement('br')); + al.appendChild(version); + document.getElementById('motdrow').appendChild(wrap); + } + } + } catch (e) { + console.error('Error probing for feature support:', e.stack); + } +})(); + var CL_VERSION = 3.0; var GS_VERSION = 1.7; // Google Drive Userscript