tabs.getCurrent() result is undefined?

Not sure why I cannot retrieve info about current tab using getCurrent() when I navigate to, say, or and hit the browser icon for a browser action. Any hints on what I am missing?


  "name": "testGetCurrentTab",
  "version":  "1.0",
  "description":  "",
  "manifest_version": 2,

  "icons": {
    "48": "icons/icon-48.png"

  "permissions": [

  "browser_action": {
      "default_icon": "icon/icon-32.png"

  "background": {
      "scripts": ["background.js"]


function displayInfo() {

  function onGot(tabInfo) {
    console.log('Inside onGot() ...');

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

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


Here is the output:

Inside onGot() ...  background.js:4:7

undefined  background.js:5:7

Firefox Dev Edition 54 (64bit)



From MDN tabs.getCurrent():

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

You can call this function 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.

The browserAction.onClicked event returns the active tab, you do not need another API call.

browser.browserAction.onClicked.addListener(function(tab) {

See the tab parameter for browserAction.onClicked listener.


You can get the currently active tab in the background.js file as well when doing

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


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.