DEV Community

Cover image for Why Instagram's In-App Browser Breaks Your Website (And How to Fix It)
muddassirhq
muddassirhq

Posted on

Why Instagram's In-App Browser Breaks Your Website (And How to Fix It)

If you've ever shared a link on Instagram and later found out logins or
checkout were silently broken for some users, the in-app browser is almost always the cause. Instagram and Facebook don't open your link in the visitor's actual Safari or Chrome. They open it inside their own app, in a sandboxed WebView you don't control.

I hit this on a client project a few months back. A login flow worked
perfectly in every browser I tested, then failed for a chunk of real
traffic. The pattern was always the same: visitors coming from an
Instagram bio link or story. Here's what's actually happening, and how to fix it on your own site without a redirect or middleware page.

Why the in-app browser breaks things

When someone taps a link inside Instagram, it opens in a WebView that Meta
controls, not the device's default browser. That WebView:

  • Often restricts or isolates third-party cookies, which breaks OAuth flows that rely on a cookie set in one tab and read in another
  • Doesn't always behave like the real Safari or Chrome when a payment provider (Stripe, PayPal) tries to open a secure popup
  • Can't be fixed from your backend, because the problem isn't your server, it's the browser rendering the page

You can't detect and block Instagram traffic. You need to detect it and
get the user out of it, into their real browser, where the page keeps
working.

The fix: detect it, then hand off

There are two unofficial deep-link tricks that can hand a user off
automatically:

iOS, via Meta's own external-browser protocol:

window.location.href = `instagram://extbrowser/?url=${encodeURIComponent(currentUrl)}`;
Enter fullscreen mode Exit fullscreen mode

Android, via an Intent URL targeting Chrome:

window.location.href = `intent://${currentUrl.replace(/^https?:\/\//, '')}#Intent;scheme=https;package=com.android.chrome;end`;
Enter fullscreen mode Exit fullscreen mode

The important part people skip: neither of these is documented, stable
API. Meta can change WebView behavior at any point and quietly break both.

I've seen plenty of Gist snippets online that fire the deep link and stop there. If it fails, the user is just stuck, with no explanation and no way out.

So the fallback matters as much as the automatic part. If the deep link
doesn't work, show a small banner with a manual "Open in browser" button
that links to the same escape URL. The user taps it themselves. It's not
elegant, but it never leaves anyone stranded.

I packaged this up

I built this into a small, dependency-free library called
open-in-native-browser. It does exactly what's above: detects Instagram/Facebook in-app browsers, attempts the automatic handoff, and
shows a dismissible fallback banner if that fails. Nothing happens on a
regular browser.

Works as a plain script tag with no build step, or as an import in
React, Vue, Next.js, Angular, or Svelte.

npm install open-in-native-browser
Enter fullscreen mode Exit fullscreen mode
import OpenInNativeBrowser from 'open-in-native-browser';
OpenInNativeBrowser.init();
Enter fullscreen mode Exit fullscreen mode

Live demo (open it from inside Instagram to actually see it trigger):
https://muddassirhq.github.io/open-in-native-browser/

GitHub: https://github.com/muddassirhq/open-in-native-browser
npm: https://www.npmjs.com/package/open-in-native-browser

What's next

The script fixes this if you can edit your site's code. A lot of the
people affected most, Shopify and WordPress store owners running
Instagram ads, can't. I'm working on a hosted version of this plus
plugins for those platforms, so the fix is a one-click install instead of a code change. If that's useful to you, I'd genuinely like to hear about it in the comments, especially any edge cases you've hit with in-app browsers that this doesn't cover yet.

Top comments (0)