fix(android): async webview constrcution#10
Merged
Conversation
Collaborator
friofry
commented
May 18, 2026
- fixes deadlock [browser] freezes when I click on a bookmark on an empty tab status-app#20886
* qt create webview * android ui thread focuses URL field fixes status-im/status-app#20886
0817643 to
1335f48
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses an Android deadlock during WebView construction by making WebView initialization non-blocking and queueing UI-thread actions until the WebView is ready. It also improves early bridge/script injection behavior and adds test/CI coverage for the new pending-action mechanism.
Changes:
- Make Android
WebViewcreation asynchronous (remove blocking wait) and introduce aPendingActionQueueto replay queued UI actions once initialization completes. - Add document-start script injection support (via reflective
androidx.webkitAPIs) and update bridge/bootstrap readiness signaling in JS. - Add a small Java test for the pending-action queue and wire it into CI; remove a JNI “getWebView” validation call that could contribute to deadlock.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
mobilewebview/src/js/bootstrap_page.js |
Exposes a synchronous window[ns].__ready flag before emitting qtWebChannelReady. |
mobilewebview/src/android/mobilewebviewbackend_android.cpp |
Removes eager getWebView() call during Java object setup. |
mobilewebview/android/src/org/mobilewebview/PendingActionQueue.java |
Adds a queue to defer actions until WebView initialization completes. |
mobilewebview/android/src/org/mobilewebview/MobileWebView.java |
Switches to async initialization, queues main-thread work, and adds document-start injection via reflection. |
mobilewebview/android/tests/org/mobilewebview/MobileWebViewPendingActionsTest.java |
Adds a basic ordering/behavior test for PendingActionQueue. |
.github/workflows/ci.yml |
Compiles/runs the new Java utility test in CI. |
Comments suppressed due to low confidence (1)
mobilewebview/android/src/org/mobilewebview/MobileWebView.java:888
- buildAllowedOriginRules() falls back to adding "" when the allowed-origins list is empty. This changes the effective meaning of an empty allowlist from "deny all" (OriginUtils.isOriginAllowed returns false for empty lists) to "inject into all origins" for document-start injection, which can unintentionally expose the bridge/user scripts on untrusted origins (including subframes) when allowedOrigins is temporarily unset/empty. Consider only including "" when it is explicitly configured by the caller (or return an empty set and make registerDocumentStartScripts()/configureBridgeInjectionMode disable document-start injection when there are no allowed origins).
private static Set<String> buildAllowedOriginRules(List<String> allowedOrigins) {
Set<String> allowedOriginRules = new HashSet<>();
for (String origin : allowedOrigins) {
if (origin != null && !origin.isEmpty()) {
allowedOriginRules.add(origin);
}
}
if (allowedOriginRules.isEmpty()) {
allowedOriginRules.add("*");
}
return allowedOriginRules;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
379
to
+385
| public void evaluateJavaScript(String script) { | ||
| runOnMainThread(() -> | ||
| runOnMainThread(() -> { | ||
| if (mWebView == null) return; | ||
| mWebView.evaluateJavascript(script, result -> | ||
| withNativePtr(ptr -> nativeOnJavaScriptResult(ptr, result != null ? result : "", "")) | ||
| ) | ||
| ); | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.