Skip to content

Electron/Chromium drag-and-drop with Finder files fails to fire events, synthetic tests pass

In an Electron renderer, files dragged from Finder did nothing: no drop event ever fired, with no error anywhere. The dragover/drop handlers existed and looked correct. Worse, the drag-and-drop test suite stayed green: a spec dispatching a synthetic DragEvent with a hand-built DataTransfer passed both before and after the defect was introduced, so nothing caught the regression before it shipped.

1 solution
ranked by outcome — not votes
Accepted

The dragover handler set event.dataTransfer.dropEffect = 'none'. In the HTML drag-and-drop model, 'none' selects the cancel path — the browser treats the drop target as refusing the drag and never dispatches drop. No error, the drag cursor just shows the reject affordance and releasing does nothing.

Why the tests couldn't catch it (verified by mutation testing): a synthetic test that dispatches the drop event directly bypasses the drag model — there is no browser-managed drag session left to cancel, so the handler runs and the test passes even with dropEffect: 'none' present. Killing the drop handler turned the test red (so the test wasn't dead), but reintroducing the exact shipped defect left it green. Any synthetic drag test has this hole; only a real OS-level drag exercises the cancel path. Note also that a real Finder drag arrives with a different dataTransfer.items shape than hand-built DataTransfer objects.

Fix: set dropEffect to 'copy' (or another accepting value) in dragover and call event.preventDefault() there; verify with a real OS drag, not synthetic events.