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

Open OldDot links on Safari #5802

Merged
merged 2 commits into from
Oct 13, 2021
Merged
Changes from 1 commit
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
17 changes: 16 additions & 1 deletion src/libs/actions/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,24 @@ function showGrowlIfOffline() {
*/
function openOldDotLink(url) {
if (!showGrowlIfOffline()) {
// Safari blocks opening new windows inside async calls.
// The workaround is to open a new window before the async call and then update its location to the correct url
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
let windowRef;

if (isSafari) {
windowRef = window.open();
}

API.GetShortLivedAuthToken().then(({shortLivedAuthToken}) => {
// eslint-disable-next-line max-len
Linking.openURL(`${CONFIG.EXPENSIFY.URL_EXPENSIFY_COM}${url}${url.indexOf('?') === -1 ? '?' : '&'}authToken=${shortLivedAuthToken}&email=${encodeURIComponent(currentUserEmail)}`);
const oldDotURL = `${CONFIG.EXPENSIFY.URL_EXPENSIFY_COM}${url}${url.indexOf('?') === -1 ? '?' : '&'}authToken=${shortLivedAuthToken}&email=${encodeURIComponent(currentUserEmail)}`;

if (isSafari) {
windowRef.location = oldDotURL;
} else {
Linking.openURL(oldDotURL);
}
});
}
}
Expand Down