Skip to content

drag leaks the source ElementHandle when the target uid lookup fails #2440

Closed

Description

@ch-bas

Description of the bug

The drag tool resolves both element handles before its try/finally:

// src/tools/input.ts, drag handler
const fromHandle = await request.page.getElementByUid(request.params.from_uid);
const toHandle   = await request.page.getElementByUid(request.params.to_uid); // can throw
try {
  ...drag...
} finally {
  void fromHandle.dispose();
  void toHandle.dispose();
}

If getElementByUid(to_uid) throws — which it does for a stale or invalid to_uid (Element uid "…" no longer exists on the page., Element uid "…" not found, or No snapshot found) — the try block is never entered, so the already-acquired fromHandle is never disposed. getElementByUid mints a fresh ElementHandle per call, so each failed drag leaks one remote object for the life of the page's execution context.

This is the same class of leak as the recently-fixed #2422 (take_screenshot). Among the multi-handle input tools, fill_form (via fillFormElement) already wraps each handle in try/finally, so drag is the only one affected.

Reproduction

  1. Take a snapshot to get element uids.
  2. Call drag with a valid from_uid and a to_uid that no longer resolves (e.g. the DOM changed since the snapshot, or a bad uid).
  3. getElementByUid(to_uid) throws; the call fails and fromHandle is leaked. Repeat → remote objects accumulate until page teardown.

Expectation

The source handle is disposed even when the target lookup fails, matching the other input handlers.

Fix: acquire toHandle inside a nested try so fromHandle is disposed on every path. I have this plus a regression test (spy fromHandle.dispose, force the target lookup to throw, assert dispose was still called) passing locally and can open a PR.

Chrome DevTools MCP version

main @ 574c320 (1.6.0)

Chrome version

n/a (independent of Chrome version)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions