0

I am developing an Hybrid mobile application (Android/Ios) with Cordova / Angular 2 / Ionic 2. To debug quickly, I run my application in Chrome.

I use a lot of XMLHttpRequest:

var xhr = new XMLHttpRequest();
xhr.open('HEAD', imgSrc, true);
            xhr.onreadystatechange = function () {

                if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        let responseContentLength = xhr.getResponseHeader('Content-Length');

This works great on mobile or emulator. But when I debug in Chrome, I get the following error:

Refused to get unsafe header "Content-Length"

Is there a way to allow access (only get) to 'Content-Length' header in Chrome?

Updated (thanks to Destrif): There is a good explanation of what is going on here Restrictions of XMLHttpRequest's getResponseHeader()? I m doing a cross-origin request (i have a plugin in chrome that's allow CORS), so the browser implement XMLHttpRequest Level 2 specification. This specification forbids access to 'Content-Length' header (and others headers).

When I use the emulator RIPPLE, I do not encounter the error. I know RIPPLE uses a proxy. A proxy for development would solve the problem? How does Ripple?

The goal is to run the app in Chrome without encountering the error.

Community
  • 1
  • 1
JeromeXoo
  • 1,378
  • 14
  • 16
  • I m getting Content-Length (not setting). – JeromeXoo Jun 03 '16 at 13:40
  • Maybe this will help so: http://stackoverflow.com/questions/7462968/restrictions-of-xmlhttprequests-getresponseheader – Destrif Jun 03 '16 at 13:54
  • And to to make it work, you will need CORS(Access-Control-Expose-Headers) example here: http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource Up vote if you liked it – Destrif Jun 03 '16 at 13:59
  • With Ripple, i don t have the error message. If i use proxy in Chrome, can i avoid this message? – JeromeXoo Jun 03 '16 at 17:56
  • Destrif thanks a lot for your answer. This explains very well http://stackoverflow.com/questions/7462968/restrictions-of-xmlhttprequests-getresponseheader. I can't upvote (i don't have right) – JeromeXoo Jun 03 '16 at 18:56
  • Günter, could you please reopen this thread? it s not a duplicate. And it s not a "set". – JeromeXoo Jun 03 '16 at 20:15
  • no chance to reopen? – JeromeXoo Jun 05 '16 at 14:18
  • Didn't you answer your question?, why do you want to reopen? – Destrif Jun 05 '16 at 16:39

0 Answers0