Skip to content

Commit 0ae4af9

Browse files
authored
Update browser check (#4214)
1 parent 79907af commit 0ae4af9

File tree

1 file changed

+52
-28
lines changed

1 file changed

+52
-28
lines changed
+52-28
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,57 @@
1-
export function checkBrowserCompatibility() {
1+
export function isChromium() {
2+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
3+
if (!navigator.userAgentData) {
4+
console.log(navigator.userAgent);
5+
return false;
6+
}
7+
8+
console.log(navigator.userAgentData);
9+
// https://learn.microsoft.com/en-us/microsoft-edge/web-platform/user-agent-guidance
10+
return navigator.userAgentData.brands.some((brand) => {
11+
return brand.brand == "Chromium";
12+
});
13+
}
14+
15+
export function checkBrowserCompatibility() {
216
const compatible = "serial" in navigator;
317

18+
if (isChromium() && compatible) {
19+
return true;
20+
}
21+
22+
let errorMessage = "";
23+
if (!isChromium()) {
24+
errorMessage = "Betaflight app requires a Chromium based browser (Chrome, Chromium, Edge).";
25+
}
26+
427
if (!compatible) {
5-
const errorMessage = "Betaflight app requires Chrome, Chromium, Edge or Vivaldi browser.";
6-
const newDiv = document.createElement("div");
7-
8-
$('body')
9-
.empty()
10-
.css({
11-
"height": "100%",
12-
"display": "grid",
13-
"background-image": "url(../images/osd-bg-1.jpg",
14-
"background-size": "cover",
15-
"background-repeat": "no-repeat",
16-
})
17-
.append(newDiv);
18-
19-
$('div')
20-
.append(errorMessage)
21-
.css({
22-
"font-size": "16px",
23-
"background-color": "var(--surface-200)",
24-
"color": "var(--text)",
25-
"padding": "1rem",
26-
"margin": "auto",
27-
"border-radius": "0.75rem",
28-
"border": "2px solid var(--surface-500)",
29-
});
30-
31-
throw new Error("No compatible browser found.");
28+
errorMessage += " Web Serial API support is disabled.";
3229
}
30+
31+
const newDiv = document.createElement("div");
32+
33+
$('body')
34+
.empty()
35+
.css({
36+
"height": "100%",
37+
"display": "grid",
38+
"background-image": "url(../images/osd-bg-1.jpg",
39+
"background-size": "cover",
40+
"background-repeat": "no-repeat",
41+
})
42+
.append(newDiv);
43+
44+
$('div')
45+
.append(errorMessage)
46+
.css({
47+
"font-size": "16px",
48+
"background-color": "var(--surface-200)",
49+
"color": "var(--text)",
50+
"padding": "1rem",
51+
"margin": "auto",
52+
"border-radius": "0.75rem",
53+
"border": "2px solid var(--surface-500)",
54+
});
55+
56+
throw new Error("No compatible browser found.");
3357
}

0 commit comments

Comments
 (0)