ionic-team / ionic-team/capacitor
[Bug]: Capacitor on Android detected as web platform after redirecting with `allowNavigation`
- Dominant language
- TypeScript
- Stars
- 16.7k
- Forks
- 1.3k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 10
Description
### Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 6.0.0
@capacitor/core: 6.0.0
@capacitor/android: 6.0.0
@capacitor/ios: 6.0.0
Installed Dependencies:
@capacitor/cli: 6.0.0
@capacitor/core: 6.0.0
@capacitor/ios: 6.0.0
@capacitor/android: 6.0.0
[success] iOS looking great! 👌
[success] Android looking great! 👌
### Other API Details
```Shell
`npm --version`
> 10.7.0
`node --version`
> v20.11.0
```
### Platforms Affected
- [ ] iOS
- [X] Android
- [ ] Web
### Current Behavior
After redirecting to an external URL that is allowed in the `server.allowNavigation` config setting, an android app reports being on a web platform instead of android.
This can be seen by calling `Capacitor.getPlatform()` (which returns `android` before redirecting and `web` after redirecting) or by trying to use a native API, which will either fallback to the web version of the API, or fail to run at all
All this works on iOS, where after redirecting, the app can still use native iOS APIs
### Expected Behavior
After redirecting, the android app should still have access to all the native Android APIs (and report itself as being an Android platform)
### Project Reproduction
https://github.com/Dylancyclone/capacitor-android-redirect/tree/main
### Additional Information
Reproduction details are in the repo, but the basic reproduction steps are as follows:
1. Serve a valid capacitor app on your computer (i.e. with `npx serve .`)
2. Add your computer's IP to the `server.allowNavigation` capacitor config setting
3. Load the application on your (real or simulated) device
4. Notice that `Capacitor.getPlatform()` returns `android` on android and `ios` on iOS
5. Redirect to the hosted server (any method works, can be `window.location.assign()`, `window.location.href = ""`, `window.location.replace()`, or redirecting through a form
6. Notice that `Capacitor.getPlatform()` now returns `web` on android but still `ios` on iOS
Possibly related to https://github.com/ionic-team/capacitor/issues/5455
Here are videos showing the issue. Even though these were recorded on a simulator, the results are identical to a physical device
https://github.com/ionic-team/capacitor/assets/19830705/076fc893-1732-4bab-9aea-b7a90b4ec142
https://github.com/ionic-team/capacitor/assets/19830705/4522dcef-bbdb-42e4-8085-7009f55176bf
Our use case is to have one app that connects to different backends on different subdomains, very similar to Slack. So far everything is working except the android app loses access to its native APIs
Contributor guide
Assessment
This issue has not been assessed yet.