Skip to content

fix(android): allow synchronous replies on the modern bridge#8383

Open
richavos wants to merge 1 commit intoionic-team:mainfrom
richavos:fix-sync-first-plugin-call
Open

fix(android): allow synchronous replies on the modern bridge#8383
richavos wants to merge 1 commit intoionic-team:mainfrom
richavos:fix-sync-first-plugin-call

Conversation

@richavos
Copy link

@richavos richavos commented Mar 9, 2026

Rationale

On Android's modern bridge, MessageHandler stored javaScriptReplyProxy after dispatching the message to postMessage(...).

That meant a plugin that resolved synchronously during the first modern-bridge call could reach sendResponseMessage() before the reply proxy was available, causing Capacitor to fall back to the legacy WebView JavaScript response path.

This is unreliable as a fallback, so can result in promises never being settled for plugin calls.

Changes

This change stores the reply proxy before dispatching the message, so that all plugin calls should be settlable, and adds a regression test for this scenario.

Testing

To provide a minimal test, I've added a small TextUtils host-test stub so the real postMessage path can be run in the test.

I've also added two reflection-based methods that attempt to surgically insert only what is required to allow the "normal" bridge call codepath to be run.

The tradeoff here is concision against brittleness - let me know/feel free to adjust the test to fit with the project as a whole.

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation

Platforms Affected

  • Android
  • iOS
  • Web

Closes #8382

Store the JavaScript reply proxy before dispatching a modern bridge message so a plugin that resolves synchronously can reply through the modern bridge instead of falling back to WebView JavaScript execution.

Add a regression test for the first modern-bridge call and a minimal TextUtils host-test stub so the real postMessage path can run in unit tests.
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.

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

1 participant