问题描述
我有一个针对Chrome开发的扩展程序,并且还上传到了Firefox的附加商店中。我最近添加了一项功能,该扩展程序向https://tf2metrics.azurewebsites.net发出跨域请求,以下载一些json数据。
从分机拨打电话:
https://tf2metrics.azurewebsites.net/api/users/76561198142328193,76561198090551717
相同的源代码可以在Chrome上正常运行,但不适用于Firefox用户。
在Firefox浏览器控制台中,此调用导致:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://tf2metrics.azurewebsites.net/api/users/76561198142328193,76561198090551717. (Reason: CORS header ‘Origin’ cannot be added).
我的内容脚本使用简单的jQuery在https://tf2center.com/lobbies/ *上运行:
$.get(url,function (data) {
// do stuff
});
我尝试添加Origin
标头,因为错误表明它“无法添加”:
$.ajaxSetup({
headers: {
'Origin': "https://tf2center.com"
}
});
此扩展程序仍无法在Firefox上运行,并且在Chrome上与此调用同时失败。错误是:
Refused to set unsafe header "Origin"
所以我删除了。我浏览了一下,发现添加了
"permissions": [
"*://*.tf2center.com/*",...
],
我的manifest.json
可能会解决此问题,但这也不起作用。
作为参考,这里是我最初为支持Chrome功能而最初添加的用于处理COR的ASP.NET Core 3.1 Startup.cs
代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
...
}
public void Configure(IApplicationBuilder app,IWebHostEnvironment env)
{
...
app.UseCors(_ => _.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
...
}
为什么我的Chrome扩展程序允许通话,而Firefox不允许?我还可以尝试解决哪些特定于Firefox的错误?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)