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

问题描述 投票:1回答:1

我在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似乎确实识别/检测清单文件。

有谁知道可能出错了什么?如何才能加载我的内容脚本?

javascript google-chrome-extension angular5
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.