Skip to content

fix: sendLogToJavaScript#2111

Merged
RohitKushvaha01 merged 4 commits into
Acode-Foundation:mainfrom
RohitKushvaha01:fix_sendJs
May 18, 2026
Merged

fix: sendLogToJavaScript#2111
RohitKushvaha01 merged 4 commits into
Acode-Foundation:mainfrom
RohitKushvaha01:fix_sendJs

Conversation

@RohitKushvaha01
Copy link
Copy Markdown
Member

@RohitKushvaha01 RohitKushvaha01 commented May 18, 2026

Fixed crash from: #2106

Related to #2105

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 18, 2026

Greptile Summary

This PR fixes a crash in sendLogToJavaScript by adding a typeof window.log === 'function' guard in the evaluated JavaScript (so an undefined window.log falls back to console.log), correcting the lambda block syntax, and wrapping the evaluateJavascript call in a try-catch inside the Runnable.

  • The JavaScript-level guard is the substantive fix: it prevents a JS TypeError when window.log has not yet been defined at evaluation time.
  • The lambda is now properly block-form (() -> { ... }), resolving the previous compile error; the try-catch is correctly placed inside the lambda so it guards the actual execution.
  • The Log.e call on the catch path passes e.getMessage() which can be null; prefer Log.e(TAG, msg, e) to capture the full stack trace.

Confidence Score: 4/5

The fix is now compilable and the immediate crash is addressed, but the WebView cast path has a silent-failure mode that could drop log messages without indication.

The core JavaScript-level fix (the typeof guard) addresses the root crash. The lambda syntax and try-catch placement are now correct. The one remaining concern is that if the android.webkit.WebView cast fails at runtime, log messages are silently swallowed — the catch block only logs internally and gives no indication to callers that JS evaluation was skipped entirely.

src/plugins/system/android/com/foxdebug/system/System.java — specifically the WebView cast and error handling in sendLogToJavaScript

Important Files Changed

Filename Overview
src/plugins/system/android/com/foxdebug/system/System.java sendLogToJavaScript now guards against undefined window.log via a typeof check in the JS string, fixes the lambda block syntax, and wraps the WebView evaluation in a try-catch inside the runnable. Minor: Log.e call uses getMessage() which can be null.

Sequence Diagram

sequenceDiagram
    participant BG as Background Thread
    participant UI as UI Thread
    participant WV as WebView (JS)

    BG->>UI: cordova.getActivity().runOnUiThread(lambda)
    UI->>UI: "try { cast to android.webkit.WebView }"
    alt cast succeeds
        UI->>WV: evaluateJavascript(js, null)
        WV->>WV: "if typeof window.log === function window.log else console.log"
    else cast fails (ClassCastException)
        UI->>UI: catch(Exception e) Log.e(TAG, message)
    end
Loading

Reviews (4): Last reviewed commit: "fix: lamda issue" | Re-trigger Greptile

Comment thread src/plugins/system/android/com/foxdebug/system/System.java Outdated
@RohitKushvaha01
Copy link
Copy Markdown
Member Author

@greptileai

Comment thread src/plugins/system/android/com/foxdebug/system/System.java Outdated
@RohitKushvaha01
Copy link
Copy Markdown
Member Author

@greptileai

Comment thread src/plugins/system/android/com/foxdebug/system/System.java Outdated
@RohitKushvaha01
Copy link
Copy Markdown
Member Author

@greptileai

@RohitKushvaha01 RohitKushvaha01 merged commit 5e99727 into Acode-Foundation:main May 18, 2026
7 checks passed
@RohitKushvaha01 RohitKushvaha01 deleted the fix_sendJs branch May 18, 2026 11:14
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.

1 participant