Skip to content

Commit

Permalink
runfix: block mobile browsers (#18305)
Browse files Browse the repository at this point in the history
* runfix: block mobile browsers

* runfix: block mobile browsers

* feat: refine mobile check to not exclude touchscreen laptops
  • Loading branch information
aweiss-dev authored Nov 14, 2024
1 parent 0258aa7 commit 4b394c3
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/script/browser/CheckBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ const isOauth = (): boolean => location?.hash?.includes(QUERY_KEY.SCOPE) ?? fals

const cookieName = 'cookie_supported_test_wire_cookie_name';

const isMobileBrowser = (): boolean => {
const isTouchScreen = window.matchMedia('(any-pointer:coarse)').matches;
const isSmallScreen = window.matchMedia('(max-width: 768px)').matches;
return (
isTouchScreen &&
isSmallScreen &&
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
);
};

const supportsCookies = (): boolean => {
switch (navigator.cookieEnabled) {
case true:
Expand All @@ -55,6 +65,11 @@ const supportsCookies = (): boolean => {
}
};

const redirectUnsupportedBrowser = (error: string): void => {
location.href = '/unsupported/';
console.error(error);
};

const supportsIndexDB = (): Promise<boolean> =>
new Promise<boolean>((resolve, _reject) => {
if (!('indexedDB' in window)) {
Expand Down Expand Up @@ -92,24 +107,28 @@ const supportsIndexDB = (): Promise<boolean> =>

const checkBrowser = (): void => {
if (!supportsCookies()) {
location.href = '/unsupported/';
console.error("This browser doesn't support cookies to run the Wire app!");
redirectUnsupportedBrowser("This browser doesn't support cookies to run the Wire app!");
return;
}
// Skip the mobile browser check for OAuth
if (isOauth()) {
return;
}

if (isMobileBrowser()) {
redirectUnsupportedBrowser("This browser doesn't support the Wire app on mobile devices!");
return;
}

if (!('RTCPeerConnection' in window)) {
location.href = '/unsupported/';
console.error("This browser doesn't support RTC to run the Wire app!");
redirectUnsupportedBrowser("This browser doesn't support RTC to run the Wire app!");
return;
}
supportsIndexDB()
void supportsIndexDB()
.catch(() => false)
.then(res => {
if (!res) {
location.href = '/unsupported/';
console.error("This browser doesn't support IndexDB to run the Wire app!");
redirectUnsupportedBrowser("This browser doesn't support IndexDB to run the Wire app!");
}
});
};
Expand Down

0 comments on commit 4b394c3

Please sign in to comment.