RESOLVED CONFIGURATION CHANGED 275326
[WebDriver] If Safari window is not focused, WebDriver-automated mouse events do not get sent to the page
https://bugs.webkit.org/show_bug.cgi?id=275326
Summary [WebDriver] If Safari window is not focused, WebDriver-automated mouse events...
Qianlang Chen
Reported 2024-06-10 12:42:04 PDT
When using WebDriver/safaridriver to automate mouse events, if the target Safari window isn't focused, these mouse events may not work at all. To reproduce, 1. host this webpage named `a.html` on `localhost:8000`: <!DOCTYPE html> <html> <head></head> <body> Hello <script> const handle = (e) => { let info = JSON.stringify({ type: e.type, pageX: e.pageX, pageY: e.pageY, target: e.target, }); let el = document.createElement("div"); el.textContent = info; document.body.append(el); }; window.addEventListener("mousemove", handle); window.addEventListener("mousedown", handle); window.addEventListener("mouseup", handle); </script> </body> </html> 2. Run the following Python 3 code with Selenium 4 installed: import time from selenium.webdriver import Safari driver = Safari() driver.get("http://localhost:8000/a.html") time.sleep(5) driver.find_element("tag name", "body").click() time.sleep(42) 3. Observe that, if the Safari window is focused when the `click()` automation code runs (after about 5 seconds from the start), then three event logs show up in the webpage: {"type":"mousemove","pageX":256,"pageY":13,"target":{}} {"type":"mousedown","pageX":256,"pageY":20,"target":{}} {"type":"mouseup","pageX":256,"pageY":20,"target":{}} (Your events may have slightly different coordinates.) However, if the window isn't focused, either because it didn't come to the top natively when the script created it or because you quickly focused a different window in 5 seconds, then no logs show up in the webpage at all, meaning the automated events failed to be delivered. The expected behavior should be that the automated events get delivered to the Safari window and the webpage regardless of whether the window is focused, like in Firefox or Chrome. rdar://117035696
Attachments
EWS
Comment 1 2024-06-14 17:54:17 PDT
Committed 280047@main (3e29d37be2b6): <https://commits.webkit.org/280047@main> Reviewed commits have been landed. Closing PR #29683 and removing active labels.
Qianlang Chen
Comment 2 2024-06-20 14:48:23 PDT
The patch https://github.com/WebKit/WebKit/commit/3e29d37be2b6cd98183fd643223f0070f55c913e has been reverted because the fix is not ideal and does not necessarily provide identical behavior since `document.hasFocus()` can still return false despite the synthesized events being successfully delivered into the unfocused target window.
Sam Sneddon [:gsnedders]
Comment 3 2025-02-11 10:46:10 PST
To directly link them together: this was reverted in https://commits.webkit.org/280262@main (https://github.com/WebKit/WebKit/pull/30014).
Sam Sneddon [:gsnedders]
Comment 4 2025-02-11 17:16:38 PST
This was then, soon after, fixed via a change in Safari — shipped in Safari 18.0.
Note You need to log in before you can comment on or make changes to this bug.