Skip to content

Commit

Permalink
In-App links
Browse files Browse the repository at this point in the history
fixing in-app browser links from all the major social apps (Instagram, Twitter, Facebook, etc)

Tested on (Instagram, Twitter, Facebook) on (IOS, Android)

          // IOS INSTAGRAM: https://github.com/user-attachments/assets/0d3ab224-1ac7-454e-b75d-21f6c52ffa87
          // IOS FACEBOOK: https://github.com/user-attachments/assets/4c8121a2-3c62-402f-be05-0c54bf108ddc
          // IOS TWITTER/X: https://github.com/user-attachments/assets/ed01b58e-5aab-48b9-8c42-d21d24cd2c03

          // ANDROID FACEBOOK: https://github.com/user-attachments/assets/45701ac3-d337-4fc4-8e82-3d03236bf3a5
          // ANDROID INSTAGRAM: https://github.com/user-attachments/assets/7e1d11fd-31ba-4b27-a13d-6beb079b4204
          // ANDROID X/TWITTER JUST OPENS SYSTEM BROWSER
  • Loading branch information
Philip Fung committed Jan 20, 2025
1 parent 662063e commit 66642c9
Show file tree
Hide file tree
Showing 25 changed files with 63 additions and 42 deletions.
29 changes: 19 additions & 10 deletions dist/add-to-homescreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,18 @@ function AddToHomeScreen(options) {
ret = new types_1.DeviceInfo((_isStandAlone = false), (_canBeStandAlone = true), (_device = _device));
_genIOSChrome(container);
}
else if (isBrowserIOSInAppFacebook() || isBrowserIOSInAppLinkedin()) {
else if (isBrowserIOSInAppFacebook()
|| isBrowserIOSInAppLinkedin()
|| isBrowserIOSInAppInstagram()) {
// IOS INSTAGRAM: https://github.com/user-attachments/assets/0d3ab224-1ac7-454e-b75d-21f6c52ffa87
// IOS FACEBOOK: https://github.com/user-attachments/assets/4c8121a2-3c62-402f-be05-0c54bf108ddc
ret = new types_1.DeviceInfo((_isStandAlone = false), (_canBeStandAlone = false), (_device = _device));
_genIOSInAppBrowserOpenInSystemBrowser(container);
_genIOSInAppBrowserUpperRightButtonOpenInSystemBrowser(container);
}
else if (isBrowserIOSInAppInstagram() ||
isBrowserIOSInAppThreads() ||
isBrowserIOSInAppTwitter()) {
else if (isBrowserIOSInAppTwitter()) {
// IOS TWITTER/X: https://github.com/user-attachments/assets/ed01b58e-5aab-48b9-8c42-d21d24cd2c03
ret = new types_1.DeviceInfo((_isStandAlone = false), (_canBeStandAlone = false), (_device = _device));
_genIOSInAppBrowserOpenInSafariBrowser(container);
_genIOSInAppBrowserLowerRightButtonOpenInSafariBrowser(container);
}
else {
ret = new types_1.DeviceInfo((_isStandAlone = false), (_canBeStandAlone = false), (_device = _device));
Expand All @@ -145,11 +148,14 @@ function AddToHomeScreen(options) {
ret = new types_1.DeviceInfo((_isStandAlone = false), (_canBeStandAlone = true), (_device = _device));
_genAndroidChrome(container);
}
else if (isBrowserAndroidFacebook()) {
else if (isBrowserAndroidFacebook() || isBrowserAndroidInstagram()) {
// ANDROID FACEBOOK: https://github.com/user-attachments/assets/45701ac3-d337-4fc4-8e82-3d03236bf3a5
// ANDROID INSTAGRAM: https://github.com/user-attachments/assets/7e1d11fd-31ba-4b27-a13d-6beb079b4204
ret = new types_1.DeviceInfo((_isStandAlone = false), (_canBeStandAlone = false), (_device = _device));
_genIOSInAppBrowserOpenInSystemBrowser(container);
_genIOSInAppBrowserUpperRightButtonOpenInSystemBrowser(container);
}
else {
// ANDROID X/TWITTER JUST OPENS SYSTEM BROWSER
ret = new types_1.DeviceInfo((_isStandAlone = false), (_canBeStandAlone = false), (_device = _device));
shouldShowModal = false;
}
Expand Down Expand Up @@ -292,6 +298,9 @@ function AddToHomeScreen(options) {
function isBrowserAndroidFacebook() {
return isDeviceAndroid() && _matchesUserAgent(/FBAN|FBAV/);
}
function isBrowserAndroidInstagram() {
return isDeviceAndroid() && _matchesUserAgent(/Instagram/);
}
/* Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-S918B) AppleWebKit/537.36
(KHTML, like Gecko) SamsungBrowser/21.0 Chrome/110.0.5481.154 Mobile Safari/537.36 */
function isBrowserAndroidSamsung() {
Expand Down Expand Up @@ -486,7 +495,7 @@ function AddToHomeScreen(options) {
container.innerHTML = containerInnerHTML;
container.classList.add("adhs-mobile", "adhs-ios", "adhs-chrome");
}
function _genIOSInAppBrowserOpenInSystemBrowser(container) {
function _genIOSInAppBrowserUpperRightButtonOpenInSystemBrowser(container) {
var containerInnerHTML = _genModalStart() +
_genInstallAppHeader() +
_genAppNameHeader() +
Expand All @@ -504,7 +513,7 @@ function AddToHomeScreen(options) {
container.innerHTML = containerInnerHTML;
container.classList.add("adhs-mobile", "adhs-ios", "adhs-inappbrowser-openinsystembrowser");
}
function _genIOSInAppBrowserOpenInSafariBrowser(container) {
function _genIOSInAppBrowserLowerRightButtonOpenInSafariBrowser(container) {
var containerInnerHTML = _genModalStart() +
_genInstallAppHeader() +
_genAppNameHeader() +
Expand Down
2 changes: 1 addition & 1 deletion dist/add-to-homescreen.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_cs.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_da.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_de.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_en.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_es.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_fr.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_he.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_it.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_ja.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_ko.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_lv.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_pl.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_pt.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_ru.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_sl.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_sv.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_th.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_vn.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_zh.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_zh_CN.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_zh_HK.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/add-to-homescreen_zh_TW.min.js

Large diffs are not rendered by default.

30 changes: 21 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,31 @@ export function AddToHomeScreen(
);

_genIOSChrome(container);
} else if (isBrowserIOSInAppFacebook() || isBrowserIOSInAppLinkedin()) {
} else if (
isBrowserIOSInAppFacebook()
|| isBrowserIOSInAppLinkedin()
|| isBrowserIOSInAppInstagram()
) {
// IOS INSTAGRAM: https://github.com/user-attachments/assets/0d3ab224-1ac7-454e-b75d-21f6c52ffa87
// IOS FACEBOOK: https://github.com/user-attachments/assets/4c8121a2-3c62-402f-be05-0c54bf108ddc
ret = new DeviceInfo(
(_isStandAlone = false),
(_canBeStandAlone = false),
(_device = _device)
);

_genIOSInAppBrowserOpenInSystemBrowser(container);
_genIOSInAppBrowserUpperRightButtonOpenInSystemBrowser(container);
} else if (
isBrowserIOSInAppInstagram() ||
isBrowserIOSInAppThreads() ||
isBrowserIOSInAppTwitter()
) {
// IOS TWITTER/X: https://github.com/user-attachments/assets/ed01b58e-5aab-48b9-8c42-d21d24cd2c03
ret = new DeviceInfo(
(_isStandAlone = false),
(_canBeStandAlone = false),
(_device = _device)
);

_genIOSInAppBrowserOpenInSafariBrowser(container);
_genIOSInAppBrowserLowerRightButtonOpenInSafariBrowser(container);
} else {
ret = new DeviceInfo(
(_isStandAlone = false),
Expand All @@ -192,14 +197,17 @@ export function AddToHomeScreen(
(_device = _device)
);
_genAndroidChrome(container);
} else if (isBrowserAndroidFacebook()) {
} else if (isBrowserAndroidFacebook() || isBrowserAndroidInstagram()) {
// ANDROID FACEBOOK: https://github.com/user-attachments/assets/45701ac3-d337-4fc4-8e82-3d03236bf3a5
// ANDROID INSTAGRAM: https://github.com/user-attachments/assets/7e1d11fd-31ba-4b27-a13d-6beb079b4204
ret = new DeviceInfo(
(_isStandAlone = false),
(_canBeStandAlone = false),
(_device = _device)
);
_genIOSInAppBrowserOpenInSystemBrowser(container);
_genIOSInAppBrowserUpperRightButtonOpenInSystemBrowser(container);
} else {
// ANDROID X/TWITTER JUST OPENS SYSTEM BROWSER
ret = new DeviceInfo(
(_isStandAlone = false),
(_canBeStandAlone = false),
Expand Down Expand Up @@ -386,6 +394,10 @@ export function AddToHomeScreen(
return isDeviceAndroid() && _matchesUserAgent(/FBAN|FBAV/);
}

function isBrowserAndroidInstagram(): boolean {
return isDeviceAndroid() && _matchesUserAgent(/Instagram/);
}

/* Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-S918B) AppleWebKit/537.36
(KHTML, like Gecko) SamsungBrowser/21.0 Chrome/110.0.5481.154 Mobile Safari/537.36 */
function isBrowserAndroidSamsung(): boolean {
Expand Down Expand Up @@ -665,7 +677,7 @@ export function AddToHomeScreen(
container.classList.add("adhs-mobile", "adhs-ios", "adhs-chrome");
}

function _genIOSInAppBrowserOpenInSystemBrowser(container: HTMLElement) {
function _genIOSInAppBrowserUpperRightButtonOpenInSystemBrowser(container: HTMLElement) {
var containerInnerHTML =
_genModalStart() +
_genInstallAppHeader() +
Expand Down Expand Up @@ -702,7 +714,7 @@ export function AddToHomeScreen(
);
}

function _genIOSInAppBrowserOpenInSafariBrowser(container: HTMLElement) {
function _genIOSInAppBrowserLowerRightButtonOpenInSafariBrowser(container: HTMLElement) {
var containerInnerHTML =
_genModalStart() +
_genInstallAppHeader() +
Expand Down

0 comments on commit 66642c9

Please sign in to comment.