scriptcat icon indicating copy to clipboard operation
scriptcat copied to clipboard

responseType: "document" 不支持

Open Kn0wns opened this issue 2 years ago • 3 comments

GM_xmlhttpRequest({
    method: "GET",
    url: "https://bbs.kanxue.com/",
    responseType: "document",
    onload: xhr => console.log(xhr),
    onerror: () => console.log('网络错误')
});

image

Kn0wns avatar Jan 17 '23 12:01 Kn0wns

看起来是后台脚本的运行环境,后台脚本暂时不支持document,可以加入后续更新计划

CodFrm avatar Jan 18 '23 02:01 CodFrm

看起来是后台脚本的运行环境,后台脚本暂时不支持document,可以加入后续更新计划 普通脚本运行也是失败的,请求是正常发出并且响应也没问题 image

Kn0wns avatar Jan 18 '23 11:01 Kn0wns

这样运行还是在后台脚本的环境中,普通脚本是指的有@match的脚本,例如:

// ==UserScript==
// @name         New Userscript
// @namespace    https://bbs.tampermonkey.net.cn/
// @version      0.1.0
// @description  try to take over the world!
// @author       You
// @match        https://bbs.tampermonkey.net.cn/
// @grant        GM_xmlhttpRequest
// ==/UserScript==

GM_xmlhttpRequest({
    url: "https://bbs.tampermonkey.net.cn/",
    responseType: "document",
    onload(data) {
        console.log(data.response);
    }
})

然后打开链接:https://bbs.tampermonkey.net.cn/

image

CodFrm avatar Jan 18 '23 13:01 CodFrm

后台脚本,暂时不打算也不太好支持此功能

需要的话,可以考虑通过三方库去解析responseText成document

CodFrm avatar Jul 09 '24 07:07 CodFrm