Google chrome extension Chrome扩展和history.onVisited事件
我是Chrome extensions开发的新手,我有以下问题: 我的扩展应该在后台工作,没有UI,并且在用户每次访问特定网页时显示一个警报对话框。因此,当浏览器被执行时,它应该始终在后台工作 我尝试了以下代码,但没有结果: manifest.jsonGoogle chrome extension Chrome扩展和history.onVisited事件,google-chrome-extension,Google Chrome Extension,我是Chrome extensions开发的新手,我有以下问题: 我的扩展应该在后台工作,没有UI,并且在用户每次访问特定网页时显示一个警报对话框。因此,当浏览器被执行时,它应该始终在后台工作 我尝试了以下代码,但没有结果: manifest.json { "name": "My First Extension", "version": "1.0", "description": "The first extension that I made.", "background_pa
{
"name": "My First Extension",
"version": "1.0",
"description": "The first extension that I made.",
"background_page": "background.html",
"permissions": [
"history"
]
}
background.html
<html>
<head>
<script>
chrome.history.onVisited.addListener(function(HistoryItem result) {
if (result.url == "http://my.url.com") {
alert("My message");
}
});
</script>
</head>
</html>
chrome.history.onvisted.addListener(函数(HistoryItem结果){
如果(result.url==”http://my.url.com") {
警惕(“我的信息”);
}
});
这个代码怎么了
谢谢将HistoryItem从函数中取出,您就没事了:
<html>
<head>
<script>
chrome.history.onVisited.addListener(function(result) {
if (result.url == "http://my.url.com/") {
alert("My message");
}
});
</script>
</head>
</html>
chrome.history.onvisted.addListener(函数(结果)){
如果(result.url==”http://my.url.com/") {
警惕(“我的信息”);
}
});
还请注意,我在“”的末尾添加了斜杠,因为这将在result.url中返回。测试:
<script>
chrome.history.onVisited.addListener(function(e) { console.log(e)})
</script>
chrome.history.onvisted.addListener(函数(e){console.log(e)})
显然考虑使用更新的
chrome.tabs.on
。它返回changeinfo.url
。顺便说一下,你的问题可以通过下面布拉德利的回答来解决。