我正在开发Firefox附加组件,我无法从弹出脚本发送请求。它显示出一些错误
错误:阻止跨源请求:同源策略禁止读取远程资源
在chrome扩展工作正常。
弹出式脚本
$.ajax({
url: 'http://localhost/api/user/66f041e16a60928b05a7e228a89c3799/emailtemplate/c60d870eaad6a3946ab3e8734466e532',
type: 'GET',
dataType: 'json',
headers: { 'accessToken': 'Krc7YPoZPaYiy37O', 'appID': '28fdd9c013e37bca7dd875b10817b694', 'appSecret': '15798907115476fdf1de7a8' },
success: function(eventSettingsResponse) {
buildTemplate(eventDetailsResponse, eventSettingsResponse);
console.log('This is content script testing...', eventDetailsResponse);
},
error: function() { }
//beforeSend: setHeader
});
的package.json
{
"title": "First",
"name": "test",
"version": "0.0.1",
"description": "Just for testing",
"main": "index.js",
"author": "Bharath",
"engines": {
"firefox": ">=38.0a1",
"fennec": ">=38.0a1"
},
"permissions": {
"cross-domain-content": ["http://localhost/*"]
},
"license": "MIT"
}
Main.js
pageMod.PageMod({
include: ["https://mail.google.com/*"],
contentScriptFile: data.url("js/content.js"),
contentScriptWhen: 'end',
onAttach: function(worker) {
worker.port.emit("init", urls);
worker.port.on("showPopup", function() {
console.log('port received');
windows.open(data.url('popup/popup.html'), {
name: 'jetpack window',
features: {
width: 500,
height: 500,
popup: false
}
});
});
worker.port.on("returnHtml", function() {
console.log('Html returnde.');
});
}
});
答案 0 :(得分:0)
我读了here我可以将以下内容添加到package.json
"permissions": {
"cross-domain-content": ["https://data.com"]
}