Tampermonkey / tampermonkey

Tampermonkey is the most popular userscript manager, with over 10 million users. It's available for Chrome, Microsoft Edge, Safari, Opera Next, and Firefox.
GNU General Public License v3.0
4.28k stars 423 forks source link

GM_XHR in fetch mode throws error when responseType set to text #1001

Closed 7nik closed 3 years ago

7nik commented 4 years ago

GM_XHR in fetch mode fails when responseType explicitly set to text.

Expected Behavior

Prints to the console Response object.

Actual Behavior

Prints error {readyState: 4, responseHeaders: "", status: 408, statusText: "Cannot read property 'then' of undefined"}

Specifications

Chromium: Version 83.0.4103.97 (Official Build) Arch Linux (64-bit) TM: beta, 4.11.6116 OS: KDE Manjaro (64-bit)

Script

(Please give an example of the script if applicable.)

// ==UserScript==
// @name         Test GM_XHR-fetch responseType
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://github.com/*
// @grant        GM.xmlHttpRequest
// @connect      httpbin.org
// ==/UserScript==

(async () => {
    console.log("ret:", await GM.xmlHttpRequest({
        fetch: true,
        url: "https://httpbin.org/robots.txt",
        responseType: "text",
        onload: (resp) => console.log("resp:", resp),
        onerror: (err) => console.error("error:", err),
    }));
})();
derjanb commented 4 years ago

Nice find! 🙈

Thanks for all your bug reports.

7nik commented 4 years ago

Also,

// ==UserScript==
// @name         Test GM_XHR responseType
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://github.com/*
// @grant        GM_xmlhttpRequest
// @grant        GM.xmlHttpRequest
// @connect      httpbin.org
// ==/UserScript==

(() => {
    GM.xmlHttpRequest ({
        url: "https://httpbin.org/json",
        responseType: 'json',
    })
    .then(() => GM.xmlHttpRequest ({
        url: "https://httpbin.org/html",
        responseType: 'document',
    }))
    .then(() => console.log('DONE'))
})();

these two types cause

xhr: requested responseType json differs from received 
xhr: requested responseType document differs from received 

on the background page where received type is an empty string.

derjanb commented 4 years ago

GM_XHR in fetch mode fails when responseType explicitly set to text.

Should be fixed at 4.11.6117

xhr: requested responseType json differs from received

It's just a console message. So I'll address that later.