从后台扩展的网页获取数据

时间:2018-02-22 21:11:30

标签: javascript firefox-addon

我正在为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 ..]

0 个答案:

没有答案