capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

[Bug]: JS does not get injected into DOM if appUrl contains query parameter

Open theigl opened this issue 1 year ago • 2 comments

Capacitor Version

:pill: Capacitor Doctor :pill: Latest Dependencies: @capacitor/cli: 6.1.0 @capacitor/core: 6.1.0 @capacitor/android: 6.1.0 @capacitor/ios: 6.1.0 Installed Dependencies: @capacitor/cli: 6.1.0 @capacitor/android: 6.1.0 @capacitor/core: 6.1.0 @capacitor/ios: 6.1.0 [success] Android looking great! :ok_hand:

Other API Details

No response

Platforms Affected

  • [ ] iOS
  • [X] Android
  • [ ] Web

Current Behavior

JS does not get injected into the page when appUrl contains a query parameter.

The Android Bridge attempts to normalize the path before passing it as allowedOrigins to WebViewCompat.addDocumentStartJavaScript, but it does not strip query parameters:

https://github.com/ionic-team/capacitor/blob/0ad0c3f23e1c62ade5081878e345e74f963b9ea5/android/capacitor/src/main/java/com/getcapacitor/Bridge.java#L257-L266

Android includes the query parameter when evaluating allowedOrigins and JS does not get injected into the DOM.

Expected Behavior

JS gets injected into the page when the appUrl contains query parameters.

Project Reproduction

https://github.com/divatzk/capacitor-server-url-query-parameter/tree/main/capacitor-app

Additional Information

The issue can be seen in the sample project where server.url contains a query parameter:

  "server": {
    "url": "https://capacitor-server-url-param.web.app?param=test"
  }

Run the app as is and you should get this result:

capacitor-not-defined

If the query parameter is removed, Capacitor JS gets injected successfully:

capacitor-defined

theigl avatar Jun 18 '24 12:06 theigl

This would probably be fixed by passing all URLs in allowNavigation instead of the server.url as suggested in #7454.

theigl avatar Jun 20 '24 04:06 theigl

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.

ionitron-bot[bot] avatar Jun 24 '24 13:06 ionitron-bot[bot]

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[bot] avatar Aug 15 '24 14:08 ionitron-bot[bot]