Firefox错误:尝试仅从扩展获取资源时出现NetworkError



我目前正在为firefox/chrome开发一个扩展,该扩展需要从另一个网站获取一些数据。

Chrome的扩展似乎运行良好,然而,我得到了"NetworkError when attempting to fetch resource";在尝试firefox的扩展时。

如果我从控制台执行代码,它运行得很好,问题只是来自扩展。

服务器上启用了CORS,你知道问题的根源是什么吗?

服务器端相关代码:

router.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
if (req.headers.authorization !== '***') {
return res.status(403).json({ error: 'Unauthorized request' });
}
next();
});

客户端相关代码:

fetch('https://host:port/api/somepath', {
headers: new Headers({
Authorization: '*****',
}),
})
.then(....

Firefox错误:

错误:类型错误:尝试获取资源时出现网络错误

扩展清单权限:

"permissions": ["storage", "activeTab", "declarativeContent","webRequest", "webRequestBlocking", "webNavigation"],

"<all_urls>"权限允许您访问有人访问的每个网站,这是一种过度使用。您需要为Firefox添加的只是您试图在提取中调用的URL(例如,在您的示例中为"https://host:port/api/somepath"(

结果扩展清单权限:

"permissions": [
"storage", 
"activeTab", 
"declarativeContent",
"webRequest", 
"webRequestBlocking", 
"webNavigation",
"https://host:port/api/somepath"
],

发现问题,我在扩展清单中缺少1个权限,添加了:

"<all_urls>"

到权限数组修复问题=(

最新更新