Chrome Extension: What is the active tab in 2 opened windows?

前端 未结 2 671
广开言路
广开言路 2021-01-03 08:56

I have an extension that needs to know what URL is on the active tab, but the problem is that when I open a second chrome window there are 2 active tabs, in the webmaster to

2条回答
  •  离开以前
    2021-01-03 09:20

    Make your query to select the last focused Window:

    chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
      //...
    });
    

    Note: Better don't take currentWindow: true because:

    The current window is the window that contains the code that is currently executing. It's important to realize that this can be different from the topmost or focused window.

    Source: http://developer.chrome.com/extensions/windows.html#current-window

提交回复
热议问题