[Bug]: Plugin call after navigation can be answered before reply proxy is updated

未关闭 适合新手
#8,616 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
android, java
领域
mobile-dev

调研方向

从 MessageHandler.java 开始,检查导航或重新加载期间回复代理更新与消息发布的顺序。在 Android 上通过快速读取 Preferences 重现该问题,然后验证新页面发起的插件调用使用更新后的代理并得到解析,而不是被静默丢弃。

由索引模型根据 Issue 内容生成。

描述

triage
Capacitor Version

@capacitor/cli: 8.4.0
@capacitor/core: 8.4.0
@capacitor/android: 8.4.0

Other API Details
npm: 11.0.0
node: 22.13.0
Platforms Affected
  • iOS
  • Android
  • Web
Current Behavior

After a reload or navigation, a fast plugin call (e.g. a Preferences read, which is how the bug appeared for us) can potentially never resolve as it uses the previous proxy instead of the updated one. The cause are these lines in MessageHandler.java:

if (isMainFrame) {
    postMessage(message.getData());
    javaScriptReplyProxy = replyProxy;
}

In case of a fast plugin call, sendResponseMessage() is reached before the proxy is updated, and therefore still uses the previous proxy and is silently dropped. Later calls work, and there's also no issue upon first page load as, at this point, javaScriptReplyProxy is null and the old evaluateJavascript path is used instead.

Expected Behavior

All plugin calls of the new page should go through the updated proxy.

Project Reproduction

Reproduced in a private repo

Additional Information

The bug is avoidable with android.useLegacyBridge = true as this routes every response through evaluateJavascriptand avoids the proxy entirely.

I've locally fixed the bug by swapping the two lines above, i.e., making sure the proxy is updated before the message post.

主要语言
TypeScript
星标
16.7k
派生
1.3k
平均合并
3 天 10 小时
30 天内合并 PR
10

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ionic-team/capacitor 的其他 Issue

查看 ionic-team/capacitor 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。