| Summary: | File DnD event.dataTransfer.items.length is zero in dragenter, over events | ||||||
|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Vishnu <visu.rohini> | ||||
| Component: | UI Events | Assignee: | Nobody <webkit-unassigned> | ||||
| Status: | NEW --- | ||||||
| Severity: | Normal | CC: | alexreardon, ap, bfulgham, graouts, webkit-bug-importer, wenson_hsieh | ||||
| Priority: | P2 | Keywords: | InRadar | ||||
| Version: | Safari 14 | ||||||
| Hardware: | Unspecified | ||||||
| OS: | Unspecified | ||||||
| Attachments: |
|
||||||
|
Description
Vishnu
2021-11-29 05:44:21 PST
I think that this may be intentional, to prevent web content from sniffing content that is simply dragged over, not intended for it. Not sure though. From the spec: > A drag data store mode, which is one of the following: > *Read/write mode* > For the dragstart event. New data can be added to the drag data store. > *Read-only mode* > For the drop event. The list of items representing dragged data can be read, including the data. No new data can be added. > *Protected mode* > For all other events. The formats and kinds in the drag data store list of items representing dragged data can be enumerated, but the data itself is unavailable and no new data can be added. https://html.spec.whatwg.org/multipage/dnd.html#the-drag-data-store During all drag events other than "dragstart" and "drop" the drag data store (`event.dataTransfer?.items`) should be in *protected mode*. In protected mode, "The formats and kinds in the drag data store list of items representing dragged data can be enumerated, but the data itself is unavailable and no new data can be added.". In Chrome and Firefox, `items` behave according to the spec. However, in Safari, `items` cannot be enumerated. This is problematic for file dragging. For file drag operations, there is no "dragstart" event. So in Safari there is no way to know how many files are being dragged until a "drop" event Reproducible example: https://codesandbox.io/s/file-drag-and-drop-for-webkit-issue-s94jk1?file=/src/index.ts |