内容脚本未显示在Chrome开发工具

时间:2018-01-01 06:02:40

标签: javascript google-chrome-extension angular5

我在manifest.json中有这个设置:

  "content_scripts": [
    {
      "matches": ["http://*/*"],
      "css": [],
      "js": ["content-script.js"]
    }
  ],

这是content-script.js文件中的代码:

console.log('this is the content script.');

chrome.browserAction.onClicked.addListener(function(tab) {

  console.log('the following tab was clicked:', tab);

  chrome.tabs.executeScript({
    code: 'document.body.style.backgroundColor="red"'
  });
});

如果我点击弹出按钮并打开Chrome扩展程序,请点击"检查"并打开开发工具,我没有看到列出的任何内容脚本:

enter image description here

然而,现在它变得非常奇怪,因为Chrome说它无法找到manifest.json文件:

enter image description here

但是,很明显它可以找到我的manifest.js脚本,该脚本在我的manifest.json文件中声明:

enter image description here

如您所见,可以识别选项页面和背景页面。因此,Chrome似乎确实识别/检测了清单文件。

有人知道可能出现什么问题吗?如何才能加载我的内容脚本?

1 个答案:

答案 0 :(得分:1)

我不确定为什么说清单没有显示出来。但我意识到你不应该检查扩展窗口来查找你的内容脚本。相反,打开一个使用http并加载网页的其他标签,例如http://www.quora.com,然后打开开发工具,您的内容脚本应该加载到那里。