diff --git a/src/plugins/system/android/com/foxdebug/system/System.java b/src/plugins/system/android/com/foxdebug/system/System.java index 61096a5c4..e0496c531 100644 --- a/src/plugins/system/android/com/foxdebug/system/System.java +++ b/src/plugins/system/android/com/foxdebug/system/System.java @@ -115,7 +115,6 @@ import android.os.Build; - public class System extends CordovaPlugin { private static final String TAG = "SystemPlugin"; @@ -633,19 +632,21 @@ public void run() { private void sendLogToJavaScript(String level, String message) { final String js = - "window.log(" + JSONObject.quote(level) + ", " + JSONObject.quote(message) + ");"; - cordova - .getActivity() - .runOnUiThread( - new Runnable() { - @Override - public void run() { - webView.evaluateJavascript(js, null); - } - } - ); - } + "if (typeof window.log === 'function')" + + " window.log(" + JSONObject.quote(level) + ", " + JSONObject.quote(message) + ");" + + "else" + + " console.log(" + JSONObject.quote(level) + ", " + JSONObject.quote(message) + ");"; + cordova.getActivity().runOnUiThread(() -> { + try { + ((android.webkit.WebView) webView.getEngine().getView()) + .evaluateJavascript(js, null); + } catch (Exception e) { + Log.e(TAG, "Failed to send log to JavaScript: " + e.getMessage()); + } + }); + } + // Helper method to determine MIME type using Android's built-in MimeTypeMap private String getMimeTypeFromExtension(String fileName) { String extension = "";