-
Notifications
You must be signed in to change notification settings - Fork 2
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
GM.xmlHttpRequest fails in Chrome with TypeError: Failed to construct 'Headers' Invalid value #162
Comments
HTTP RFC says line break must be CRLF.
|
I'm using chrome on windows, which OS you are using? Is this issue platform specific? Or can you share server code to reproduce this? python/nodejs/go would be best. |
Absolutely! That's why I was using the respective emoticons above.
Unfortunately, no. It happens in userscript context in the browser. Let me give you a MVE to play with it yourself (use whatever URL you like for the // ==UserScript==
// @name trim21
// @match https://www.example.com/
// @require https://cdn.jsdelivr.net/npm/@trim21/[email protected]/dist/gm_fetch.js
// @grant GM.xmlHttpRequest
// @connect *
// @run-at document-end
// ==/UserScript==
await( async () => {
'use strict';
const url = "https://www.example.com";
console.info(`will fetch ${url}`)
// will fail with TypeError: Failed to construct 'Headers': Invalid value
const res = await GM_fetch(url, {
headers: { "content-type": "text/html" },
});
const text = await res.rawBody.text();
console.info(text);
})(); Will break like so when you load https://www.example.com/: You can see the value already in the debugger preview:
Nb.: It's the response headers, not the request headers, and it's completely independent from the URL you are fetching... |
Oh, apologies, forgot the first question: I'm on MacOS 14.4 (23E214)... |
It doesn't reproduce on windows. I think this is a upstream issue from Tampermonkey, can you also send a issue to them? I can add a workaround on macos, but I think this should be fixed my Tampermonkey, since RFC says it's CRLF. |
you can send a PR to add a workaround for MacOS only. |
I have the same error on Windows with the latest version of Tampermonkey.
|
this should have been fixed by upstream Tampermonkey/tampermonkey#2160 |
Description
GM.xmlHttpRequest
fails in Chrome withTypeError: Failed to construct 'Headers' Invalid value
. It turns out that this piece of code splits a header string by\r\n
while the header stringh
comes in with only\n
as line separator:Environment
How to reproduce
Expectations
Should deal with the headers as they come in, i.e. regardless whether it's
\r\n
(Brave 👍) or just\n
(Chrome 🤦🏼♀️).The following simple patch will do:
Should be here:
gm-fetch/src/utils.ts
Line 7 in c377b28
but I'm not the TypeScript expert to PR for that. In fact, I don't even have TS set up on my machine.
Actual result
GM.xmlHttpRequest
fails withTypeError: Failed to construct 'Headers' Invalid value
.The text was updated successfully, but these errors were encountered: