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

GM_xmlhttpRequest NetworkError #1172

Closed
ArtiiP opened this issue Mar 8, 2021 · 3 comments
Closed

GM_xmlhttpRequest NetworkError #1172

ArtiiP opened this issue Mar 8, 2021 · 3 comments
Milestone

Comments

@ArtiiP
Copy link

ArtiiP commented Mar 8, 2021

my userscript stopped downloading img (and pack to zip) in latest TM version (6130)
it only displays a weird error on console and doesn't even "fire" onerror function

Expected Behavior

let it works as previous version i.e. TM 4.11.6120

Actual Behavior

console error
obraz

content.js:102:421 via beautifier in ff-dev:
obraz

i tried to download files from my "server" and i am getting normal requests in logs

(very painfull) downgrade to 6120 fix this situation

Specifications

  • Firefox 87.0b6 (64 bit) dev
  • TM: 4.12.6130
  • OS: Win7

Script

only small snippets function
zip: is JSZip blob open for writing

function urlToBlob(url, fname, zip, tablic){
        GM_xmlhttpRequest({
            method: "GET",
            url: url,
            responseType: 'arraybuffer',
            onload: function(event) {
                console.log(event);
                var byteArray = new Uint8Array(event.response);
                console.log(zip.file(fname, byteArray, {binary:true, compression: "STORE"}));
                tablic[url] = fname;
            },
            onerror: function(res) {
                  var msg = "An error occurred."
                  + "\nresponseText: " + res.responseText
                  + "\nreadyState: " + res.readyState
                  + "\nresponseHeaders: " + res.responseHeaders
                  + "\nstatus: " + res.status
                  + "\nstatusText: " + res.statusText
                  + "\nfinalUrl: " + res.finalUrl;
                  console.log(msg);
              }
        });
}

I added onerror later (to debug this problem) but it's never fired

@derjanb
Copy link
Member

derjanb commented Mar 8, 2021

This seems to work here pretty good using the script below. Can you please test with a new temporary profile?

Tested at

  • Ubuntu 20.04 87.0b7 (64-bit)
  • W10 85.0.2 (64-Bit)
  • W10 86.0 (64-Bit)
// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @require      https://cdnjs.cloudflare.com/ajax/libs/jszip/2.6.0/jszip.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js
// @grant        GM_xmlhttpRequest
// @connect      *
// ==/UserScript==

function urlToBlob(url, fname, zip, tablic){
    return new Promise(resolve => {
        GM_xmlhttpRequest({
            method: "GET",
            url: url,
            responseType: 'arraybuffer',
            onload: function(event) {
                console.log(event);
                var byteArray = new Uint8Array(event.response);
                console.log(zip.file(fname, byteArray, {binary:true, compression: "STORE"}));
                tablic[url] = fname;
                resolve();
            },
            onerror: function(res) {
                var msg = `An error occurred.
                    responseText: ${res.responseText}
                    readyState: ${res.readyState}
                    responseHeaders: ${res.responseHeaders}
                    status: ${res.status}
                    statusText: ${res.statusText}
                    finalUrl: ${res.finalUrl}
                `;
                console.log(msg);
                resolve();
            }
        });
    });
}

(async () => {
    const zip = JSZip();
    const tablic = {};

    for (let e of [
        [ 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==', 'empty.gif' ],
        [ 'https://developer.mozilla.org/favicon144.png', 'mozilla.png' ],
        [ 'https://www.tampermonkey.net/favicon.ico', 'tampermonkey.ico' ],
        [ 'https://user-images.githubusercontent.com/8899307/110259506-e6953d80-7f9f-11eb-8257-2e60a04457e8.png', 'githubusercontent.png' ],
        [ 'https://tampermonkey.freetls.fastly.net/images/security.png', 'security.png' ]
    ]) {
        const [ url, name ] = e;
        await urlToBlob(url, name, zip, tablic);
    }

    saveAs(zip.generate({ type: 'blob' }), 'out.zip');
})();

@ArtiiP
Copy link
Author

ArtiiP commented Mar 8, 2021

firefox containers is the problem here ;/
normaly i use
https://addons.mozilla.org/pl/firefox/addon/multi-account-containers/
and
https://addons.mozilla.org/pl/firefox/addon/temporary-containers/
this last addon in auto mode (that means all tab have new temporary cointarner)

if i force noncontainer mode tab and run my or your script - it's works as expected, but changing tab to new or old container make this error

/then why older TM works but new one no/

@derjanb
Copy link
Member

derjanb commented Mar 8, 2021

Tampermonkey now uses another way to forward the XHR's data to the tab. Unfortunately this way seems to be incompatible with containers.

Will be fixed soon...

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