capacitor
capacitor copied to clipboard
bug: external link opens in webview instead of browser
Bug Report
Capacitor Version
Capacitor Doctor
Latest Dependencies:
@capacitor/cli: 3.6.0
@capacitor/core: 3.6.0
@capacitor/android: 3.6.0
@capacitor/ios: 3.6.0
Installed Dependencies:
@capacitor/ios: not installed
@capacitor/cli: 3.6.0
@capacitor/core: 3.6.0
@capacitor/android: 3.6.0
[success] Android looking great! 👌
Platform(s)
Tested on Android, not sure about IOS
Current Behavior
Any link that contains the hostname specified in capacitor.config.json opens in webview instead of external browser.
Same behaviour with window.open and window.location
capacitor.config.json
"server": {
"hostname": "example.com",
"androidScheme": "https"
},
https://user-images.githubusercontent.com/53205290/180592532-f6f996a6-b3ec-46b7-9156-7587be6b1112.mp4
Code Reproduction
https://github.com/umeshn1/external-link-bug
npm run build && npx cap sync && npx cap open android
I think is by design to work like this so basically is not a bug but a feature :) Let me explain; The scope of the hostname field is to test your app in live reload execution. This means that whatever url put you there, it will simulate the app meaning will show in the webview so no browser will be open as it does not make sense. If you leave that to localhost, than the example.com will be opened in the browser as you are expecting...
This is a confirmed bug. The hostname is not used for live reload, for live reload you use the url field. Also the problem is the url containing the hostname, not loading the actual hostname url, in the example the problem is the app navigating to google while the hostname is example.com
Hostname can be anything, even example.com so you cannot prohibit that.
Yeah, you are right about that, but the issue has nothing to do with what you are talking about. The issue is about the page navigating to google.com, not about navigating to example.com.