How get address of current tab page?

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(); 
  1. this will work only from normal tabs, not from background script or pop-up script
  2. to access URL, you need either tabs permission or activeTab permission (and execute the code in some user-triggered action, like context menu click). More info about permissions:
    https://extensionworkshop.com/documentation/develop/request-the-right-permissions/#Request_permissions_at_runtime

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