Chrome扩展Manifest V3中模拟站点请求返回HTTP 500,原请求与Postman请求正常的问题排查求助
Chrome扩展Manifest V3中模拟站点请求返回HTTP 500,原请求与Postman请求正常的问题排查求助
我正在用JS开发基于Manifest V3的Chrome扩展(最新版Chrome),大部分接口和功能都跑的很正常,但唯独一个请求总是返回500状态码。这个请求是我从站点的原生请求里扒来的——我需要替换原生请求的参数来提交特定数据,但原生请求能正常返回200,我的模拟请求却死活不行。
两个请求都是通过Chrome DevTools右键请求→复制→复制为fetch得到的,而且都没有额外的上下文预处理,我实在找不到两者的差异在哪。
更奇怪的是,我用Postman等调试工具,带着完全相同的Header和Body发送请求,结果都是正常的200,所以我开始怀疑是不是Chrome的bug,或者某些Header在扩展环境里没被正确识别?
下面是我的请求(返回500):
fetch('https://www.server.com/spt/betslips/betslip/toggleitem?betslipId=value here', { 'headers': { 'accept': 'application/json, text/plain, */*', 'accept-language': 'fr,ru;q=0.9,ru-RU;q=0.8,en;q=0.7', 'betslipid': 'value here', 'cache-control': 'no-cache', 'content-type': 'application/json', 'pragma': 'no-cache', 'priority': 'u=1, i', 'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"', 'sec-ch-ua-arch': '"x86"', 'sec-ch-ua-bitness': '"64"', 'sec-ch-ua-full-version': '"131.0.6778.86"', 'sec-ch-ua-full-version-list': '"Google Chrome";v="131.0.6778.86", "Chromium";v="131.0.6778.86", "Not_A Brand";v="24.0.0.0"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-model': '""', 'sec-ch-ua-platform': '"Windows"', 'sec-ch-ua-platform-version': '"10.0.0"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-origin', 'x-gw-application-name': 'NoviIE', 'x-gw-betslipid': '1314396104817811456', 'x-gw-channel': 'WebPC', 'x-gw-client-timezone': 'Europe/Moscow', 'x-gw-cms-key': '_IE', 'x-gw-country-sysname': 'IE', 'x-gw-currency-sysname': 'EUR', 'x-gw-domain-key': '_IE', 'x-gw-language-sysname': 'en-IE', 'x-gw-odds-representation': 'Fractional', 'x-gw-state-sysname': '', 'Referer': 'https://www.server.com/live-betting/value here', 'Referrer-Policy': 'strict-origin-when-cross-origin', }, 'body': '{"betContextId":38188719,"betInstanceId":38188719,"marketInstanceId":1207665657,"price":2.5}', 'method': 'POST', });
站点的原生请求(返回200):
fetch('https://www.server.com/spt/betslips/betslip/toggleitem?betslipId=value here', { 'headers': { 'accept': 'application/json, text/plain, */*', 'accept-language': 'fr,ru;q=0.9,ru-RU;q=0.8,en;q=0.7', 'cache-control': 'no-cache', 'content-type': 'application/json', 'pragma': 'no-cache', 'priority': 'u=1, i', 'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"', 'sec-ch-ua-arch': '"x86"', 'sec-ch-ua-bitness': '"64"', 'sec-ch-ua-full-version': '"131.0.6778.86"', 'sec-ch-ua-full-version-list': '"Google Chrome";v="131.0.6778.86", "Chromium";v="131.0.6778.86", "Not_A Brand";v="24.0.0.0"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-model': '""', 'sec-ch-ua-platform': '"Windows"', 'sec-ch-ua-platform-version': '"10.0.0"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-origin', 'x-gw-application-name': 'NoviIE', 'x-gw-betslipid': 'value here', 'x-gw-channel': 'WebPC', 'x-gw-client-timezone': 'Europe/Moscow', 'x-gw-cms-key': '_IE', 'x-gw-country-sysname': 'IE', 'x-gw-currency-sysname': 'EUR', 'x-gw-domain-key': '_IE', 'x-gw-language-sysname': 'en-IE', 'x-gw-odds-representation': 'Fractional', 'x-gw-state-sysname': '', 'Referer': 'https://www.server.com/live-betting', 'Referrer-Policy': 'strict-origin-when-cross-origin', }, 'body': '{"betContextId":value here,"betInstanceId":value here,"marketInstanceId":value here,"price":1.2}', 'method': 'POST', });
备注:内容来源于stack exchange,提问作者Kors Man
相关产品推荐
相关产品推荐

