Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update browser check #4214

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 52 additions & 28 deletions src/js/utils/checkBrowserCompatibilty.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,57 @@
export function checkBrowserCompatibility() {
export function isChromium() {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
if (!navigator.userAgentData) {
console.log(navigator.userAgent);
return false;
}

console.log(navigator.userAgentData);
// https://learn.microsoft.com/en-us/microsoft-edge/web-platform/user-agent-guidance
return navigator.userAgentData.brands.some((brand) => {
return brand.brand == "Chromium";
});
}

export function checkBrowserCompatibility() {
const compatible = "serial" in navigator;

if (isChromium() && compatible) {
return true;
}

let errorMessage = "";
if (!isChromium()) {
errorMessage = "Betaflight app requires a Chromium based browser (Chrome, Chromium, Edge).";
}

if (!compatible) {
const errorMessage = "Betaflight app requires Chrome, Chromium, Edge or Vivaldi browser.";
const newDiv = document.createElement("div");

$('body')
.empty()
.css({
"height": "100%",
"display": "grid",
"background-image": "url(../images/osd-bg-1.jpg",
"background-size": "cover",
"background-repeat": "no-repeat",
})
.append(newDiv);

$('div')
.append(errorMessage)
.css({
"font-size": "16px",
"background-color": "var(--surface-200)",
"color": "var(--text)",
"padding": "1rem",
"margin": "auto",
"border-radius": "0.75rem",
"border": "2px solid var(--surface-500)",
});

throw new Error("No compatible browser found.");
errorMessage += " Web Serial API support is disabled.";
}

const newDiv = document.createElement("div");

$('body')
.empty()
.css({
"height": "100%",
"display": "grid",
"background-image": "url(../images/osd-bg-1.jpg",
"background-size": "cover",
"background-repeat": "no-repeat",
})
.append(newDiv);

$('div')
.append(errorMessage)
.css({
"font-size": "16px",
"background-color": "var(--surface-200)",
"color": "var(--text)",
"padding": "1rem",
"margin": "auto",
"border-radius": "0.75rem",
"border": "2px solid var(--surface-500)",
});

throw new Error("No compatible browser found.");
}