Skip to content

Instantly share code, notes, and snippets.

@yashshah1
Created January 26, 2023 00:53
Show Gist options
  • Select an option

  • Save yashshah1/39a96f8939790b73d4c2005f125fe6fb to your computer and use it in GitHub Desktop.

Select an option

Save yashshah1/39a96f8939790b73d4c2005f125fe6fb to your computer and use it in GitHub Desktop.
// from: https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browsers
const useBrowserType = () => {
if (!window) {
return {};
}
const isIE = false || !!document.documentMode;
const isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);
return {
isOpera:
(!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0,
isFirefox: typeof InstallTrigger !== 'undefined',
isSafari:
/constructor/i.test(window.HTMLElement) ||
(function (p) {
return p.toString() === '[object SafariRemoteNotification]';
})(!window['safari'] || (typeof safari !== 'undefined' && window['safari'].pushNotification)),
isIE,
isChrome,
isEdge: !isIE && !!window.StyleMedia,
isEdgeChromium: isChrome && navigator.userAgent.indexOf('Edg') != -1,
};
};
export default useBrowser;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment