Skip to content

fix(android): async webview constrcution#10

Merged
friofry merged 1 commit into
masterfrom
ab/issue-20886-fix-freeze
May 18, 2026
Merged

fix(android): async webview constrcution#10
friofry merged 1 commit into
masterfrom
ab/issue-20886-fix-freeze

Conversation

@friofry
Copy link
Copy Markdown
Collaborator

@friofry friofry commented May 18, 2026

* qt create webview
* android ui thread focuses URL field

fixes status-im/status-app#20886
@friofry friofry force-pushed the ab/issue-20886-fix-freeze branch from 0817643 to 1335f48 Compare May 18, 2026 10:17
@friofry friofry merged commit 71e6bf9 into master May 18, 2026
2 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 WebView creation asynchronous (remove blocking wait) and introduce a PendingActionQueue to replay queued UI actions once initialization completes.
  • Add document-start script injection support (via reflective androidx.webkit APIs) 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 : "", ""))
)
);
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants