AutoControl Control your browser your way Forum               Install now from theChrome Web Store

ACtl.getTabInfo


Gets detailed information about one or more tabs.
ACtl.getTabInfo([tabSpec]) tabSpec Type: TabSpec Default: undefined One or more tabs to obtain their information. It can be either a tab ID, a filter object, a tab-selection name or an array combining all that. Full details at Tab Specifier.
If omitted, it defaults to the tab the script is running in.
Returns Type: Promise Resolves to: Object Returns immediately. The Promise will resolve with an object of [tabID, TabInfo] pairs that looks like this:

						{
							23: { /*... tab info ...*/ },
							51: { /*... tab info ...*/ },
							105: { /*... tab info ...*/ },
						}
						
This object is iterable, so it can be destructured like an array. See the examples below.
If tabSpec contains non-existent tab IDs, those IDs are excluded from the returned object.
Throws Type: string Error description if tabSpec is not a valid Tab Specifier.

TabInfo object

The TabInfo object contains the following properties:
Property Type Description
id number Integer number, unique identifier of the tab.
index number Position of the tab in its window, starting at 1 from the left.
title string Title of the page currently loaded in the tab.
url string URL of the page currently loaded in the tab.
favIconUrl string URL of the page's favicon.
openerTabId number ID of the tab that opened this one (if any).
status string The load status of the page: 'loading', 'loaded' or 'unloaded'.
active boolean Whether the tab is the active one in its window.
selected boolean Whether the tab is selected (by Ctrl+Click on the tab).
pinned boolean Whether the tab is pinned.
audible boolean Whether the tab is playing audio (speaker icon on tab's right edge).
muted boolean Whether the tab is muted.
incognito boolean Whether it's an incognito tab.
width number Width of the tab's viewport in pixels.
height number Height of the tab's viewport in pixels.
window.type string Type of window the tab belongs to: 'normal', 'popup', 'app' or 'devtools'.
window.state string Visibility state of the tab's containing window: 'normal', 'minimized', 'maximized', 'fullscreen', 'hidden'.
window.focused boolean Whether the tab's containing window is focused.
window.alwaysOnTop boolean Whether the tab is in a topmost window.
window.left number X coordinate of the window from the left edge of the desktop, in pixels.
window.top number Y coordinate of the window from the top edge of the desktop, in pixels.
window.width number Width of the window in pixels.
window.height number Height of the window in pixels.

Examples

Check whether the tab the script is running in is focused.

	//Get info for the tab the script is running in
	let [[, tabInfo]] = await ACtl.getTabInfo() ;
	//Whether the tab is active and its window is focused
	let tabIsFocused = tabInfo.active && tabInfo.window.focused ;
	alert( `The tab ${tabIsFocused ? 'IS' : 'IS NOT'} focused` ) ; 
	

Close all popup windows smaller than 300x300 pixels.

	//Get ALL tabs' info
	let allTabsInfo = await ACtl.getTabInfo('#allTabs') ;
	//Get each tabId and window info by destructuring each [tabID, TabInfo] pair 
	for( let [tabId, {window}] of allTabsInfo ){
		//If the window is a popup smaller than 300x300
		if( window.type == 'popup' && window.width < 300 && window.height < 300 )
			//Close the tab and, thus, the window (popup windows have only one tab)
			ACtl.closeTab(tabId) ;
	}
	
Scripting API Script Isolation Asynchronicity Backgrnd Scripts GUI vs API ACtl.include ACtl.import ACtl.getFile ACtl.saveFile ACtl.saveURL ACtl.openURL ACtl.closeTab ACtl.runInTab ACtl.runInFrames ACtl.runInPageCtx ACtl.getTabInfo ACtl.getTabIds ACtl.TAB_ID ACtl.setTabState ACtl.captureTab ACtl.execAction ACtl.runCommand ACtl.getClipboard ACtl.setClipboard ACtl.expand ACtl.switchState ACtl.var ACtl.pubVar ACtl.on ACtl.off ACtl.sleep ACtl.STOP_CHAIN ACtl.STOP_FULL_SEQ