I’ve been struggling for a long time with Chrome Extensions. How do I get the URL of the tab from background.js
(my service worker) ?
It seems like a very easy thing to do but……..
// manifest.json
{
"name": "Getting Started Example",
"description": "Build an Extension!",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"permissions": ["storage", "activeTab", "scripting"],
"action": {
"default_popup": "popup.html"
}
}
// background.js
chrome.tabs.onActivated.addListener(activeInfo => {
chrome.tabs.get(activeInfo.tabId, (tab) => {
// tab.url is undefined, it should not.
});
});
it doesn’t work. why ?