Android block ads in webview

前端 未结 3 883
余生分开走
余生分开走 2020-12-06 03:07

I want to implement a mechanism in a custom webview client (without JavaScript injection) that can block ads. Is a way I can catch ads and replace them with other ads from a

3条回答
  •  悲哀的现实
    2020-12-06 03:15

    To implement this, you have two options:

    1. Use Javascript injected code to do this (which you explicitely said, don't want)
    2. In WebView, instead of "http://example.com" load "http://myproxy.com?t=http://example.com" (properly escaped, of course) and setup "myproxy.com" to be a proxy which will fetch the upstream page (given in "t" query parameter, or in any other way) and replace ads with the trusted ones before sending response to the client. This will be pretty complex, though, because ads can be in many forms, they're usually Javascript injected themselves and you'd probably need to rewrite a lot of URL's in the fetched HTML, CSS and JS files etc.

提交回复
热议问题