[Bug]: Android does not inject the Capacitor bridge after navigating to an allowNavigation URL

Abierto
#8,661 1 comentario 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@eric-horodyski ya está trabajando en esto.

Desde el 22/10/2026.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
38/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
android, java
Área
mobile

Línea de trabajo

The relevant code is in Bridge.java under android/capacitor/src/main/java/com/getcapacitor/, in loadWebView(), where the document-start script is registered for only the appUrl origin, while the allowNavigation origins are already collected in allowedOriginRules. Reproduce with the linked redirect project, then check whether plugins work on the remote page. Pull request #8429 already contains the proposed change and has no maintainer review, so check it before starting new work. Done means the bridge is injected on allowNavigation origins on Android and the existing Android tests still pass.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

capacitor-10
Capacitor Version

💊 Capacitor Doctor 💊

Latest Dependencies:

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

Installed Dependencies:

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

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

Other API Details

Platforms Affected
  • iOS
  • Android
  • Web
Current Behavior

On Android, the app starts on the local origin (https://localhost) and then navigates with window.location to a remote URL listed in server.allowNavigation (for example https://client.example.com).

allowNavigation keeps the navigation inside the WebView, but native plugins stop working on the remote page. Calls fail with UNIMPLEMENTED / "plugin is not implemented on android". window.Capacitor.PluginHeaders is empty on the new origin.

Cause: Bridge.loadWebView() registers the bridge with WebViewCompat.addDocumentStartJavaScript only for the appUrl origin:

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

allowedOrigin is derived from appUrl (https://localhost). The allowNavigation origins are already collected in allowedOriginRules, but that set is not passed to addDocumentStartJavaScript.

iOS does not have this problem. WKUserScript is injected at document start on every main-frame load, with no origin filter, so plugins keep working after the same redirect.

This is still the case in the 8.5.3 tag, and also in 9.0.0-alpha.8:
https://github.com/ionic-team/capacitor/blob/8.5.3/android/capacitor/src/main/java/com/getcapacitor/Bridge.java

Expected Behavior

After navigating to a URL allowed by server.allowNavigation, Android should keep the native bridge, same as iOS.

addDocumentStartJavaScript should receive allowedOriginRules (local origin, server.url when set, and allowNavigation origins), not only the appUrl origin. Plugins should keep working on the remote page without an app-level patch of Bridge.java.

Project Reproduction

https://github.com/Dylancyclone/capacitor-android-redirect

Additional Information

Same bug as #7454, still open. The reproduction repo linked above is the one from that issue. The one-line fix is already in #8429 (rebased from #7571) and has had no maintainer review. #7571 was closed for backlog rebase, not because the change was rejected.

Please land #8429, or apply the same change on main:

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

Reproduced on 8.5.3. The same line is still present in 9.0.0-alpha.8. Apps currently have to patch @capacitor/android themselves to get iOS parity.

Lenguaje dominante
TypeScript
Estrellas
17.1k
Forks
1.3k
Merge medio
1 d 22 h
PR fusionados (30 d)
26

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ionic-team/capacitor

Todos los issues de ionic-team/capacitor

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.