Bug 275326
| Summary: | [WebDriver] If Safari window is not focused, WebDriver-automated mouse events do not get sent to the page | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Qianlang Chen <qianlangchen> |
| Component: | WebDriver | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED CONFIGURATION CHANGED | ||
| Severity: | Normal | CC: | bburg, webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
Qianlang Chen
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 | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
EWS
Committed 280047@main (3e29d37be2b6): <https://commits.webkit.org/280047@main>
Reviewed commits have been landed. Closing PR #29683 and removing active labels.
Qianlang Chen
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]
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]
This was then, soon after, fixed via a change in Safari — shipped in Safari 18.0.