Is it possible to catch net::ERR_BLOCKED_BY_CLIENT?
Unfortunately you cannot catch that error message specifically, but you can catch the error itself:
$.ajax({
url: 'http://openx.net',
dataType: 'json',
success: function( data ) {
console.log( "Success:", data);
},
error: function( data ) {
console.log( "Error:", data);
}
});
Obviously the example isn't requesting JSON, but you can see that it fails and calls the error handler.
These errors are fired by Chrome when, for instance, a plugin like Adblock (as you mentioned) cancels a request.
ltw1991
I am a British/Maltese .NET/Dynamics 365 developer with a computer science degree from the University of Kent (Canterbury). When I am not customising CRM environments or writing code, I like to play 5 aside football and video games.
Updated on June 24, 2022Comments
-
ltw1991 almost 2 years
So on our site we have various searches some of which work fine and return the appropriate results. A few of them however return the javascript error:
Failed to load resource: net::ERR_BLOCKED_BY_CLIENT when I search on my machine.
I have found out that issue is that I am running AdBlocker in Google Chrome and it is AdBlocker that is causing the problem. Now I know I could just turn AdBlocker off which is fine and I have, but is there a way for me to catch this error in javascript and report to the user why they are not getting any search results?
Ideally I am after something similar to a c# try/catch.
EDIT: OK, so after some digging around and being pointed in the right direction from the comments below I think I have deduced the issue, hopefully this will help others.
After having read this it looks like what I am trying to accomplish cannot be done using the version of jQuery we are currently running (1.10.x) so I guess the solution is to use a new version of jQuery (2.x) and see if I can catch the error
-
ltw1991 over 7 yearsI have tried this but I don't get anything output to the console:
$.ajax({ type: 'GET', url: url, contentType: 'application/json', dataType: 'json', success: function (data) { //do stuff }, error: function(err) { console.log("Error:", err); } });
-
Perry Mitchell over 7 yearsI've got it working with jsbin here. Make sure ad block is on, and the error will appear in the console.
-
ltw1991 over 7 yearsI am gunna mark this as answered as your link works for me, I am clearly missing something in my code hopefully I will find out what it is! Thank you though!
-
Dr. Gianluigi Zane Zanettini about 7 yearsPlease note: this won't work with jQuery 1.x : stackoverflow.com/questions/42159558/…
-
KingRider over 6 yearsnet::ERR_CONNECTION_TIMED_OUT is different, not work a console response.
-
Perry Mitchell over 6 years@KingRider My example specifically shows ERR_BLOCKED_BY_CLIENT - I didn't mention ERR_CONNECTION_TIMED_OUT at all, and can't say if it'd ever work for that specific error.
-
Portekoi over 3 yearsQuestion is about how to catch this error, not avoid it.