Open Bug 1943448 Opened 14 days ago Updated 13 days ago

Support focussing the document in background windows with "focusmanager.testmode" enabled

Categories

(Core :: DOM: Core & HTML, enhancement)

enhancement

Tracking

()

People

(Reporter: whimboo, Unassigned)

Details

With the FocusManager test mode we have a way to simulate that a window in the background is considered internally as the top-most window to as well receive user events. This is required by WebDriver so that we can run user interactions in multiple windows in parallel.

As I've just discovered when investigating test failures in Playwright when running them with WebDriver BiDi they also consider Nodes in those background windows as focusable. Right now this doesn't work in Firefox because the focus manager doesn't support it, and the Playwright team added the following code to their custom Firefox build to support it:

It would be great if we could support that as well.

Manually it can be reproduced with the following steps:

  1. Open about:config and set focusmanager.testmode to true
  2. Load some web page
  3. Open a new window
  4. Open the browser toolbox and enable multi-process mode
  5. Select the original window with some web page as target
  6. Run document.hasFocus() in the console

With step 6 the document of the now background window has no focus but it should have.

Actually this is about the document to receive the focus and not about individual elements. So I'm updating the bug's summary.

The line of code that currently returns false is:
https://searchfox.org/mozilla-central/rev/55706b888f91fffa6f045f7cbc1a7b1c34598292/dom/base/Document.cpp#4638-4640

  if (!fm->IsInActiveWindow(bc)) {
    return false;
  }

  return fm->IsSameOrAncestor(bc, fm->GetFocusedBrowsingContext());

Not sure if it would be ok to have a check for fm->IsTestMode() added before, or if it could cause some side-effects.

Henry, do you have more details? Olli mentioned that you may still know more about the focus manager test mode these days. Thanks!

Flags: needinfo?(hsivonen)
Summary: Support focussing of elements in background windows with "focusmanager.testmode" enabled → Support focussing the document in background windows with "focusmanager.testmode" enabled

Unfortunately, I don't recall the specifics of the interaction here. My expectation is that unwanted side effects are likely, but to find out what those are, you need to try the change and experiment. Sorry.

Flags: needinfo?(hsivonen)
You need to log in before you can comment on or make changes to this bug.