-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
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:
- Android modern bridge is enabled
- The first plugin call arrives through
WebMessageListener - The plugin resolves synchronously
- 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.