Im get example - but it not working.
Maybe who ask - how get url of current tab
The example is not very good as the API returns a Promise. Also make sure you have proper permissions…
Example:
const currentTab = await browser.tabs.getCurrent();
// if you need only URL, you can use:
const {url: currentTabURL} = await browser.tabs.getCurrent();
tabs
permission or activeTab
permission (and execute the code in some user-triggered action, like context menu click). More info about permissions:How get from background process, when user change tab ???
Second variant for get url in passive mode - onclick:
browser.tabs.query({active: true, windowId: browser.windows.WINDOW_ID_CURRENT})
.then(tabs => browser.tabs.get(tabs[0].id))
.then(tab => {
console.info(tab.url);
});
You can use browser.tabs.onActivated.addListener()
to run code when the user changes tabs.
If you need an example, I use this to keep track of the most recently used tabs: https://github.com/jscher2000/switch-to-previous-active-tab/blob/master/background.js#L153