Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Capacitor on Android detected as web platform when server.url contains fragment on WebViews that support DOCUMENT_START_SCRIPT #7596

Closed
1 of 3 tasks
hbordersTwitch opened this issue Aug 1, 2024 · 2 comments · Fixed by #7607
Labels
type: bug A confirmed bug report

Comments

@hbordersTwitch
Copy link

hbordersTwitch commented Aug 1, 2024

Capacitor Version

[warn] The bundledWebRuntime configuration option has been deprecated. Can be safely deleted.
💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 6.1.1
  @capacitor/core: 6.1.1
  @capacitor/android: 6.1.1
  @capacitor/ios: 6.1.1

Installed Dependencies:

  @capacitor/cli: 6.1.1
  @capacitor/ios: 6.1.1
  @capacitor/android: 6.1.1
  @capacitor/core: 6.1.1

[success] iOS looking great! 👌
[success] Android looking great! 👌

Other API Details

$ npm --version
10.7.0
$ node --version
v22.2.0
$ pod --version
1.15.2

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

When I run capacitor with a server.url that includes a url fragment (https://example.com#foo) on an API 34 Android emulator (or any emulator that supports WebViewFeature.DOCUMENT_START_SCRIPT), Capacitor detects the runtime as web. I can open the WebView in the Chrome Inspector, and run the following in the console:

> Capacitor.platform
<- 'web'

If I remove the fragment from the server.url (https://example.com), then everything works fine. I can open the WebView in the Chrome Inspector, and run the following in the console:

> Capacitor.platform
<- 'android'

Expected Behavior

When I run capacitor with a server.url that includes a url fragment (https://example.com#foo) on an API 34 Android emulator (or any emulator that supports WebViewFeature.DOCUMENT_START_SCRIPT), Capacitor detects the runtime as android, and all plugins work normally.

Project Reproduction

https://github.com/hbordersTwitch/capacitor-server-url-fragment-bug

  • main shows a server.url without a fragment and things working normally
  • server_url_fragment_demo shows a server.url with a fragment and only a / path, which demonstrates the bug on if (appUri.getPath().equals("/")) { path of Bridge.java
  • server_url_fragment_demo_2 shows a server.url with a fragment and a non-/ path, which demonstrates the bug on the else (appUri.getPath().equals("/")) { path of Bridge.java

Additional Information

#7454 is related because it involves allowedOrigin rules.

This bug is worse when server.url contains a path (https://example.com/#foo) or a port (https://example.com:8443#foo) because addDocumentStartJavaScript throws an exception in those cases.

Copy link

ionitron-bot bot commented Aug 5, 2024

This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.

Copy link

ionitron-bot bot commented Sep 6, 2024

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A confirmed bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants