Returns information about the focused workspace tab or subtab. This method works only in Lightning console apps.
To retrieve information about the workspace tab or the subtab that a component is rendered in, don’t use getFocusedTabInfo(). When lifecycle hooks such as renderedCallback() or connectedCallback() are invoked for the component, the tab enclosing that component isn’t guaranteed to be in focus, so getFocusedTabInfo() sometimes doesn’t return that tab’s information.
We recommend that you continue to use getFocusedTabInfo() with components in the utility bar, because the utility bar doesn’t have an enclosing tab ID.
Note
Arguments
None.
LWC Sample Code
This component checks if it’s in a Lightning console app, using the IsConsoleNavigation wire adapter, and returns information about the focused tab or subtab. It uses the tabId and highlighted properties from the tabInfo return object to toggle highlighting on the tab.
To make your component available for use in a Lightning console app, specify the lightning__AppPage target in the component’s configuration file.
Aura Components Sample Code
This component has a button that, when clicked, closes the currently focused tab.
This is the component code. The lightning:workspaceAPI component provides access to Lightning console methods. When clicked, the lightning:button base component executes the closeFocusedTab action in the component’s client-side controller.
This is the client-side controller code. The closeFocusedTab action retrieves the tab ID of the tab in focus, and then closes the tab with that ID.
1({2 closeFocusedTab : function(component, event, helper){3 var workspaceAPI = component.find("workspace");4 workspaceAPI.getFocusedTabInfo().then(function(response){5 var focusedTabId = response.tabId;6 workspaceAPI.closeTab({tabId: focusedTabId});7})8 .catch(function(error){9 console.log(error);10});11}12})
Response
This method returns a promise that, upon success, resolves to a tabInfo object that represents the focused tab. A tabInfo object is a JSON array of information about a workspace tab, with nested arrays of information on each subtab. This is the structure of a tabInfo object.