Skip to content

dragAndDrop uses fragile manual mouse sequence — silently fails when elements shift or disappear #69

Description

@ANSHSINGH050404

Problem

src/tools.ts:511-534PlaywrightTools.dragAndDrop() uses a manual sequence:

sourceLocator.hover() → page.mouse.down() → targetLocator.hover() ×2 → page.mouse.up()

This has several issues:

  1. Layout-shift race: Between hover() and mouse.down(), the page could re-render, moving the element. mouse.down() fires at stale coordinates.
  2. No element-under-cursor check: If hover() succeeded but the element was already detached, mouse.down() silently presses at current position — nothing is actually grabbed.
  3. Double hover() on target (line 527-528) is a hack to force dragover events, suggesting the event dispatch is unreliable.
  4. Silent success: The method always returns { success: true } — any failure in the drag sequence is swallowed.
  5. No tests: tools.ts has zero test coverage (694 lines).

Suggested fix

Replace the manual sequence with Playwright's built-in locator.dragTo(target):

await sourceLocator.dragTo(targetLocator, { timeout: LOCATOR_ACTION_TIMEOUT });
Playwright's dragTo() handles correct event ordering (mousedown → mousemove → mouseup → dragstart → drag → dragenter → dragover → drop → dragend), cross-browser quirks, and throws on missing elements.
Impact
Reproducible in any test that uses the browser_drag_and_drop tool with dynamic content  e.g., drag-and-drop on a list that re-renders after the source hover.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions