Friday, May 10, 2024
47
rated 0 times [  48] [ 1]  / answers: 1 / hits: 42630  / 12 Years ago, fri, june 22, 2012, 12:00:00

I am creating an extension for Chrome. I want to show an alert() with the page URL whenever the user moves from one tab to another, or when the user enters a new URL in a tab.



This is not working:



chrome.tabs.onUpdated.addListener(function(integer tabId, object changeInfo, Tab tab) {
alert(changeInfo.url);
});

chrome.tabs.onActivated.addListener(function(object activeInfo) {
// also please post how to fetch tab url using activeInfo.tabid
});

More From » google-chrome-extension

 Answers
11

Remove integer, object and Tab in the functions signature. Also change .onUpdated to .onActivated



chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
alert(changeInfo.url);
});

chrome.tabs.onActivated.addListener(function(activeInfo) {
// how to fetch tab url using activeInfo.tabid
chrome.tabs.get(activeInfo.tabId, function(tab){
console.log(tab.url);
});
});

[#84727] Thursday, June 21, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dustin

Total Points: 599
Total Questions: 105
Total Answers: 106

Location: Belarus
Member since Tue, Mar 14, 2023
1 Year ago
;