Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GET net::ERR_FAILED error when probing for extension

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:

enter image description here

enter image description here

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');
like image 755
sidanmor Avatar asked May 29 '16 19:05

sidanmor


2 Answers

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 communication. 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).

like image 165
Xan Avatar answered Oct 13 '22 00:10

Xan


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 comments:

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. :)

like image 35
Teyam Avatar answered Oct 13 '22 01:10

Teyam