Open Bug 1764162 Opened 3 years ago Updated 3 years ago

Occasionally, the `focus` event fails to fire when focusing a textarea in a cross-origin iframe

Categories

(Core :: DOM: UI Events & Focus Handling, defect, P3)

Firefox 98
defect

Tracking

()

UNCONFIRMED

People

(Reporter: rafael.hrtd, Unassigned)

References

Details

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

Steps to reproduce:

  1. Create a docker container that serves an HTML file containing an input (container A)
  2. Create a second docker container that:
    a) Creates a second HTTP server which serves an HTML file containing an iframe pointing to the file served in contained A.
    b) Runs repeated tests using selenium to check that a click on the iframe input causes the input to focus.

The tests above set up two listeners, one on 'click' events and the second one on 'focusin' events, which both save flags to the document's window variable. The flags are then checked to be true. If the focus flag was not set to true, the process is retried up to 5 times, each time checking that the click and focus events occurred. There is a one second wait between attempts.

I have set up a repository with the code needed to reproduce the issue:
https://github.com/rafaelhrtd/firefox_focus_check
To run the tests:

  1. git clone https://github.com/rafaelhrtd/firefox_focus_check.git
  2. cd ./firefox_focus_check && npm i
  3. chmod 755 ./run_tests.sh && ./run_tests.sh

Actual results:

The tests occasionally (read rarely, ~1 / 2000 runs on my computer) fail due to the focus flag being set to false after five attempts. I have not observed the click flag having a negative value at the moment of failure, so it appears that the click event is handled correctly, but somehow the focus event is prevented.

The problem does not seem to be caused by selenium. I came across this problem while working on end-to-end tests, and was able to examine Firefox after one of this failures. Attempting to click the input manually did not do anything, and the input would not focus until after I switched to a different Firefox window and then switched back. An example that allows for manual inspection is much harder to set up, however, which is why the linked repository only does it through selenium.

Expected results:

The input should always be focused when it is clicked.

The Bugbug bot thinks this bug should belong to the 'Core::DOM: UI Events & Focus Handling' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → DOM: UI Events & Focus Handling
Product: Firefox → Core
Flags: needinfo?(echen)
See Also: → 1763900

Yeah, this might be the same as bug 1763900, let's see whether fixing bug 1763900 helps first.

Flags: needinfo?(echen)
Severity: -- → S3
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.