Block certain url pattern while loading in webview


#1

Hi,

I am opening google.com in my webview.
Google.com calls lot of api urls while loading like google.static.com, oneclick.com inside its html
Is there a way to block ‘google.static.com’ from rendering.

Thanks


#2

I’ve not tried it yet but it seems you can intercept and cancel requests from the main NodeJS process:

http://electron.atom.io/docs/api/web-request/


#3

Awesome suggestion @erikwallace-lewdewe :slight_smile:
We just need to add below lines into main.js.
Now I am trying to use adblock filter string to block/filter the matching URL

session.defaultSession.webRequest.onBeforeRequest(['*://*./*'], function(details, callback) {
    var test_url = details.url;
    var result = /google/.test(test_url);
    if(result){
        callback({cancel: true});
    }else{
        callback({cancel: false})
    }
    
});

Thanks
Jk