Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catching Mixed content error

I'm trying to detect an XHR failing on mixed content. It looks like different browsers have different implementations:

var xhr = new XMLHttpRequest();
try {
  xhr.open('http://otherdomain/');
} catch (err) {
  console.log(err); // IE10 hits this one
}
try {
  xhr.send(); // Chrome fails here, but doesn't throw an error
} catch (err) {
  console.log(err); // No browser I've tried hits this one
}

I don't want to use autodetection (xhr.open('//otherdomain')), since the target might not support http, or https. I simply want to know the call failed, so I can show an error in my page. Is it possible to handle this correctly for all browsers?

like image 290
Jorn Avatar asked Nov 09 '22 12:11

Jorn


1 Answers

There is no way to handle this error with javascript unfortunately. It is a security restriction enforced by the browser and thrown on a lower level. I have tried so many different methods, including the use of extensions but nothing worked except a timeout handler to be honest.

like image 60
Yigit Erol Avatar answered Nov 14 '22 23:11

Yigit Erol