Skip to content

Instantly share code, notes, and snippets.

@kimuchi1203
Last active March 18, 2020 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kimuchi1203/5998828 to your computer and use it in GitHub Desktop.
Save kimuchi1203/5998828 to your computer and use it in GitHub Desktop.
chrome extension to log tabs user watched.
var tabToUrl = {};
chrome.tabs.onCreated.addListener(
function(tab) {
console.log("create "+tab.url);
}
);
chrome.tabs.onUpdated.addListener(
function(tabId, changeInfo, tab) {
console.log("update "+changeInfo.url);
tabToUrl[tabId] = tab.url;
}
);
chrome.tabs.onActivated.addListener(
function(activeInfo) {
chrome.tabs.get(activeInfo.tabId, function(tab) {
console.log("activate "+tab.url);
});
}
);
chrome.tabs.onHighlighted.addListener(
function(highlightInfo) {
chrome.tabs.get(highlightInfo.tabIds[0], function(tab) {
console.log("highlight "+tab.url);
});
}
);
chrome.tabs.onRemoved.addListener(
function(tabId, removeInfo) {
console.log("delete "+tabToUrl[tabId]);
delete tabToUrl[tabId];
}
);
chrome.tabs.onReplaced.addListener(
function(addedTabId, removedTabid) {
chrome.tabs.get(addedTabId, function(tab) {
console.log("replace "+tab.url);
});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment