The current browsing context's document loses focus when a download is triggered because the DownloadsPanel takes focus
Categories
(Remote Protocol :: Agent, defect, P2)
Tracking
(Not tracked)
People
(Reporter: julienw, Unassigned)
Details
(Whiteboard: [webdriver:m21])
STR:
- Clone https://github.com/julienw/bug-firefox-webdriver-focus-after-download
- Run
npm ithennpm test
=> Notice that all focus-related tests fail after initiating download.
From what I see after removing the headless arg, the problem is that the download manager is present. If I add some code to send the Escape to the chrome, with some timeouts before/after to account for races, then the tests are passing as expected.
I understand it's useful for a user, especially for accessibility, but it would be good to have a pref to avoid that, that we could use in tests.
Thanks
Comment 1•2 months ago
|
||
Julien, does it still happen with the latest Nightly build?
Comment 2•2 months ago
|
||
I tried on latest main it still happens.
We can modify one of our wdspec tests to check that:
diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browser/set_download_behavior/download_behavior_allowed.py b/testing/web-platform/tests/webdriver/tests/bidi/browser/set_download_behavior/download_behavior_allowed.py
index 1fa9a1a37803..7828c4f9393c 100644
--- a/testing/web-platform/tests/webdriver/tests/bidi/browser/set_download_behavior/download_behavior_allowed.py
+++ b/testing/web-platform/tests/webdriver/tests/bidi/browser/set_download_behavior/download_behavior_allowed.py
@@ -1,4 +1,6 @@
import pytest
+import time
+from webdriver.bidi.modules.script import ContextTarget
pytestmark = pytest.mark.asyncio
@@ -21,7 +23,29 @@ async def test_destination_folder(bidi_session, new_tab, temp_dir,
"type": "allowed",
"destinationFolder": temp_dir
})
+
+ async def assert_has_focus():
+ hasFocus = await bidi_session.script.call_function(
+ arguments=[],
+ function_declaration="() => document.hasFocus()",
+ target=ContextTarget(new_tab["context"]),
+ await_promise=True,
+ user_activation=True,
+ )
+ assert hasFocus["value"]
+
+ # OK
+ await assert_has_focus()
+
+ # trigger the download, the download list will be displayed
event = await trigger_download(new_tab)
+
+ # wait a bit, does not fail immediately
+ time.sleep(1)
+
+ # KO: fails because focus is kept by the download manager
+ await assert_has_focus()
+
# Assert download is allowed.
assert event["status"] == "complete"
# Assert `destinationFolder` is respected.
Comment 4•2 months ago
|
||
Ok, so we are speaking about the downloader popup which stays open when a download is initiated and finished? If that's the case we should probably enforce that the popup doesn't get opened.
Comment 5•2 months ago
|
||
so we are speaking about the downloader popup which stays open when a download is initiated and finished?
Correct.
Comment 6•2 months ago
|
||
So the problem seems to be here:
https://searchfox.org/firefox-main/rev/410a52656dd13aa2360a3e96788e41bf48e80c0f/browser/components/downloads/content/downloads.js#349
We probably need a preference to control the panel, and that we can force it to not show up by default for WebDriver.
Comment 7•2 months ago
|
||
Could be an issue with async events, let's tackle this next milestone.
Description
•