Skip to content

[Bug]: first Android modern-bridge call can miss the reply proxy if synchronous #8382

@richavos

Description

@richavos

Capacitor Version

8.2.0

Other API Details

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

On Android's modern WebMessageListener bridge, MessageHandler dispatches the incoming message before it stores the JavaScriptReplyProxy for that message.

That means a plugin method that resolves synchronously during the first modern-bridge call can reach sendResponseMessage() while javaScriptReplyProxy is still null. When that happens, Capacitor falls back to the legacy WebView JavaScript response path instead of replying through replyProxy.postMessage(...).

This can make the first synchronous plugin call flaky: the native plugin resolves successfully, but the JavaScript caller may never receive the result if that legacy fallback path is ineffective at that moment.

Expected Behavior

The reply proxy for a modern bridge message should be available before plugin dispatch begins, so a synchronous response from the first call is always delivered through replyProxy.postMessage(...) and does not depend on the legacy fallback path.

Project Reproduction

.

Additional Information

Minimal failing conditions:

  1. Android modern bridge is enabled
  2. The first plugin call arrives through WebMessageListener
  3. The plugin resolves synchronously
  4. The JavaScript caller expects the normal modern reply path

The current listener ordering is effectively:

postMessage(message.getData());
javaScriptReplyProxy = replyProxy;

A focused Android unit test demonstrates the problem by asserting that the first synchronous modern-bridge call should use the reply proxy instead of WebView.post(...). Reordering those two lines makes that test pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs reproductionneeds reproducible example to illustrate the issue

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions