[Bug]: Android does not inject the Capacitor bridge after navigating to an allowNavigation URL
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
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 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
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ionic-team/capacitor
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ionic-team/capacitor#8759 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Plugin call after navigation can be answered before reply proxy is updatedCó thể đã có người làm @MateStrysewske đã nhận 71 ngày trước. Đang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
ionic-team/capacitor#8616 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ionic-team/capacitor#8574 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SystemBars: safe area CSS injection throws "Cannot read properties of null" on startup (Android 16)Có thể đã có người làm @kttalley đã nhận 62 ngày trước. Đang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ionic-team/capacitor#8530 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(android): remove unchecked Java compilation warningsCó thể đã có người làm @Ajamuar đã nhận 15 ngày trước. Đang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ionic-team/capacitor#8529 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của ionic-team/capacitor
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
prio:low scope:world
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
OliverRomhagen/vrigstad-joyride#849 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
genfeedai/genfeed.ai#11916 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
erkamyaman/rust-anything#1153 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
The Phase 5 report says 0.3.0 waits for the live checkCó thể đã có người làm @fzn0x đã nhận hôm nay. Đang mởdocumentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày