How to get 'Location' for XMLHttpRequest with 320 status code.

1,024 views
Skip to first unread message

Valery

unread,
Nov 5, 2010, 5:25:37 AM11/5/10
to Chromium-extensions
Hello,

My server's page (http://abc.com/a) always returns 302 status code
with new location in the response header. New location points to my
server but other subdomain like http://mac.abc.com/b.

Inside my extension, I need somehow to get only this location. I tried
to use XMLHttpRequest with both 'GET' and 'HEAD' request, but no
success.

In the "Developer Tools"->Resources I see two resources: 'a' and 'b'.

The header of the first one 'a' contain Status Code: 302 Found.
The second one is 200 OK.

I require to be notified after the first response. Instead I am
notified only after the second response.

My code is the following:

var xhr = new XMLHttpRequest();
xhr.open("GET", 'https://www.mysite.com/'); //or HEAD
xhr.onreadystatechange = function() {
console.debug(xhr.status);
console.debug(xhr.getResponseHeader('Location'));
};
xhr.send();

The output: 200 null 200 null 200 null 200 null 200 null.

Is it possible to do?


Thanks,
Valery.

Arne Roomann-Kurrik

unread,
Nov 5, 2010, 6:27:56 PM11/5/10
to Valery, Chromium-extensions
Normally the XHR request should stop if you're changing origin, but it looks like since extensions can do cross-domain requests, the browser is treating this like a same-origin request.  Which I take to mean that Chrome is following the specification here and redirecting transparently - there's no mechanism built into XMLHttpRequest that will give you information about any redirects, sadly.

This is the kind of thing that the upcoming webrequest API will help address, but that's not implemented yet.  Perhaps there's another workaround you can do to figure out where the request was directed?

~Arne



--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Reply all
Reply to author
Forward
0 new messages