我正在为mozilla编写扩展程序。 manifest.json
权限是:
` "permissions": [
"tabs",
"activeTab",
"menus",
"https://glosbe.com/*",
"https://*/" //redundant, just a try
],`
和background.js
:
`function text_translate(){
var url = "https://glosbe.com/gapi/translate?from="
url += f_lang ;
url += "&dest=" + t_lang + "&format=json&phrase=";
url += text;
$.ajax({
type: "GET",
url: url,
async:true,
dataType : 'jsonp', //you may use jsonp for cross origin request
crossDomain:true,
success: function(data, status, xhr) {
alert(data.tuc[0].phrase.text);
}
});
}`
但是当我运行扩展时,我收到了这个错误:
Loading failed for the <script> with source “https://glosbe.com/gapi/translate?from=&dest=&format=json&phrase=fa%20&callback=jQuery33107006632350570763_1519332433684&_=1519332433685”.
和
Content Security Policy: The page’s settings blocked the loading of a resource at https://glosbe.com/gapi/translate?from=&dest=&format=json&phrase=3%20ore%20fa%20&callback=jQuery33103711740868579675_1519334384027&_=1519334384028 (“script-src moz-extension://cff0712a-f5f0-4eff-8dc3-f2dbf5d8da4c”)
使用Chrome我没有遇到这些错误。仅使用Mozilla
这个错误是由于manifest.json
的错误配置造成的,还是不可能做我想要的?
修改
我在manifest.json
中添加一行来解决第二个错误(`content sicurity polici:[stuff ..]