Mozilla附加insertCSS或executeScript似乎不起作用

时间:2019-02-17 19:13:07

标签: javascript firefox mozilla add-on

我试图编写一个基本的mozilla附加组件以在任何页面上创建聚光灯效果。这是我的manifest.json文件

bash-3.2 $ cat manifest.json     {

  "manifest_version": 2,
  "name": "Mkr",
  "version": "1.0",

  "description": "Adds a spotlight all webpages matching mozilla.org.",

  "icons": {
    "48": "icons/border-48.png"
  },

  "permissions": [
     "activeTab",
     "https://*.mozilla.org/*"
  ],

  "content_scripts": [
    {
      "matches": ["*://*.mozilla.org/*"],
      "js": ["lib/Readability.js","spotlighter.js"]
    }
  ]

}

这是我的spotlighter.js文件

bash-3.2 $ cat spotlighter.js

console.log("Spotlight: Debug");

function onError(error) {
        console.log(`Error: ${error}`);
          }

//Insert spotlight CSS


//browser.browserAction.setTitle({title: "A reader"});
browser.tabs.insertCSS({file: "css/spotlight.css"});

//Insert spotlight JS
browser.tabs.executeScript({file: "lib/spotlight.js"});

//Extract article and add spotlight divs
var article = new Readability(document).parse();
console.log(article.content);

//Modify for spotlight

ct = "<div class=\"searchlight\"></div> <div class=\"canvas\">" + article.content + "<div>"

document.body.innerHTML = ct;

当我从console.log中的mozilla.org获取页面时,我可以看到“ Spotlight:Debug”消息,但看不到article.content。在此之后,它似乎没有插入CSS或执行脚本或执行可读性代码。但是,如果我注释掉所有浏览器。如果在Spotlighter.js脚本中排了几行,那么该脚本的其余部分似乎就会执行。为什么附加组件不插入CSS或执行脚本?浏览器的开发人员控制台中也绝对没有错误消息。任何指针都将不胜感激。

0 个答案:

没有答案