cdp: add Input.setInterceptDrags and Input.dispatchDragEvent

Merged
JA
12d ago
+467-1

Part of #4186.

Playwright sends Input.setInterceptDrags around every mouse move made with the left button down, so this failed with 'Input.setInterceptDrags' wasn't found, and locator.dragTo() timed out:

await page.mouse.move(10, 20)
await page.mouse.down()
await page.mouse.move(150, 20)
  • Input.setInterceptDrags stores the flag. Mouse input doesn't start a native drag yet, so no Input.dragIntercepted is sent, as in Chrome when the press isn't on a draggable element. The script above now works and the page gets pointermove/mousemove with buttons=1.
  • Input.dispatchDragEvent drives a drag from outside the page, as Puppeteer's mouse.dragEnter/dragOver/drop do. As in Chrome, dragEnter, dragOver and drop each run one step: dragenter (and dragleave on the old target) on a new target, dragover on the same one. A drop then fires drop if that step accepted the drag with an operation the source allows, else dragleave if the page called preventDefault(), else nothing. dragCancel fires nothing and ends the drag. Each event gets a DataTransfer built from data.items, protected for everything but drop, with effectAllowed and dropEffect from dragOperationsMask. DataTransfer gets the drag data store mode for this. data.files isn't handled.

As discussed in #4186, drags that start inside the page (dragstart from mouse input, Input.dragIntercepted, the non-intercepted mouse-driven drag, dragend on the source) are left for a follow-up.

Tests: five new cdp.input tests (setInterceptDrags with a held button; dispatchDragEvent enter/move/drop, a drop running its step first, a drop nobody accepted, dragCancel ending the drag). make test: 2069 of 2069.