javascript - XMLHttpRequest 在 chrome 上工作,但在 firefox 上不工作
问题描述
我目前正在开发一个扩展以在我的工作中集成两个系统,chrome 扩展运行得很好并且运行良好,但是我的团队还要求一个 firefox 版本,在 firefox 中我遇到了 xmlhttprequest() 的问题,
调用请求的函数是这个:
function getModelList(API_KEY)
{
return new Promise(resolve => {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "POST", 'http://10.255.12.128/api/get_models/', true );
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onload = function(e) {
resolve(xmlHttp.response);
};
xmlHttp.onerror = function (e) {
resolve(undefined);
console.error("** An error occurred during the XMLHttpRequest");
};
xmlHttp.send( 'API_KEY='+API_KEY );
})
}
(我知道在 POST 中发送 API_KEY 是不安全的,但它只在我们的本地网络中运行,所以现在可能没问题)
当我运行它时,它直接进入onerror,它比超时更快,并且在检查时不显示在网络选项卡中,我想我需要在firefox中给它一些权限或其他东西才能运行?
另外,扩展的清单是这个(也许问题在这里?):
{
"name" : "Zabbix-Bitrix Integration",
"version": "0.0.4",
"manifest_version": 2,
"description" : "Insere funções extras ao zabbix",
"options_ui": {
"page": "options.html",
"open_in_tab": false,
"browser_style": true,
"chrome_style": true
},
"content_scripts" : [
{
"js" : ["init.js"],
"css": ["styles.css"],
"matches" : ["*://zabbix.monitor.redeunifique.com.br/zabbix.php?action=problem.view*"]
}
],
"permissions": ["storage","webRequest"]
}
@edit,经过一番挖掘,发现一条错误消息:错误:收到请求http://10.255.12.128/api/get_models/没有设置浏览上下文ID
调用错误的函数有这样的注释:
// Ensure that we have a browsing context ID for all requests when debugging a tab (=`browserId` is defined).
// Only privileged requests debugged via the Browser Toolbox (=`browserId` null) can be unrelated to any browsing context.
if (!this._browsingContextID && this._networkEventWatcher.browserId) {
throw new Error(
`Got a request ${this._request.url} without a browsingContextID set`
);
}
如何以及在哪里设置此上下文 ID?
解决方案
推荐阅读
- ruby-on-rails - 如何使用rails_admin gem从rails中的另一个表中下拉?
- shell - 如何使用文档的行数在 shell 中设置“for i in seq”或等效项
- python - 如何检查单个朴素贝叶斯预测的结果?
- javascript - for循环检查哪个日期是星期几(周末或工作日)
- java - 请求许可后继续 Android Studio
- azure - 如何将消息从 ServiceBusQueueTrigger Azure 函数发送到 Durable Function
- json - 使用 jq 将 JSON 导出为 CSV
- python-3.x - 将 csv 文件数据导入 pandas 数据框时出错
- typescript - 通过 Typescript 中实现的接口捕获错误
- json - JsonSerializable 与 dart 中的子类