javascript - 是否可以使用 webview 注入(inject)我的 javascript 以在任何网页内禁用 javascript?

标签 javascript android html webview

我正在为我的自定义浏览器开发断开连接或 firefox 中的 ghosty 插件,以停止各种网页内的一些跟踪脚本,但未能找到任何帮助来禁用在 webview 中加载的所有网页内的跟踪。

经过一些搜索,我找到了通过从要加载的网页中删除脚本来停止跟踪的方法。 但未能找到解决方案以从加载到 webview 中删除所有这些脚本,请帮忙..

最佳答案

好的,所以我找到了在 WebViewClient 的方法 shouldInterceptRequest 的帮助下仅阻止加载页面中的一些 javascript 的解决方案 我使用简单的返回空响应,没有任何数据像文档中写的那样像往常一样加载。

Notify the host application of a resource request and allow the application to return the data. If the return value is null, the WebView will continue to load the resource as usual. Otherwise, the return response and data will be used. NOTE: This method is called on a thread other than the UI thread so clients should exercise caution when accessing private data or the view system.

public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
     if(myConditionFullFilled){
          return new WebResourceResponse("text/css", "UTF-8", null);
         } 
        return super.shouldInterceptRequest(view, url);
    }

关于javascript - 是否可以使用 webview 注入(inject)我的 javascript 以在任何网页内禁用 javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43066272/

相关文章:

javascript - 由于更多的 for 循环导致性能问题

javascript - Window 和 Screen 对象属于 DOM API 还是 BOM API?

javascript - 如果 src 为空或参数,我如何更改图像占位符的可见性?

javascript - 如何从渲染的 html 将初始数据添加到 angularjs 应用程序

javascript - JavaScript 中的反转十六进制 0x

java - 仅添加新表时的房间数据库迁移

android - 我可以从名称中获取图像文件的 Uri 吗?

android - ExoPlayer 播放错误

javascript - 需要每 3 秒更改一次 div 背景?

html - <DIV> 向下移动窗口调整大小