Repository navigation
fix(android): 修复登录自动提取失败(evaluateJavascript 返回 JSON 编码结果) - #30
Merged
Merged
Conversation
There was a problem hiding this comment.
一句话总结
修复 Android 登录自动提取失败:将 evaluateJavascript 中返回 JSON 字符串改为直接返回对象,适配 Android 回调的 JSON 编码语义。
🔴 红线 / 严重问题
无。改动未触碰任何红线(无第三方依赖、无 Token 存储变更、无平台接口臆造、无 CI 破坏)。
🟡 建议改进
-
android/src/DeepSeekMeter/TokenLoginWebView.kt:239-243:注释中「A4 真机发现」表述不够严谨,建议补充具体的 Android 版本/WebView 版本信息,便于后续维护者复现和验证。例如改为「Android 14 + Chrome WebView 120 真机发现」。
-
android/src/DeepSeekMeter/TokenLoginWebView.kt:243:修改后的 JS 直接返回对象,但
evaluateJavascript回调中result的类型处理逻辑未在 diff 中展示。建议确认回调中对result的解析方式是否已适配(例如JSONObject(result)解析对象而非字符串),若解析逻辑未同步修改,可能导致新的解析错误。
🔵 小问题 / 风格
- android/src/DeepSeekMeter/TokenLoginWebView.kt:239:注释中「勿照搬」的表述略显口语化,建议改为「语义不同,不可直接复用」以保持注释风格统一。
审查结论
改动方向正确,修复了 Android 与 iOS 在 evaluateJavascript 回调语义上的差异,注释也清楚说明了原因。建议确认回调解析逻辑是否同步适配,并补充更具体的真机环境信息后即可合并。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
描述
真机 QA(#16 后续复测)定位到的自动提取失败根因(第 4 个真机 bug,A3 遗留):
现象
WebView 内登录成功后(localStorage 已含
userToken = {"value":"<64字符 Bearer>"}),App 状态永远停在「尚未就绪,等待登录完成…」。根因
Android
evaluateJavascript的回调收到的是 JSON 编码的求值结果:注入脚本return JSON.stringify({...})的完成值是一个字符串,回调里就变成带引号的"{\"ok\":true,...}"——JSONObject(result)解析字符串必然抛JSONException,被 catch 吞掉 → 每次轮询都走「尚未就绪」分支。iOS WKWebView 的
evaluateJavaScript返回裸值,同样的写法在 iOS 正常、Android 必然失败(A3 从未真机验证过自动提取路径,故潜伏至今)。修复
注入脚本改为直接返回对象:
return { ok: true, data: pairs },由evaluateJavascript序列化为 JSON 对象,JSONObject(result)正常解析。并加注释说明平台语义差异,防止照搬 iOS 写法回归。验证
关联
变更类型
边界检查