It’s a very simple code.
I used the ‘chrome.tabs.onUpdated.addListener’ and ‘chrome.tabs.onActivated.addListener’ functions to check if the page has finished loading.
For testing, I tried to page refresh, page naviage.
But my code doesn’t work.
What do I need to fix?
manifest.json
{
"manifest_version": 3,
"name": "Tab Events Logger",
"version": "1.5",
"description": "Logs tab update and activation events",
"permissions": [
"tabs"
],
"background": {
"service_worker": "background.js"
},
"icons": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"action": {
"default_popup": "popup/popup.html",
"default_icon": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
}
}
}
background.js
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
console.log("Tab updated:", tabId, tab.url);
console.log("Change Info:", changeInfo);
});
chrome.tabs.onActivated.addListener((activeInfo) => {
console.log("Tab activated:", activeInfo.tabId);
});