google-chrome-extension - 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!");
有任何想法吗?
解决方案
除了鼓励您在每次更新后重新加载扩展的评论之外,请确保您没有在扩展页面本身 ( chrome://extensions/
) 上测试此扩展。尝试类似的东西www.google.com
。您不能将内容注入chrome://extensions/
页面。
推荐阅读
- node.js - 无法在邮递员中获取请求正文
- javascript - 安装 Angular CLI 时出错
- c# - 从 JSON 对象中获取键值
- c# - 将多个选择表达式组合成动态类
- report - Sparx Enterprise Architect EA 15 - 如何在报告中包含决策表
- python - 当我将 groupby 对象转换为 dict 时,grouper 对象已用尽
- scala - Scalatest provide position different file for assertion
- mysql - 如果一个字段为 NULL,GROUP_CONCAT 返回一行 NULL
- android - 在 Android Studio 中签署应用程序时的证书信息
- apache-kafka - Kafka not starting up if zookeeper.set.acl is set to true