Skip to content

[Bug]: Capacitor on Android detected as web platform after redirecting with allowNavigation #7454

@Dylancyclone

Description

@Dylancyclone

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

`npm --version`
> 10.7.0

`node --version`
> v20.11.0

Platforms Affected

  • iOS
  • 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 #5455

Here are videos showing the issue. Even though these were recorded on a simulator, the results are identical to a physical device

android.mov
ios.mov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions