erosman / support

Support Location for all my extensions
Mozilla Public License 2.0
168 stars 12 forks source link

[FireMonkey] Event handlers of `GM_xmlhttpRequest` are not called #506

Open Iey4iej3 opened 1 year ago

Iey4iej3 commented 1 year ago

I use the sample code at https://github.com/Tampermonkey/tampermonkey/issues/958#issuecomment-881646563 For sake of completeness, here is the code (slightly modified):

// ==UserScript==
// @name         log onprogress
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        *://example.com/*
// @grant        GM_xmlhttpRequest
// @connect      httpbin.org
// ==/UserScript==

GM_xmlhttpRequest({
    method:   "POST",
    data: 'x'.repeat(1*1024*1024),
    url:      'https://httpbin.org/post?t='+ Date.now(),
    onloadstart: function(e) {
        console.log('onloadstart', e);
    },
    onloadend: function(r) {
        console.log('onloadend', r);
    },
    onprogress: function(e) {
        console.log('onprogress', (e.loaded / e.total), e);
    },
    onload: function(r) {
        console.log('onload', r);
    },
    onerror: function(r) {
        console.error('onerror', r);
    }
});

It seems that only is onload handler called. In particular, onprogress is not called (this sample code is about POST, but the same for GET).

erosman commented 1 year ago

As per FireMonkey Help: xmlHttpRequest only onload, onerror, onabort, ontimeout are supported.

There are restrictions in userScripts context and maintaining a continuous connection between background script, userScripts API & userscript requires additional resources. As onprogress wasn't commonly used, its support was not included.

Iey4iej3 commented 1 year ago

These events are used when a userscript deals with downloading.

erosman commented 1 year ago

I searched greasyfork.org now and 208 out of 64,000 scripts use onprogress and not all with GM_xmlhttpRequest. That is 0.3% if the scripts.

https://greasyfork.org/en/scripts/code-search?c=onprogress