Open Bug 1912558 Opened 1 year ago Updated 1 year ago

Ability for extensions to switch focus between sidebar and active browser tab

Categories

(WebExtensions :: General, enhancement, P3)

Firefox 128
enhancement

Tracking

(Not tracked)

People

(Reporter: alex, Unassigned)

References

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:129.0) Gecko/20100101 Firefox/129.0

Steps to reproduce:

This is an enhancement request for giving browser extensions the ability to switch focus between the extension's sidebar and the main frame of the active browser tab.

My Firefox extension has a sidebar UI which let users insert text into a web page textbox by clicking on an element that is displayed in the sidebar. When the action in the sidebar is performed, a message is sent to the content script which first tries to focus the active element (the web page textbox) before inserting text. I've tried two approaches to focusing: calling window.focus() or activeElement.ownerDocument.defaultView.focus().

This RFE originates from this discussion in the Firefox add-ons developer forum: https://discourse.mozilla.org/t/switching-focus-from-the-sidebar-to-the-active-tab/132436

Actual results:

The web page textbox sometimes fails to gain focus.

A workaround was found where the end user would have to perform this sequence of actions:

  1. Select the item in the extension sidebar whose text is to be inserted into the web page textbox in the active tab
  2. Click on the target textbox in the web page in the active tab
  3. Perform the action in the sidebar to trigger the text insertion

Using this workaround, the user must always click on the web page textbox first, otherwise the text may not be inserted. This is an awkward user experience.

Expected results:

The web page should consistently gain focus when the content script that executes window.focus() or activeElement.ownerDocument.defaultView.focus() is invoked by the sidebar via extension messaging.

The Bugbug bot thinks this bug should belong to the 'WebExtensions::Untriaged' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Product: Firefox → WebExtensions

This was discussed before in the WECG at https://github.com/w3c/webextensions/issues/693
and there is consensus on supporting this capability.

Patches are welcome!

Severity: -- → S3
Status: UNCONFIRMED → NEW
Component: Untriaged → General
Ever confirmed: true
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.