Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console message captured by onConsoleMessage is incomplete

I have WebView into which I'm loading a webpage, I have set the custom WebChromeClient to capture console logs but I've found it is incomplete comparing to the console in browser. The message returned by cm.message() doesnt contain all values passed to the console methods.

console.log("Test");//Test

will work but following will only display first param

console.log("test", 1);//test - expected test 1

is there any way to workaround it?

like image 401
Lukasz 'Severiaan' Grela Avatar asked Aug 22 '26 11:08

Lukasz 'Severiaan' Grela


1 Answers

An interesting bug!

You can wrap console.log in your own function that concatenates all the arguments into a single string. The JavaScript code for doing this is below:

(function() { 
    var oldLog = console.log;
    console.log = function() { 
        oldLog.call(console, Array.prototype.slice.call(arguments).join(" "));
    }
})();

You can inject it into your page with WebView.loadUrl('javascript:...'), or WebView.evaluateJavascript.

like image 161
Mikhail Naganov Avatar answered Aug 24 '26 01:08

Mikhail Naganov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!