Doug Molineux
Doug Molineux

Reputation: 12431

Google Chrome Extension Running in the background

I am trying to make a google extension that basically checks the current tab URL to see if the URL is our prefix, so far I have this in my background.html (I have tab and background permissions set in my manifest):

<script type="text/javascript">
        chrome.tabs.getSelected(null, function(tab) {
            alert(tab.url);
            if(tab.url == "http://www.google.com") {
                alert("YOU'RE AT GOOGLE");
            }
            //changeTabURL(tab.url, tab);
        });
</script>

So this seems to run only when I first load the extension, it tells me "chrome://extensions" and then it disappears. How do I get it to check each time the user goes to a new URL? Is this possible?

Thanks!

Upvotes: 0

Views: 1125

Answers (2)

serg
serg

Reputation: 111265

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    if(changeInfo.status == "loading"){ 
        //do url check
    }
});

Upvotes: 3

ztatic
ztatic

Reputation: 1181

use the following:

chrome.tabs.onUpdated.addListener(function(Tab tab) {...});

See the documentation here.

Upvotes: 2

Related Questions