0

In my Chrome Extension, I want that when the URL is reloaded then an alert box will appear, but it does not work

Here is the manifest:

{
    "manifest_version": 2,
    "name": "Sample Extension",
    "description": "Sample Chrome Extension",
    "version": "1.0",
    "background": {
        "scripts": ["background.js"]
    },
    "browser_action": {
        "default_icon": "icon.png",
        "default_title": "That's extension",
        "default_popup": "popup.html"
    },
    "permissions":[
        "http://translate.google.hu/*", "tabs"
    ]
}

background.js:

chrome.tabs.onUpdated.addListener(function(tabId,changeInfo,tab) {
    if (tab.url.indexOf("http://translate.google.hu/") > -1 && 
            changeInfo.url == "undefined") {
        window.alert('test')
    }
});
Xan
  • 74,770
  • 16
  • 179
  • 206
  • @livibetter It's always better to add a language tag instead of language markup if the question is definitely about one language. It will enable syntax highlight for answers too. – Xan Apr 20 '15 at 09:37

1 Answers1

0

var object = {};
if(object.something == "undefined") {
  alert("True");
} else {
  alert("False"); 
}

You are trying to see if something is undefined by comparing it to a string saying "undefined". That does not work.

The proper way is to check the type:

if(typeof changeInfo.url == "undefined") { /* ... */ }

The quick and dirty way is to check the truth value: any non-empty string is true and undefined is false:

if(changeInfo.url) { /* ... */ }
Xan
  • 74,770
  • 16
  • 179
  • 206