I’m working on a system with the following goals:
- Create a short link that points to an Amazon product URL.
- When someone clicks this link, it should ideally open directly in the Amazon app if it’s installed on their device.
Current Approach
To achieve this, I’m serving a short link that, when clicked, returns HTML and JavaScript designed to redirect users to the Amazon app if it’s installed. Here’s the core HTML and JavaScript I’m using for the redirection:
const htmlResponse = `
<!DOCTYPE html>
<html>
<head>
<script>
window.location.href = '${urls.redirectUrl}';
</script>
</head>
<body>
<p>Redirecting</p>
</body>
</html>
`;
res.setHeader('Content-Type', 'text/html');
res.send(htmlResponse);
Results So Far
-> Directly Clicking the Link: This setup works well in most cases, directly opening the Amazon app as expected on both iOS and Android when the link is clicked from most browsers.
-> Shared on Instagram Story:
> iOS: When the Instagram Story is clicked by an iOS user, links opens in the Instagram InApp Browser, and it redirects correctly to the Amazon app, likely due to Apple’s support for Universal Links, which Instagram respects.
> Android: On Android, however, clicking the link from an Instagram Story opens it within Instagram’s in-app browser. Here, the link doesn’t redirect to the Amazon app. Instead, it simply opens within Instagram’s browser, likely because Android's Instagram browser blocks intents and app redirections.
Solutions I have tried based on a few questions asked on StackOverflow
- How open default browser from instagram in-app browser page link?
- Redirect website from facebook web browser to mobile’s default browser
- Redirecting from Facebook/Instagram in-app browser to default browser on iOS
Based on these, I have tried a few solutions, like
Solution 1
Redirection when the request is coming from Android & Instagram, assuming that, it will open the Amazon App, but it’s not
<script>
window.location.href =
'intent://www.amazon.com/dp/B0CM5J4X7W#Intent;scheme=https;package=com.amazon.mobile.shopping.web;end';
</script>;
or
<script>
window.location.href =
'intent://www.amazon.com/dp/B0CM5J4X7W#Intent;scheme=https;package=com.amazon.mShop.android.shopping;end';
</script>;
Solution 2
Tried to open the URL in the default browser, but looks like Instagram has blocked this redirection to the default browser as well.
<script>
window.location.href = `googlechrome://${link}`;
</script>;
or
<script>
window.location.href = `intent://${link}#Intent;scheme=https;end`;
</script>;
Solution 3
When the request is coming from Android & Instagram, return a file download response. As the InApp browser doesn’t handle file download, so I was assuming that it would redirect to Default, but in the case of Instagram Story, this redirection also doesn’t happen. But if we share the Link via Inbox with someone, and click that link, it opens in the default browser as it’s a file download link.
Here’s the code for that.
router.get(
'/:id.docx',
async (req: Request, res: Response) => {
try {
const { id } = req.params;
const userAgent = req.headers['user-agent']?.toLowerCase().trim() || '';
const isInstagram = userAgent?.includes('instagram');
const isAndroid = userAgent?.includes('android');
const file = bucket.file('dummy/dummy.docx');
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
res.setHeader(
'Content-Type',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
);
res.setHeader(
'Content-Disposition',
'attachment; filename="dummy.docx"',
);
res.setHeader('Content-Transfer-Encoding', 'binary');
res.setHeader('Accept-Ranges', 'bytes');
res.setHeader('Cache-Control', 'no-store, must-revalidate');
res.setHeader('Pragma', 'no-cache');
// Stream the file to the response
file
.createReadStream()
.on('error', (err) => {
console.error('Error fetching file:', err);
res.status(500).send('Error downloading file.');
})
.pipe(res);
return;
} catch (firebaseError) {
console.error(firebaseError);
res.status(303).redirect(notFound);
}
},
);
Question
Is there any way on Android to programmatically trigger Instagram’s in-app browser to open my link in the default browser when clicked from a Story?
If users were redirected to their default browser from Instagram’s in-app browser, the Amazon app redirection would work as intended. Any workaround or solution that helps to open the link in the default browser directly from an Instagram Story on Android would be greatly appreciated.
Thank you for any suggestions or guidance!