Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome extension Chrome扩展和history.onVisited事件_Google Chrome Extension - Fatal编程技术网

Google chrome extension Chrome扩展和history.onVisited事件

Google 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

我是Chrome extensions开发的新手,我有以下问题: 我的扩展应该在后台工作,没有UI,并且在用户每次访问特定网页时显示一个警报对话框。因此,当浏览器被执行时,它应该始终在后台工作

我尝试了以下代码,但没有结果:

manifest.json

{
  "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
。顺便说一下,你的问题可以通过下面布拉德利的回答来解决。