6

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?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Jorn
  • 20,612
  • 18
  • 79
  • 126

1 Answers1

2

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.

Yigit Erol
  • 170
  • 1
  • 6