To retrieve information about the tab or the subtab that a component is rendered in, first use getEnclosingTabId() instead of getFocusedTabInfo(). Then call getTabInfo() and use the enclosing tab’s ID as the argument. By using getEnclosingTabId(), you make sure that the correct tab ID is returned when you work with lifecycle hooks such as renderedCallback() or connectedCallback().
Tip
Arguments
None.
Aura Components Sample Code
This component has a button that, when clicked, retrieves the enclosing tab ID.
This is the component code. The lightning:workspaceAPI component provides access to Lightning console methods. When clicked, the lightning:button base component executes the handleGetEnclosingTabId action in the component’s client-side controller.
This method returns a promise that, upon success, resolves to the tabId of the enclosing tab, if within a tab. If not within a tab, the method resolves to false upon success.