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有些headers无法修改 #215

Open
ImagineBook opened this issue Jul 20, 2023 · 3 comments
Open

GM_xmlhttpRequest有些headers无法修改 #215

ImagineBook opened this issue Jul 20, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@ImagineBook
Copy link

ImagineBook commented Jul 20, 2023

看文档里说GM_xmlhttpRequest 支持修改特殊的headers项,还特意举例了Origin和Referer,但我手动设置包括这两个在内的几个headers发现无法修改,在实际发送的headers里我修改的项目会变成以x-cat-7fb067ca-b2d6-4a17-8b95-d7d0827256ea-开头的项加在最后。
例如:设置了几个特殊headers

GM_xmlhttpRequest({
	method: 'POST',
	url: 'https://data.sonkwo.com/analysis/event/collect',
	headers: {
		"Content-Type": "application/json",
		"Origin": "https://www.sonkwo.cn",
		"Referer": "https://www.sonkwo.cn/",
		"Sec-Fetch-Site": "cross-site"
	},
	data: JSON.stringify({
		"eventType":"indexSignin",
		"eventTime":Math.round(new Date()),
		"client":"index_native_pc",
		"detailParameter":{
			"uuid":uuid,
			"rcode":null,
			"userid":id
		}
	})
});

但实际上发出去的请求headers相关部分是这样的

Content-Type: application/json
Host: data.sonkwo.com
Origin: chrome-extension://liilgpjgabokdklappibcjfablkpcekh
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: none
x-cat-7fb067ca-b2d6-4a17-8b95-d7d0827256ea-gm-xhr: true
x-cat-7fb067ca-b2d6-4a17-8b95-d7d0827256ea-origin: https://www.sonkwo.cn
x-cat-7fb067ca-b2d6-4a17-8b95-d7d0827256ea-referer: https://www.sonkwo.cn/
x-cat-7fb067ca-b2d6-4a17-8b95-d7d0827256ea-sec-fetch-site: cross-site

只有Content-Type修改成功了

@CodFrm CodFrm added the bug Something isn't working label Jul 20, 2023
@CodFrm
Copy link
Member

CodFrm commented Jul 20, 2023

你是在什么环境运行的呢?我这里测试OK

是后台脚本的调试模式吗?

image

@ImagineBook
Copy link
Author

是的,写的一个定时脚本,在脚本猫的编辑器调试的时候会这样

@CodFrm
Copy link
Member

CodFrm commented Aug 25, 2023

调试时暂不支持修改unsafe header,过两个版本处理一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants