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…


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:

How get from background process, when user change tab ???

Second variant for get url in passive mode - onclick:

browser.tabs.query({active: true, windowId:})
.then(tabs => browser.tabs.get(tabs[0].id))
.then(tab => {;

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: