feat: await promises in WebView JS eval via token-based poll loop#261
Conversation
WalkthroughWebViewAgent's JavaScript evaluation method is refactored to support async expressions. A per-process evaluation token counter is introduced. The 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@agents/android/java/WebViewAgent.java`:
- Around line 91-97: evaluateExpression currently only treats
JSONTokener(raw).nextValue() as valid when it's a String, which causes timeouts
if the bridge returns an unquoted object/array or if JSON.stringify inside
buildEvalScript throws; update evaluateExpression to accept JSONObject/JSONArray
(and any non-String tokenized result) by converting tokenized.toString() (or raw
when tokenized is not a String) into outcomeJson so the poll succeeds, and also
harden buildEvalScript so its Promise then/catch handlers each wrap
JSON.stringify in try/catch and always assign a string value to
window.__mwEval[token] (on both success and failure) to avoid leaving the slot
unset; reference evaluateExpression, buildPollScript, buildEvalScript,
AndroidBridge.evalJs, and JSONTokener in the change so you locate the spots to
modify.
- Around line 123-136: In WebViewAgent.buildEvalScript the injected body can
fail to parse before the outer try/catch and JSON.stringify errors inside the
then() success handler can escape the rejection handler, leaving
window.__mwEval[token] unwritten; to fix, compile the user body inside the
script try block (e.g., create the function via new Function(...)/Function.apply
inside the try so SyntaxError is caught) and make setting window.__mwEval[token]
resilient by wrapping JSON.stringify (or the assignment) in its own try/catch in
both fulfillment and rejection paths, and/or replace .then(success, failure)
with .then(success).catch(failure) so exceptions in the success handler are
forwarded to the common failure handler; update references to token and
window.__mwEval in buildEvalScript accordingly so every code path writes a JSON
string into window.__mwEval[token].
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 11f28dda-5589-4bba-ac77-a15f79ed2546
📒 Files selected for processing (1)
agents/android/java/WebViewAgent.java
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
agents/ios/bridge.m (1)
132-132:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUpdate timeout message to reflect the actual API in use.
The error message still references "evaluateJavaScript" but the code now uses
callAsyncJavaScript.📝 Proposed fix
- return @{@"__error": @"evaluateJavaScript timed out"}; + return @{@"__error": @"JavaScript evaluation timed out"};🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@agents/ios/bridge.m` at line 132, The timeout error message is stale — update the returned error string (the @{@"__error": ...} return) so it references the current API callAsyncJavaScript instead of evaluateJavaScript; locate the return in the bridge.m function that returns @{@"__error": @"evaluateJavaScript timed out"} and change the message to something like @"callAsyncJavaScript timed out" (or a similarly accurate phrasing).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@agents/ios/bridge.m`:
- Line 132: The timeout error message is stale — update the returned error
string (the @{@"__error": ...} return) so it references the current API
callAsyncJavaScript instead of evaluateJavaScript; locate the return in the
bridge.m function that returns @{@"__error": @"evaluateJavaScript timed out"}
and change the message to something like @"callAsyncJavaScript timed out" (or a
similarly accurate phrasing).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 60564526-3d1c-4469-9eb8-f69d01977c8b
📒 Files selected for processing (3)
agents/android/java/WebViewAgent.javaagents/ios/bridge.mgo.mod
🚧 Files skipped from review as they are similar to previous changes (1)
- agents/android/java/WebViewAgent.java
No description provided.