Seamlessly open links in Chrome, Firefox, Brave, Edge, Opera, Samsung Internet, Vivaldi, UC, Safari and more ā with Android Intents and iOS URL Schemes.
Live demo: https://browser-switcher-demo.jakkimcfly.com
GitHub: https://github.com/jakkimcfly/browser-switcher
npm: https://www.npmjs.com/package/browser-switcher
Have you ever needed to redirect users from one browser to another? For example, when you want a link to be opened directly in Chrome, Firefox, or another browser instead of the current one?
Thatās exactly what my new npm package browser-switcher does. It helps you:
- Seamlessly redirect users.
- Fully typed (TypeScript).
- Detect the current browser.
- Supported 10+ browsers.
- Detect In-App browser (e.g., Facebook, Instagram, TikTok).
In this post, Iāll walk you through the basics of using browser-switcher
, give you a working example, and briefly cover its core methods.
š§ Installation
You can install the package via npm or yarn:
npm install browser-switcher
# or
yarn add browser-switcher
š² Basic Usage Example
Imagine you want to force open a link in Google Chrome when the user clicks a button:
import BrowserSwitcher from 'browser-switcher';
document.getElementById('open-chrome')?.addEventListener('click', () => {
try {
BrowserSwitcher.open({
targetUrl: 'https://example.com',
platform: 'auto',
browser: 'chrome',
});
} catch (error) {
console.error('Browser switching failed:', error);
}
});
š On Android, this will use intent://
to launch Chrome.
š On iOS, it will use the Chrome URL scheme (googlechrome://
).
š If the browser is not installed, behavior depends on the browser ā some may redirect to Google Play, others may just fail (e.g., DuckDuckGo, Firefox).
Full details are in the README.
š Example
You can find a working demo in the example folder of the repository.
šÆ Conclusion
With browser-switcher
, you can easily:
- Detect the current browser.
- Open links in other browsers.
- Provide users with a simple UI to choose their browser.
š Check it out here: GitHub Repo
ā Thatās it! In just a few lines of code, you can reliably switch users between browsers on both Android and iOS.