Closed Bug 2011516 Opened 3 months ago Closed 2 months ago

action.openPopup() should reject if the window is not a foreground window

Categories

(WebExtensions :: General, enhancement, P2)

enhancement

Tracking

(firefox149 fixed)

RESOLVED FIXED
149 Branch
Tracking Status
firefox149 --- fixed

People

(Reporter: robwu, Assigned: robwu)

References

(Blocks 1 open bug)

Details

(Keywords: dev-doc-complete, Whiteboard: [addons-jira])

Attachments

(2 files)

The action.openPopup() API currently focuses a window if it was not focused before.
This can result in surprising behavior, and is not supported by Chrome https://issuetracker.google.com/issues/345640558

We should reject with a new error message instead. Chrome's error message is as follows, for reference:

Cannot show popup for an inactive window. To show the popup for this window, first call `chrome.windows.update` with `focused` set to "true."

We'd want our error message to be more generic, because the recommendation of using focused:true would not work on Android (when implemented - bug 1817809). There, the extension has to make the relevant tab active instead (e.g. browser.tabs.update(tabId, { active: true }).

Removing this feature could also enable us to re-enable the tests on Linux (bug 1798334), where it is currently skipped for causing intermittent failures. If we don't need to depend on a particular sequence of window state changes, and only need to check for errors, the test becomes more reliable.

Note: Safari's behavior is to show the minimized/background window, like Firefox does now (https://github.com/w3c/webextensions/issues/160#issuecomment-1127042759).

Since Chrome has shipped their behavior for so long without notable complaints, I expect that we'd be able to not automatically focus the window.

On the other hand, action.openPopup() can currently already be called with user interaction (e.g. shortcut), and that could potentially rely on the window getting focused. So I'd put the old behavior behind a pref, to allow us to re-enable support for automatic focusing of windows if needed.

Severity: -- → N/A
Priority: -- → P2
See Also: → 1795956

The tests are for browserAction.openPopup, but the implementation is
identical between action.openPopup and browserAction.openPopup.

Duplicate of this bug: 1798334

As explained in bug 2015895, extension popups are not closed on Android
when an extension unloads. That is a pre-existing bug, and will cause
test failures when we start rejecting action.openPopup() calls when
another extension popup is present.

As a work-around, this patch explicitly closes popups that were opened
during the test. These can be removed when bug 2015895 is fixed.

Blocks: 2016283
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 149 Branch
Flags: needinfo?(rob)
Regressions: 1855364

dev-doc-needed:
I wanted to mention this in the action.openPopup() documentation, but https://github.com/mdn/content/pull/43370 was merged without review from me, so I'm requesting documentation here.

Before 149, action.openPopup could be passed a windowId to open the popup for a different window, and that window would be focused before the popup was opened. This behavior was removed in 149: the windowId (if passed) can only match the active window's ID. If the window is not focused, browser.windows.update(windowId, { focused: true }) needs to be called first.

This behavior is also what Chrome has implemented, so the primary article for action.openPopup can call out this behavior.

Keywords: dev-doc-needed
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: