Skip to content

Instantly share code, notes, and snippets.

@e-orlov
Forked from kimuchi1203/log_tabs.js
Created March 18, 2020 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e-orlov/43871aa4c3bc1f82c7a8295ad65f5e81 to your computer and use it in GitHub Desktop.
Save e-orlov/43871aa4c3bc1f82c7a8295ad65f5e81 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