Mixed Active Content Blocked Download Trap CORS Error

In firefox, when javascript tries to execute a CORS request to the http server from a page hosted on https , this will cause an error:

 Blocked loading mixed active content 

I would like to catch these errors, but I cannot figure out how to do this. For example, I tried something like this with jQuery:

 try { $.get("http://public.opencpu.org/ocpu/library/").fail(function(xhr, err){ console.log("Server error:" + xhr.responseText); }); } catch(e){ console.log(e.message);; } 

But xhr.responseText and e.message are empty lines (perhaps because $.ajax happens asynchronously). How can I catch the actual error message that says: Blocked loading of mixed active content ...

+7
javascript jquery firefox ajax cors
source share
2 answers

You cannot catch this exact message. It will be registered only on the console, but not accessible to the user.

When using simple XHR, calling .open() throws an exception with .result === 0x805e0006 . In addition, ex.toString() will contain nsresult: "0x805e0006 (<unknown>)" .

jQuery puts ex.toString() in .statusText jqXHR , so you can perform the following check for queries blocked due to mixed content:

 xhr.statusText.indexOf('nsresult: "0x805e0006 (<unknown>)"') > -1 

For the curious: 0x805e0006 should be NS_ERROR_CONTENT_BLOCKED (C ++ macro value).

+3
source share

You should be able to prevent the error in the first place using the relative protocol url:

 $.get("//public.opencpu.org/ocpu/library/") 

uses either http or https, depending on the context of your page. public.opencpu.org supports both, so there is no problem.

0
source share

All Articles