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

Đang mở
#8,661 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@eric-horodyski đang làm issue này rồi.

Từ ngày 22/10/2026.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
38/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
android, java
Lĩnh vực
mobile

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
17.1k
Fork
1.3k
Merge trung bình
1 ngày 22 giờ
Pull request đã merge (30 ngày)
26

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ionic-team/capacitor

Tất cả issue của ionic-team/capacitor

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.