Tampermonkey / tampermonkey

Tampermonkey is the most popular userscript manager, with over 10 million users. It's available for Chrome, Microsoft Edge, Safari, Opera Next, and Firefox.
GNU General Public License v3.0
4.28k stars 423 forks source link

How could GM_xmlhttpRequest fetch the 'Location' in the Response Headers? #335

Closed pendave closed 7 years ago

pendave commented 7 years ago

How could GM_xmlhttpRequest fetch the 'Location' in the Response Headers?

It displays status:200 when I use GM_xmlhttpRequest, but actually it needs to be 302.

xqpv_1 o9a o tosue_gg i

derjanb commented 7 years ago

[Redirects are handled transparently](https://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#infrastructure-for-the-send()-method), but you can use the finalUrl property of GM_xmlhttpRequest to detect redirects.

var url = "http://google.com";
GM_xmlhttpRequest ( {
    method: "GET",
    url: url,
    onload: function (response) {
        console.debug ('Redirected: ' + (url != response.finalUrl));
    }
} );
pendave commented 7 years ago

Yes it reports:

Redirected: true

How can I get the real redirected URL?

derjanb commented 7 years ago

response.finalUrl

pendave commented 7 years ago

response.finalUrl is not the correct Location