Skip to content

Commit

Permalink
Merge pull request #27233 from kubabutkiewicz/ts-migration/Browser-lib
Browse files Browse the repository at this point in the history
[No QA] [TS Migration] Migrate 'Browser' lib to TypeScript
  • Loading branch information
madmax330 authored Sep 13, 2023
2 parents 2f2c46b + 93966f9 commit 3bf5358
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
File renamed without changes.
22 changes: 9 additions & 13 deletions src/libs/Browser/index.web.js → src/libs/Browser/index.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import ROUTES from '../../ROUTES';
/**
* Fetch browser name from UA string
*
* @return {String} e.g. Chrome
*/
function getBrowser() {
function getBrowser(): string {
const {userAgent} = window.navigator;
let match = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))/i) || [];
let temp;
const match = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))/i) ?? [];
let temp: RegExpMatchArray | null;
let browserName = '';

if (/trident/i.test(match[1])) {
return 'IE';
Expand All @@ -28,15 +28,14 @@ function getBrowser() {
}
}

match = match[1] ? match[1] : navigator.appName;
return match ? match.toLowerCase() : CONST.BROWSER.OTHER;
browserName = match[1] ?? navigator.appName;
return browserName ? browserName.toLowerCase() : CONST.BROWSER.OTHER;
}

/**
* Whether the platform is a mobile browser.
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
*
* @returns {Boolean}
*/
function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Silk|Opera Mini/i.test(navigator.userAgent);
Expand All @@ -45,7 +44,6 @@ function isMobile() {
/**
* Checks if requesting user agent is Safari browser on a mobile device
*
* @returns {Boolean}
*/
function isMobileSafari() {
const userAgent = navigator.userAgent;
Expand All @@ -55,7 +53,6 @@ function isMobileSafari() {
/**
* Checks if requesting user agent is Chrome browser on a mobile device
*
* @returns {Boolean}
*/
function isMobileChrome() {
const userAgent = navigator.userAgent;
Expand All @@ -68,8 +65,6 @@ function isSafari() {

/**
* The session information needs to be passed to the Desktop app, and the only way to do that is by using query params. There is no other way to transfer the data.
* @param {String} shortLivedAuthToken
* @param {String} email
*/
function openRouteInDesktopApp(shortLivedAuthToken = '', email = '') {
const params = new URLSearchParams();
Expand All @@ -95,8 +90,9 @@ function openRouteInDesktopApp(shortLivedAuthToken = '', email = '') {
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
iframe.contentWindow.location.href = expensifyDeeplinkUrl;

if (iframe.contentWindow) {
iframe.contentWindow.location.href = expensifyDeeplinkUrl;
}
// Since we're creating an iframe for Safari to handle deeplink,
// we need to give Safari some time to open the pop-up window.
// After that we can just remove the iframe.
Expand Down

0 comments on commit 3bf5358

Please sign in to comment.