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

javascript - GET net::ERR_FAILED error when probing for extension - Stack Overflow

programmeradmin5浏览0评论

There is a certain Chrome extension and I want to get a PNG file from it by XMLHttpRequest. If the extension is enabled, I want to write 'load' to the console, and if the extension is disabled, I want to write 'error' to the console.

It works fine, but if the Extension is disabled, Chrome writes an error in the console that I do not want to appear:

How can I remove this error from the console?

(I have tried window.onerror but it doesn't work)

The code:

var loadHref = function(href) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onload = function(){console.log('load')};
    xmlhttp.onerror = function() {console.log('error');};
    xmlhttp.open('GET', href);
    xmlhttp.send();
}
loadHref('chrome-extension://77672b238520494cba8855547dd00ba8/img/icon24.png');

There is a certain Chrome extension and I want to get a PNG file from it by XMLHttpRequest. If the extension is enabled, I want to write 'load' to the console, and if the extension is disabled, I want to write 'error' to the console.

It works fine, but if the Extension is disabled, Chrome writes an error in the console that I do not want to appear:

How can I remove this error from the console?

(I have tried window.onerror but it doesn't work)

The code:

var loadHref = function(href) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onload = function(){console.log('load')};
    xmlhttp.onerror = function() {console.log('error');};
    xmlhttp.open('GET', href);
    xmlhttp.send();
}
loadHref('chrome-extension://77672b238520494cba8855547dd00ba8/img/icon24.png');
Share Improve this question edited Oct 18, 2016 at 20:13 sidanmor asked May 29, 2016 at 19:54 sidanmorsidanmor 5,1893 gold badges26 silver badges31 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Basically, you can't silence those errors, as they are not JS errors but network errors.

Assuming your goal is to detect that a specific extension is present:

  1. Assume you need it at a specific domain and for a specific extension that is controlled by you.

    In this case, the optimal approach is externally_connectable munication. Here's a sample.

  2. Assume you need it at a non-specific domain not known in advance, but you control the extension.

    In this case, a Content Script can be injected (probably with "run_at": "document_start") and add something to the document signalling the presence of the extension. For example, injecting a page-level script that sets a variable.

  3. Assume you don't control the extension.

    Well, in that case you're screwed. If an extension won't cooperate in the manners described above, probing its web-accessible resources (if any!) is the only way to detect it, short of watching for specific content script activity in the DOM (again, if any).

Actually, there is already an existing issue on error when chrome cast extension is not installed with google-cast-sdk and based on that issues tracker, this hasn't been totally resolved yet. There are, however, given workarounds from one of the ments:

the workarounds would be to either install the Google Cast extension or disable network warnings (please note you may miss some warnings that could be on interest to you) so you don't see these additional logs.

And, you may also try with the probable solutions given in this SO post - Google chrome cast sender error if chrome cast extension is not installed or using incognito and who knows, it might help. :)

发布评论

评论列表(0)

  1. 暂无评论