Closed Bug 1740798 Opened 4 years ago Closed 4 years ago

Input.dispatchMouseEvent() doesn't wait for mouse event to be processed before returning

Categories

(Remote Protocol :: CDP, defect, P3)

defect

Tracking

(firefox96 fixed)

RESOLVED FIXED
96 Branch
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.

Blocks: 1719528

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.

Once landed and available in Nightly I'll have to re-enable affected tests upstream. See: https://github.com/puppeteer/puppeteer/issues/7175

Pushed by hskupin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/26d9f747b14f [remote] Await the mouse event before returning from Input.dispatchMouseEvent(). r=webdriver-reviewers,jdescottes https://hg.mozilla.org/integration/autoland/rev/aee80b16c695 [puppeteer] Update expected meta data. r=webdriver-reviewers,jdescottes
Regressions: 1741440
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 96 Branch
Blocks: 1642771

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.

I've created an upstream PR for re-enabling the tests at: https://github.com/puppeteer/puppeteer/pull/7776

Pushed by hskupin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/20d9468462ff [puppeteer] Remove multiple results from test "Page.click should click the button". r=webdriver-reviewers,jgraham

Upstream PR got merged.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: