Skip to content

Instantly share code, notes, and snippets.

@tracker1

tracker1/precheck.js

Created Mar 28, 2020
Embed
What would you like to do?
Modern browser SPA precheck.js
// 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