Problem with contentblocker in appwebview

319

Android

InAppWebView(
initialOptions: InAppWebViewGroupOptions(
    android: AndroidInAppWebViewOptions(
      useShouldInterceptRequest: true,
    ),
),
androidShouldInterceptRequest: (controller, request) async {
  var url = request.url.toString();
  var i = 0;
  while(i<adblock.length){
    if(url.contains(adblock.elementAt(i))){
      return WebResourceResponse();
    }
    i++;
  }
});

my variable adblock is just list for filter like that

List<String> ads(){
List<String> list = [];
list.add("imasdk.googleapis.com");
list.add("rtmark.net");
list.add("offerimage.com");
list.add("xadsmart.com");
list.add("cloudfront.net");
list.add("in-page-push.com");
return list;}

you can add others if you want

Ios

you must use ContentBlocker with regex

Share:
319
linkkader
Author by

linkkader

Updated on December 02, 2022

Comments

  • linkkader
    linkkader over 1 year

    hi i try block ads using ContentBlocker but but it doesn't work , i try with androidShouldInterceptRequest and it working fine but not available on ios for test i just try block all url contains "voiranime" and i use that regex ".*voiranime.*" but not working

    contentBlockers:[
               ContentBlocker(
                   trigger: ContentBlockerTrigger(urlFilter: ".*voiranime.*",),
                   action: ContentBlockerAction(
                       type: ContentBlockerActionType.BLOCK
                   )
               ),
             ],
    
    • Martin Wittick
      Martin Wittick over 2 years
      Did you find any solution to prevent ads or popups???
    • linkkader
      linkkader over 2 years
      @MartinWittick i add answer