New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add redirect
option support to GM_xhr
#1729
Comments
4.19.6180 (crx|xpi) now has experimental support for the // ==UserScript==
// @name no-www
// @namespace org.openuserjs.sjehuda.no-www
// @description www. is deprecated. Redirect to URL without www.
// @run-at document-start
// @include *
// @grant GM.xmlHttpRequest
// @version 1
// ==/UserScript==
if (!location.host.startsWith('www.')) return; // exit (else, continue)
var newURL = location.href.replace('://www.','://');
GM.xmlHttpRequest({
method: 'GET',
url: newURL,
redirect: 'manual',
onload: function(response) {
if (response.readyState == 4 && [ 301, 302 ].includes(response.status)) {
console.log(r.responseHeaders);
// check r.responseHeaders for the Location header
} else {
console.log('No redirect');
// do something else
}
},
onerror: function(response) {
console.log('Error requesting for no-www')
}
}) Chrome/Edge users, please download the crx file linked above and drag and drop it to the extensions page For a quick fix please export your settings and scripts as zip or (JSON) file at the "Utilities" tab and import it back at the fixed BETA version. |
The no-www script works well with Greasemonkey and Tampermpnkey.
This script doesn't work with Greasemonkey for Falkon because they need
to fix Falkon, so I figured a @nocors metablock should be created
mainly to have:
1) Uniformity
2) Lesser use of specific libraries (i.e. GM.xmlHttpRequest)
I didn't ask for redirect support.
What do you mean by redirect?
Please explain.
|
There is a bug regarding the I just upgraded to the last version, just to benefit from the redirect feature as I really need it. It's an essential feature. I need all the I would appreciate a fast fix for this annoying issue. |
Gentlemen, redirection works fine, even without the "redirect feature", which I didn't even try, yet. Just try these userscript which don't use any explicit redirect feature. https://openuserjs.org/scripts/sjehuda/Proxy_Redirect |
@sjehuda I appreciate your contribution to this awesome project and the always evolving code, Thanks for everything. But please pay a bigger attention to what I've wrote and try it yourself. If you want I can open a new issue with a live example to show you that the issue I'm talking about does exist. And it is crucial for basic operations to interact with HTTP actions. The problem is not with the Redirect feature, but the contrary, it's when I don't want to follow redirects, but to get a proper response from the server without following the redirect. In general, usually, there is one header only per key (e.g. one Again, if you want, I can supply a live example. |
I think I understand.
I've overcome this issue by seeking 200 status and comparing resulted
URL with original URL.
Again, if you want, I can supply a live example.
Yes, please.
|
Ok, I just set up a new HTTP server using beeceptor.com with 2 endpoints: Endpoint 1
Response headers:
Endpoint 2
Response headers:
So now, when I access https://setcookie.free.beeceptor.com it should redirect me to https://setcookie.free.beeceptor.com/redirect but I don't want to auto redirect, because I want to get these So this is my TamperMonkey script (with
And this is the output of
instead of the expected:
or, if headers are combined (as I found in "normal" responses), which I think shouldn't be combined, but it's another subject:
|
By the way, this is a common behavior of servers when logging in to the site. The server respond with some |
@derjanb I forgot to thank you, you did a great job! You fixed the bug and you even took care of the header split, so that they don't combine into one line, but spread on multiple lines, one per each header, which is much easier to work with (and makes more sense). So thanks a lot! |
UPDATE: This suggestion has been rejected by violentmonkey/violentmonkey#1781
Discussion at https://openuserjs.org/discuss/nocors_metadata_block
I think it would be useful to add
@nocors
metadata block (similarly to@noframes
) which would be productive in the sense of coding and consequently make userscript managers to behave in a uniform fashion.no-www is using
GM.xmlHttpRequest
which doesn't seem to be supported with all userscript managers.Example script
If
@nocors
was introduced, this script could have been shorter.The text was updated successfully, but these errors were encountered: