我在我的扩展程序中找不到我的内容脚本

I can't find my content script in my extension

我正在为 Google chrome 写扩展。

我正在尝试编写一个内容脚本,该脚本将在单击弹出窗口时从选项卡中获取元标记。

我的清单中有以下权限:

"content_scripts": [{
    "js": ["src/js/DOMReader.js"],
    "matches" : [
        "*://*/*",
        "http://*/*",
        "https://*/*"
    ]
}],
"permissions": [
    "unlimitedStorage",
    "storage",
    "notifications",
    "activeTab",
    "tabs",
    "bookmarks",
    "browsingData",
    "identity",
    "topSites",
    "history"
]

每当我调用内容脚本时,它 returns 默认错误值,当我使用开发人员控制台源选项卡查找它时,我看不到我的内容脚本。

我无法正确调试我的代码,因为我什至看不到内容脚本,无法知道是否有问题。我只想知道为什么我什至看不到我的内容脚本,而且搜索也没有显示任何内容。

来自documentation

Content scripts execute in a special environment called an isolated world. They have access to the DOM of the page they are injected into, but not to any JavaScript variables or functions created by the page. It looks to each content script as if there is no other JavaScript executing on the page it is running on.

所以这意味着您将无法在您的开发工具正在检查的同一页面上看到它。相反,您必须将代码注入到您实际想要检查的网页中。描述的方法 here(还有关于内容脚本的更多详细信息)