Skip to content

Instantly share code, notes, and snippets.

@jgphilpott
Last active November 18, 2022 11:38
Show Gist options
  • Save jgphilpott/7d76cbfe92ecb86bc5206c6e8bd84906 to your computer and use it in GitHub Desktop.
Save jgphilpott/7d76cbfe92ecb86bc5206c6e8bd84906 to your computer and use it in GitHub Desktop.
A function for detecting a clients browser.
# Credit: https://stackoverflow.com/a/40246491/1544937
getBrowser = ->
try
error.throw
catch error
error = error.toString().toLowerCase()
if error.includes "cannot read"
return "chrome"
if error.includes "not an object"
return "safari"
if error.includes "error is undefined"
return "firefox"
return "unknown"
// Generated by CoffeeScript 2.7.0
// Credit: https://stackoverflow.com/a/40246491/1544937
var getBrowser;
getBrowser = function() {
var error;
try {
return error.throw;
} catch (error1) {
error = error1;
error = error.toString().toLowerCase();
if (error.includes("cannot read")) {
return "chrome";
}
if (error.includes("not an object")) {
return "safari";
}
if (error.includes("error is undefined")) {
return "firefox";
}
return "unknown";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment