views:

49

answers:

2

Hi to all,

I'm new to the Chrome extensions development, and i have the following questions: My extension should work in background, with no UI, and show an alert dialog every time the user visits a specific web page. So it should work always, in backround, when the browser is executed.

I was trying with the following code without results:

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>

What's wrong with this code?

Thanks

+1  A: 

Take HistoryItem out of the function and you are fine:

<html>
<head>
<script>
chrome.history.onVisited.addListener(function(result) {
    if (result.url == "http://my.url.com/") {
        alert("My message");
    }
}); 
</script>
</head>
</html>

Also note that I added the slash at the end of "http://my.url.com/" since that is what will be returned in result.url.

Bradley Mountford
A: 

Test this:

<script>
chrome.history.onVisited.addListener(function(e) { console.log(e)})
</script>

it's clearly

bsnxff