Issue
I'm trying to open a html with some javascripts in a Android Webview and getting the following error after implements onConsoleMessage of my WebChromeClient:
Uncaught ReferenceError: console is not defined -- From line 10 of file:///storage/sdcard0/TargetApp/e184bae3-5824-4e23-a26e-820ce6d32aa2/pres/fce4da510de8431bB3eeD5bdbd1c695d/fce4da510de8431bB3eeD5bdbd1c695d/html/js/target/util_Q_3bb82a6eabd3339d91ca15cb4fd6685c.js
Follows the line 10 of my file:
console = console ? console : { log : function() {}, debug : function() {}};
The strange thing is that the same code works perfectly on browsers and IOS webview.
Is there somebody that could give me a hint about what is happening?
Solution
Sorry guys, unfortunally my code example was incomplete. The problem was that javascript was setting the Strict Mode
(function($) {
'use strict';
/*
*
*/
jQuery.ajaxSettings.traditional = true;
console = console ? console : { log : function() {}, debug : function() {}};
window.c = console;
/*
* ...
*/
Specificacion says:
With strict mode, you can not, for example, use undeclared variables.
So, the correct way is:
var console = window.console = window.console ? window.console : { log : function() {}, debug : function() {}};
The only question still open is why other browsers like Chrome, Firefox and ios it works
Answered By - Victor Laerte
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.