Input.dispatchMouseEvent() doesn't wait for mouse event to be processed before returning
Categories
(Remote Protocol :: CDP, defect, P3)
Tracking
(firefox96 fixed)
| Tracking | Status | |
|---|---|---|
| firefox96 | --- | fixed |
People
(Reporter: whimboo, Assigned: whimboo)
References
Details
Attachments
(3 files)
There is a problem with the Input.dispatchMouseEvent() method. It returns too early and as such a next command might race because a result as expected to be set by the page's click event handler isn't present yet.
When we trigger the click via EventUtils.synthesizeMouse() we do not wait until it actually has been processes by a possible event listener on that page. An example can be seen here:
https://treeherder.mozilla.org/logviewer?job_id=357808344&repo=try&lineNumber=1264-1274
[task 2021-11-11T20:48:39.996Z] PID 423 | 1636663719987 CDP TRACE CDPConnection {4d6e0301-4bed-4e08-8b6c-620f9f5bcde0} -> {"sessionId":"6625c662-2a7e-4450-8290-1e30ffc8a430","method":"Input.dispatchMouseEvent","params":{"type":"mouseReleased","button":"left","x":50,"y":19.5,"modifiers":0,"clickCount":1},"id":197}
[task 2021-11-11T20:48:39.996Z] PID 423 |
[task 2021-11-11T20:48:39.996Z] PID 423 | *** ownerglobal: [object Window]
[task 2021-11-11T20:48:39.997Z] PID 423 |
[task 2021-11-11T20:48:39.997Z] PID 423 | *** Received event: mouseup
[task 2021-11-11T20:48:39.998Z] PID 423 | 1636663719988 CDP TRACE CDPConnection {4d6e0301-4bed-4e08-8b6c-620f9f5bcde0} <- {"id":197,"result":{},"sessionId":"6625c662-2a7e-4450-8290-1e30ffc8a430"}
[task 2021-11-11T20:48:39.998Z] PID 423 | 1636663719988 CDP TRACE CDPConnection {4d6e0301-4bed-4e08-8b6c-620f9f5bcde0} <- {"method":"Target.receivedMessageFromTarget","params":{"sessionId":"6625c662-2a7e-4450-8290-1e30ffc8a430","message":"{\"id\":197,\"result\":{}}"}}
[task 2021-11-11T20:48:39.998Z] PID 423 | 1636663719989 CDP TRACE CDPConnection {4d6e0301-4bed-4e08-8b6c-620f9f5bcde0} -> {"sessionId":"6625c662-2a7e-4450-8290-1e30ffc8a430","method":"Runtime.callFunctionOn","params":{"functionDeclaration":"() => ... tion_script__\n","executionContextId":3,"arguments":[],"returnByValue":true,"awaitPromise":true,"userGesture":true},"id":198}
[task 2021-11-11T20:48:39.998Z] PID 423 |
[task 2021-11-11T20:48:39.998Z] PID 423 | ** button was clicked - updating result
[task 2021-11-11T20:48:39.998Z] PID 423 | 1636663719993 CDP TRACE CDPConnection {4d6e0301-4bed-4e08-8b6c-620f9f5bcde0} <- {"id":198,"result":{"result":{"type":"string","value":"Was not clicked","description":"Was not clicked"}},"sessionId":"6625c662-2a7e-4450-8290-1e30ffc8a430"}
This will fix a couple of Puppeteer tests.
| Assignee | ||
Comment 1•4 years ago
|
||
Given our code in Input.dispatchMouseEvent() we call EventUtils.synthesizeMouse() on the browser element with the appropriate coordinates but not on the element itself.
To fix that I registered an event listener for mousedown and mouseup on the ownerGlobal, and wrapped that finally inside a Promise. While that code now awaits at least for the event to happen it still returns before the page's onclick event handler has been processed. I wonder if there is a way to further delay it with some option. If that's not possible we might have to identify the specific node at the given position and attach the listener directly.
| Assignee | ||
Comment 2•4 years ago
|
||
Depends on D131211
| Assignee | ||
Comment 3•4 years ago
|
||
Once landed and available in Nightly I'll have to re-enable affected tests upstream. See: https://github.com/puppeteer/puppeteer/issues/7175
| Assignee | ||
Comment 4•4 years ago
|
||
Comment 6•4 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/26d9f747b14f
https://hg.mozilla.org/mozilla-central/rev/aee80b16c695
| Assignee | ||
Comment 7•4 years ago
|
||
Looks like I forgot to update the Puppeteer expectation data for the following test:
I'll add a follow-up patch to this bug on Thursday.
| Assignee | ||
Comment 8•4 years ago
|
||
| Assignee | ||
Comment 9•4 years ago
|
||
I've created an upstream PR for re-enabling the tests at: https://github.com/puppeteer/puppeteer/pull/7776
Comment 10•4 years ago
|
||
Comment 11•4 years ago
|
||
| bugherder | ||
| Assignee | ||
Comment 12•4 years ago
|
||
Upstream PR got merged.
Description
•