Is there a tabs API method (or any way) of setting the active browser tab based on user action?

Is it possible to create a menu of tab titles open in the browser from which users can click to set the active tab? For example, please consider the scenario of having the browser in fullscreen view and having a menu from which to choose which tab to view, without having to leave fullscreen view.

I can see how to generate the menu, but couldn’t find a method for setting the active tab in “Working with tabs” and other tabs API information. It appears that it isn’t permitted but I figured it prudent to ask here before giving up on it.

My real interest in this is that part of my extension opens local html pages and, in some cases, I don’t want to permit opening the same page in two spearate tabs to avoid confusion. I can check for this scenario and prevent it, but instead of just displaying a warning message and closing the tab, I’d prefer to have the duplicate tab close and move the user to the tab that was already open. I just can’t figure out how to make the already opened tab become the active tab. If a user navigates through the extension tool by using the tool menus only, this isn’t an issue; but I would like to prevent potential failures for scenarios in which a user navigates to a page through a bookmark, back button, browser file menu, etcetera.

Thank you.

IIRC you use tabs.update to set the tab’s active property.

I guess this could also be achieved by setting the parent tab to the tab you want to go to before closing the tab. Though that depends on the configured tab closing behavior, I think.

Edit: Ah, you can override the tab closing behavior in Firefox 66: https://bugzilla.mozilla.org/show_bug.cgi?id=1500479

Which fullscreen do you mean? The one where the website requests a fullscreen view? In which case switching the tab would require you to close the fullscreen view first. But since that menu would have to be injected into html, you’d already be able to do that.

Else I don’t quite see the point, as you can still access all browser functions by moving your cursor to the top of the monitor (and I think keyboard shortcuts to activate extension buttons etc. would also still work).

Thank you. I shouldn’t have missed that. Sure am I glad I asked.

I meant when the website requests a fullscreen view. The primary point of the tab menu is to limit it to the tabs that are specific to the extension’s use of local html pages; so that a user can navigate through those with the feel of a desktop application to some degree while in fullscreen view.

Thanks again for your help over the past few days also.

My addon page (FF for Android) just closes after switching to another active tab.
Is there any way to prevent this?

Is the page opened as a popup from a browser or page action? If so that’s the expected behavior. “popups” close when they lose focus.

It is popup, I think.
Yes, I see same behavior for other addons, but still need it to stay open after losing focus.
Can I force that in any way? It’s extension for me only, so dirty hacks are accepted as well :slight_smile:

You can use the browser.tabs API to open a tab with your extension page when the browser/page action is clicked instead of defining a popup.

Found also “background tabs” info there, solved, thank you!