首页 > 解决方案 > Content.js 没有触发

问题描述

我正在尝试一个超级基本的“hello world”chrome 扩展。我想要一个内容脚本与浏览器的页面进行交互。content.js 中没有错误,但没有控制台日志。

我在这里尝试过 Google 的文档: https ://developer.chrome.com/extensions/content_scripts

并在这里看过这个人: https ://www.youtube.com/watch?v=9Tl3OmwrSaM&list=PLRqwX-V7Uu6bL9VOMT65ahNEri9uqLWfS&index=3

清单.json

{
  "manifest_version": 2,
  "name": "Hello World",
  "version": "1.0",
  "description": "xxxxx",
  "browser_action": {
    "default_icon": "images/icon128.png",
    "default_popup": "popup.html"
  },
  "content_scripts": [
    {
      "matches": [
        "<all_urls>"
      ],
      "js": ["content.js"]
    }
  ],
  "permissions": [
    "activeTab"
  ]
}

popup.html

<!DOCTYPE html>
<html>
  <head>
    <script src="js/Main.js" type="text/javascript"></script>
    <style>
      button {
        height: 30px;
        width: 300px;
        outline: none;
      }
    </style>
  </head>
  <body>
    <button id="btnTest">TEST</button>
  </body>
</html>

内容.js

console.log("CONTENT!");

有任何想法吗?

标签: google-chrome-extension

解决方案


除了鼓励您在每次更新后重新加载扩展的评论之外,请确保您没有在扩展页面本身 ( chrome://extensions/) 上测试此扩展。尝试类似的东西www.google.com。您不能将内容注入chrome://extensions/页面。


推荐阅读