idan mor idan mor - 8 months ago 66
Javascript Question

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

. 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
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');};'GET', href);

Xan Xan

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