W3cubDocs

/Web Extensions

tabs.getCurrent()

Get a tabs.Tab containing information about the tab that this script is running in.

Note: This function is only useful in contexts where there is a browser tab, such as an options page.

If you call it from a background script or a popup, it will return undefined.

This is an asynchronous function that returns a Promise.

Syntax

const gettingCurrent = browser.tabs.getCurrent()

Parameters

None.

Return value

A Promise that will be fulfilled with a tabs.Tab object containing information about the current tab. If any error occurs the promise will be rejected with an error message.

Examples

Get information about the current tab:

function onGot(tabInfo) {
  console.log(tabInfo);
}

function onError(error) {
  console.log(`Error: ${error}`);
}

const gettingCurrent = browser.tabs.getCurrent();
gettingCurrent.then(onGot, onError);

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
getCurrent
Yes
14
45
?
Yes
14
?
?
54
?
?
?

Note: This API is based on Chromium's chrome.tabs API. This documentation is derived from tabs.json in the Chromium code.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/getCurrent