How to redirect from embedded browser to main browser, on mobile devices?
Unanswered
Tornjak posted this in #help-forum
TornjakOP
Hey everyone, I’ve been trying to force a redirect on my nextJS app.
For instance, someone sends a link to my app on Instagram. When I open it on Instagram, it opens in Instagram’s embedded browser. I want it to redirect to Safari as soon as it opens on the embedded browser on Insta, LinkedIn, etc.
The code that I’ve implemented after reading documentation and articles, manages to open safari, but does a google search using the default search engine.
How do I fix this?
https://felixcarmona.com/solving-google-login-issues-linkedin-ios/
This is the reference article I used.
“””
utils/detectEmbeddedBrowser.js
import { android_regex, ios_regex } from "./regex/regex";
export const detectEmbeddedBrowser = () => {
code not included due to text limit }
export const handleEmbeddedBrowserRedirect = () => {
if (detectEmbeddedBrowser()) {
const isIOS = ios_regex.test(navigator.userAgent) && !window.MSStream;
const isAndroid = android_regex.test(navigator.userAgent);
const url = window.location.href;
if (isIOS) {
alert("Please open this page in Safari for the best experience.");
window.location.href =
}
else if (isAndroid) {
alert("Please open this page in Chrome for the best experience.");
window.location.href =
}
// Fallback for other environments
else {
alert("For the best experience, please open this page in your default browser.");
}
}
};
“””
Looking forward to what you guys have to share. Thank you!
For instance, someone sends a link to my app on Instagram. When I open it on Instagram, it opens in Instagram’s embedded browser. I want it to redirect to Safari as soon as it opens on the embedded browser on Insta, LinkedIn, etc.
The code that I’ve implemented after reading documentation and articles, manages to open safari, but does a google search using the default search engine.
How do I fix this?
https://felixcarmona.com/solving-google-login-issues-linkedin-ios/
This is the reference article I used.
“””
utils/detectEmbeddedBrowser.js
import { android_regex, ios_regex } from "./regex/regex";
export const detectEmbeddedBrowser = () => {
code not included due to text limit }
export const handleEmbeddedBrowserRedirect = () => {
if (detectEmbeddedBrowser()) {
const isIOS = ios_regex.test(navigator.userAgent) && !window.MSStream;
const isAndroid = android_regex.test(navigator.userAgent);
const url = window.location.href;
if (isIOS) {
alert("Please open this page in Safari for the best experience.");
window.location.href =
x-web-search://?${url}
;}
else if (isAndroid) {
alert("Please open this page in Chrome for the best experience.");
window.location.href =
googlechrome://navigate?url=${url}
;}
// Fallback for other environments
else {
alert("For the best experience, please open this page in your default browser.");
}
}
};
“””
Looking forward to what you guys have to share. Thank you!
5 Replies
I think stackoverflow is a perfect place to ask this question, or you can wait for someone who has knowledge about it to answer.
The user can enable a setting "Open links in external browser", to auto open on external browser.
The user can enable a setting "Open links in external browser", to auto open on external browser.
TornjakOP
Yes, that leaves the expectation on the user. Thing is, sign in with google is not working on embedded browsers. Gives a terrible impression that your app is broken.
Thank you for your response. Much appreciated. I’ll try to post there as well.
Thank you for your response. Much appreciated. I’ll try to post there as well.
Also post the stackoverflow link here. I'll upvote your question
I think there should be a user agent instagram, then you can ask them to open on external browser