我正在尝试从用户正在查看的页面中提取数据并将该数据发送到扩展弹出窗口。我在从当前页面提取信息时遇到了麻烦。在查看了谷歌代码教程后,我设置了我的清单和内容脚本,如下所示。当我转到一个跨度为 id="comments" 的测试页面时,来自注入内容脚本的变量总是以 null 结束。有人知道我可能会错过什么吗?谢谢!
manifest.json
=================
{
"name": "Sample Extension",
"version": "0.0.1",
"description": "Sample extension",
"icons": {"128": "icon.png"},
"permissions": [
"tabs", "<all_urls>"
],
"browser_action": {
"default_icon": "browseraction.png",
"default_title": "Sample",
"popup": "popup.html"
},
"content_scripts": [
{
"matches": ["http://*/*", "<all_urls>" ],
"js": ["scripts/contentscript.js"]
}
]
}
contentscript.js
===================
var comments = document.getElementById("comments");
alert( comments.innerText );