最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it possible to catch net::ERR_BLOCKED_BY_CLIENT? - Stack Overflow

programmeradmin4浏览0评论

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

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

Share Improve this question edited May 23, 2017 at 12:06 CommunityBot 11 silver badge asked Nov 10, 2016 at 12:11 ltw1991ltw1991 3251 gold badge4 silver badges12 bronze badges 8
  • Possible duplicate of: stackoverflow.com/questions/27277656/… As this occurs with network requests, you can detect a failure if it's an XHR. If it's an asset then it's a bit more difficult. This is Chrome blocking some request by instruction. – Perry Mitchell Commented Nov 10, 2016 at 12:19
  • So it's not strictly XHR, it's using $.getJSON() to send the request and retrieve the results. I had a look here: stackoverflow.com/questions/1740218/… And it looks like I am going to have to change how the request is sent... – ltw1991 Commented Nov 10, 2016 at 12:46
  • But that link shows that you can handle errors (stackoverflow.com/a/5553540/966338) with .error(function() { alert("error"); }).. Does that not work for you in this case? – Perry Mitchell Commented Nov 11, 2016 at 8:55
  • If you're looking to catch that error specifically from within the browser - unfortunately it's not going to be possible. You'll only ever get a generic error message. – Perry Mitchell Commented Nov 11, 2016 at 9:02
  • 1 Somewhat off topic, but I was surprised to find out that bug notification systems like Bugsnag and Sentry are blocked by Ad Blockers like uBlock Origin, etc. That sucks. – Joshua Pinter Commented Mar 11, 2021 at 16:06
 |  Show 3 more comments

2 Answers 2

Reset to default 11

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.

*For those like to me trying to get around it....

If you have any Ad Blockers, disable them for the URL.

发布评论

评论列表(0)

  1. 暂无评论