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 不兼容,无法发送自定义的请求头 #20

Closed
ViCrack opened this issue Dec 31, 2021 · 8 comments
Closed

GM_xmlhttpRequest 不兼容,无法发送自定义的请求头 #20

ViCrack opened this issue Dec 31, 2021 · 8 comments

Comments

@ViCrack
Copy link

ViCrack commented Dec 31, 2021

在scriptcat中使用如下代码指定headers

GM_xmlhttpRequest({
        method: 'GET',
        url: 'http://xxxx',
       headers:    {
            referer:  "http://microsoft.com",
            origin:   "http://microsoft.com"
       }

发现它会把Origin和Referer请求头变成

X-Cat-20379D59-3753-4Bc2-9Aac-7Fd1601C4454-Origin: http://microsoft.com
X-Cat-20379D59-3753-4Bc2-9Aac-7Fd1601C4454-Referer: http://microsoft.com

而且还莫名多了一个X-Cat-xxx-Scriptcat的出来
X-Cat-20379D59-3753-4Bc2-9Aac-7Fd1601C4454-Scriptcat: true

导致最终请求失败。

而我换成用tampermonkey去验证了一下,发送的请求头则都是标准和正确的值,也没有多余的X-Cat-xxx-Scriptcat出现。

这是为什么,需要如何避免?

Firefox最新版,后台脚本

@CodFrm
Copy link
Member

CodFrm commented Dec 31, 2021

image

v0.7.7 么?我chrome测试正常,Firefox我在元旦的时候看一看,可能是浏览器兼容问题

@CodFrm
Copy link
Member

CodFrm commented Dec 31, 2021

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

// 在此处键入代码……
GM_xmlhttpRequest({
        method: 'GET',
        url: 'https://bbs.tampermonkey.net.cn/',
       headers:    {
            referer:  "http://microsoft.com",
            origin:   "http://microsoft.com"
       }
});

@ViCrack
Copy link
Author

ViCrack commented Dec 31, 2021

是0.7.7,好像只有后台脚本才有这情况,还有在脚本编辑器 点操作->调试的时候 (换到了edge来测试)

图片

case 'x-cat-' + this.rand + '-cookie': {

@CodFrm
Copy link
Member

CodFrm commented Dec 31, 2021

发现了,是调试的时候会这样,不过运行是可以的,我元旦的时候修复一下(Firefox 运行没测试)

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

// 在此处键入代码……
GM_xmlhttpRequest({
        method: 'GET',
        url: 'https://bbs.tampermonkey.net.cn/',
       headers:    {
            referer:  "http://microsoft.com",
            origin:   "http://microsoft.com"
       }
});

@CodFrm
Copy link
Member

CodFrm commented Jan 3, 2022

修复 328ca18

@CodFrm CodFrm closed this as completed Jan 3, 2022
@ViCrack
Copy link
Author

ViCrack commented Jan 11, 2022

@CodFrm

在0.8.0版本 Firefox
图片

后台脚本还是会发送错误和多余的请求头
图片

@CodFrm
Copy link
Member

CodFrm commented Jan 11, 2022

@ViCrack chrome系没问题,Firefox我再看看 尴尬了

@CodFrm
Copy link
Member

CodFrm commented Jan 11, 2022

修复,这两天就更新,Firefox审核很快

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants