Skip to content

[Feature]: Allow configuration of Android WebView Origins for the bridge to work on subdomains #7993

Closed as duplicate

Description

@RTK

Description

Using only the configured hostname results in the bridge not available in subdomains

Platforms

  • iOS
  • Android
  • Web

Request or proposed solution

We have a use case, where we want to never load a local index.html file but load a remote server url e.g., example.org.

Thus we are configuring Capacitor to use the https scheme and the example.org and the https://example.org serverUrl.

Now we are encountering an issue when a redirect is happening on startup, such as https://example.org -> https://www.example.org (subdomain www). The Bridge does not inject JavaScript.

Right now this line in Bridge.java limits our use case:

WebViewCompat.addDocumentStartJavaScript(webView, injector.getScriptString(), Collections.singleton(allowedOrigin));

A single value is used in the Collection which is example.org where www.example.org does not match example.org. To navigate around this issue we were using the workaround to use *.example.org as our hostname, the wildcard matches any subdomain. With this configuration we unfortunately encountered some issues on some devices with XHR and CORS since it seems to match its origin (example.org) with the hostname (*.example.org).

In my opinion it would be beneficial to keep the configured hostname clean (-> example.org) but additionally provide values that will be added in the Bridge as allowed origins.

Alternatives

No response

Additional Information

Example capacitor.config.ts:

export default {
  server: {
    hostname: 'example.org',
    androidScheme: 'https',
    url: 'https://www.example.org'
  }
}

Activity

  1. ionitron-bot commented on May 29, 2025

    @ionitron-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.

  2. locked and limited conversation to collaborators on May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions