Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/windows/getcurrent/index.md
6557 views
------{{AddonSidebar()}}
Gets the current browser window, passing its details into a callback.
The "current" window is not necessarily the same as the currently focused window. If this function is called from a background script, then it returns the currently focused window. But if it is called from a script whose document is associated with a particular browser window, then it returns that browser window. For example, if the browser is displaying a sidebar, then every browser window has its own instance of the sidebar document. If a script running in the sidebar document calls getCurrent(), then it will return that sidebar document's window.
This is an asynchronous function that returns a Promise.
Syntax
Parameters
getInfo{{optional_inline}}:
object.populate{{optional_inline}}:
boolean. If true, 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 that match the tab's URL.
windowTypes{{deprecated_inline}} {{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 windows.Window object containing the details of the window. If any error occurs, the promise will be rejected with an error message.
Browser compatibility
{{Compat}}
Examples
When the user clicks a browser action's icon, this example gets the current window and logs the URLs of 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.