Skip to content
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

[MV3] All GM_xmlhttpRequest requests are serialized #2215

Open
derjanb opened this issue Oct 25, 2024 · 5 comments
Open

[MV3] All GM_xmlhttpRequest requests are serialized #2215

derjanb opened this issue Oct 25, 2024 · 5 comments

Comments

@derjanb
Copy link
Member

derjanb commented Oct 25, 2024

Expected Behavior

GM_xmlhttpRequest requests are made in parallel

Actual Behavior

requests run serialized (until response headers are received)

Specifications

  • Chromium: any
  • TM: 5.3+

Explanation

In order to fix #2179 Tampermonkey needs to register a DNR rule for every request. Since those header modifications are not preserved over HTTP redirects like headers set via fetch, Tampermonkey needs to match all requests, but therefore can't run more than one at once. In my opinion this is a Chrome bug.

Workaround

Add the following to your script (Tampermonkey 5.3.2+, Tampermonkey BETA 5.3.6216+).

// @require      https://raw.githubusercontent.com/Tampermonkey/utils/refs/heads/main/requires/gh_2215_make_GM_xhr_more_parallel_again.js

Drawbacks:

  • no progress events
  • 401 responses (basic auth, ...) are not handled

Script

// ==UserScript==
// @name         Non-parallel GM_xhr
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://example.com/*
// @grant        GM_xmlhttpRequest
// @grant        GM.xmlHttpRequest
// @connect      httpbin.org
// ==/UserScript==

console.log('Dummy request started');

GM.xmlHttpRequest({
    method:   "GET",
    url:      'https://httpbin.org/delay/5000',
})
.then(() => {
    console.log('Dummy request finished');
})

GM_xmlhttpRequest({
    method: 'GET',
    url: 'https://httpbin.org/redirect-to?url=https://httpbin.org/headers',
    responseType: 'arraybuffer',
    headers: {
        'user-agent': 'TM',
        'foo': 'bar'
    },
    onreadystatechange: function(event) {
        console.log(`Ready state: ${event.readyState}, status ${event.status}`);
    },
    onprogress: function(event) {
        if (event.lengthComputable) {
            console.log(`Downloading: ${event.loaded}/${event.total}`);
        }
    },
    onload: function(res) {
        console.log('Download finish');
        console.log(res);
        console.log(res.responseText);
    },
    onerror: function(res) {
        console.log('Can\'t load URL');
    }
});
@derjanb derjanb changed the title All GM_xmlhttpRequest requests are serialized [MV3] All GM_xmlhttpRequest requests are serialized Oct 25, 2024
@Purfview
Copy link

I got lots of reports about this from Chrome users, and one was Chromium user.

@derjanb
Copy link
Member Author

derjanb commented Oct 29, 2024

I got lots of reports about this from Chrome users, and one was Chromium user.

@Purfview Have you tried the workaround with the latest BETA version 5.3.6216?

If you wan't to test it at the stable version, then you have to download this crx, because version 5.3.2 is currently in review.

After downloading the crx file linked above you need to drag and drop it to the extensions page chrome://extensions (after you've enabled 'Developer Mode').

@Purfview
Copy link

In BETA version 5.3.6216: responses comes very slow - still serialized, and same like the other issue with loading, refreshed it like 50 times till it worked.

@derjanb
Copy link
Member Author

derjanb commented Oct 29, 2024

In BETA version 5.3.6216: responses comes very slow

The workaround from above should fix this one:

// @require      https://raw.githubusercontent.com/Tampermonkey/utils/refs/heads/main/requires/gh_2215_make_GM_xhr_more_parallel_again.js

@Purfview
Copy link

Yeah, I thought that beta works without it, skipped the first post too fast...

Btw, your link is not secure as it doesn't ensure integrity and I think it wouldn't be allowed on GF as such.

Here is the secure version of the link and it should be compliant with GF:

// @require      https://github.com/Tampermonkey/utils/raw/d8a4543a5f828dfa8eefb0a3360859b6fe9c3c34/requires/gh_2215_make_GM_xhr_more_parallel_again.js

Ocrosoft added a commit to Ocrosoft/PixivPreviewer that referenced this issue Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants