简体   繁体   English

在Android WebView中禁用console.assert

[英]Disable console.assert in Android WebView

I have an Android WebView that loads .js files containing several console.assert(...) calls. 我有一个Android WebView,它加载包含多个console.assert(...)调用的.js文件。

I would like to disable all console.assert calls when running those scripts in the Android WebView. 在Android WebView中运行这些脚本时,我想禁用所有console.assert调用。 It is possible to do so? 有可能这样做吗? Could we imagine to do so only in certain build configuration/flavors? 我们可以想象仅在某些构建配置/样式中这样做吗?

Many thanks for your help. 非常感谢您的帮助。

I didn't tried , also not worked on it : i think if there is console message then you should have to return false .Try this but don't know it's work or not 我没有尝试过,也没有做过:我认为如果有控制台消息,那么您应该返回false。尝试一下,但不知道它是否有效

webView.setWebChromeClient(new WebChromeClient() 
{
   @Override
   public boolean onConsoleMessage(ConsoleMessage cm) {
      Log.d("TAG", cm.message() + " at " + cm.sourceId() + ":" + cm.lineNumber());
      return false;
   }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM