CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/support/browser-info.ts
Views: 687
1
declare var navigator;
2
3
export default function browserInfo(): {
4
userAgent?: string;
5
browser:
6
| "chrome"
7
| "firefox"
8
| "safari"
9
| "ios"
10
| "ipados"
11
| "other"
12
| "node";
13
context?: string; // could get filled in later by caller with some extra info.
14
} {
15
const userAgent = navigator?.userAgent;
16
if (!userAgent) {
17
return { userAgent, browser: "node" };
18
}
19
20
let browser;
21
let useragent = userAgent.toLowerCase();
22
if (/chrom(e|ium)/.test(useragent)) {
23
browser = "chrome";
24
} else if (useragent.includes("firefox")) {
25
browser = "firefox";
26
} else if (
27
useragent.match(/Mac/) &&
28
navigator.maxTouchPoints &&
29
navigator.maxTouchPoints > 2
30
) {
31
browser = "ipados";
32
} else if (useragent.match(/iPhone|iPod/i)) {
33
browser = "ios";
34
} else if (useragent.includes("safari")) {
35
browser = "safari";
36
} else {
37
browser = "other";
38
}
39
return { userAgent, browser };
40
}
41
42