Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/windows/getlastfocused/index.md
6565 views
------{{AddonSidebar()}}
Gets the window that was most recently focused — typically the window 'on top'.
This is an asynchronous function that returns a Promise.
Syntax
Parameters
getInfo{{optional_inline}}:
object.populate{{optional_inline}}:
boolean. Iftrue, the {{WebExtAPIRef('windows.Window')}} object will have atabsproperty that contains a list of {{WebExtAPIRef('tabs.Tab')}} objects representing the tabs in the window. TheTabobjects only contain theurl,titleandfavIconUrlproperties if the extension's manifest file includes the"tabs"permission or host permissions matching the tab's URL.
windowTypes{{optional_inline}}: An
arrayof {{WebExtAPIRef('windows.WindowType')}} objects. If set, the {{WebExtAPIRef('windows.Window')}} returned will be filtered based on its type. If unset the default filter is set to['normal', 'panel', 'popup'], with'panel'window types limited to the extension's own windows.
Note: If supplied, the
windowTypescomponent ofgetInfois ignored. The use ofwindowTypeshas been deprecated as of Firefox 62.
Return value
A Promise that will be fulfilled with a {{WebExtAPIRef('windows.Window')}} object containing the details of the last focused window. If any error occurs, the promise will be rejected with an error message.
Browser compatibility
{{Compat}}
Examples
Get the last focused window, and log the tabs it contains. Note that you'll need the "tabs" permission or matching host permissions to access tab URLs.
{{WebExtExamples}}
Note: This API is based on Chromium's
chrome.windowsAPI. This documentation is derived fromwindows.jsonin the Chromium code.