Created
March 28, 2020 18:06
-
-
Save tracker1/8eea53ec700a0fea725123516a30a70a to your computer and use it in GitHub Desktop.
Modern browser SPA precheck.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// precheck | |
try { | |
eval('(function() { async _ => _; })();'); | |
if (typeof fetch !== 'function') throw new Error('No fetch api'); | |
} catch (e) { | |
// render unsupported message in half a second - after error trap | |
window.setTimeout(function() { | |
// fallback render for development | |
var body = document.getElementsByTagName('body')[0]; | |
body.className = 'message'; | |
body.innerHTML = | |
'\ | |
<h1>Unsupported Browser</h1> \ | |
<p>For security reasons, only current/green browsers are supported.</p> \ | |
<p>Current versions of Chrome, Firefox, Safari and Edge should work</p> \ | |
<p>For more information see <a href="https://browsehappy.com/">browsehappy.com</a></p> \ | |
'; | |
}, 500); | |
// remove all scripts | |
var r = document.getElementsByTagName('script'); | |
for (var i = r.length - 1; i >= 0; i--) { | |
r[i].parentNode.removeChild(r[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment