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]: JS does not get injected into DOM if appUrl contains query parameter #7517

Closed
1 of 3 tasks
theigl opened this issue Jun 18, 2024 · 3 comments · Fixed by #7545
Closed
1 of 3 tasks

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

theigl opened this issue Jun 18, 2024 · 3 comments · Fixed by #7545
Labels
platform: android type: bug A confirmed bug report

Comments

@theigl
Copy link

theigl commented Jun 18, 2024

Capacitor Version

💊 Capacitor Doctor 💊
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! 👌

Other API Details

No response

Platforms Affected

  • iOS
  • 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:

String allowedOrigin = appUrl;
Uri appUri = Uri.parse(appUrl);
if (appUri.getPath() != null) {
if (appUri.getPath().equals("/")) {
allowedOrigin = appUrl.substring(0, appUrl.length() - 1);
} else {
allowedOrigin = appUri.toString().replace(appUri.getPath(), "");
}
}
WebViewCompat.addDocumentStartJavaScript(webView, injector.getScriptString(), Collections.singleton(allowedOrigin));

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 theigl added the triage label Jun 18, 2024
@theigl
Copy link
Author

theigl commented Jun 20, 2024

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

@jcesarmobile jcesarmobile added the type: bug A confirmed bug report label Jun 24, 2024
Copy link

ionitron-bot bot commented Jun 24, 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 Aug 15, 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 Aug 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: android type: bug A confirmed bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants