Bug 233555 - File DnD event.dataTransfer.items.length is zero in dragenter, over events
Summary: File DnD event.dataTransfer.items.length is zero in dragenter, over events
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: Safari 14
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-11-29 05:44 PST by Vishnu
Modified: 2022-08-09 16:46 PDT (History)
6 users (show)

See Also:


Attachments
Issue with Safari (64.80 MB, video/mp4)
2021-11-29 05:44 PST, Vishnu
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vishnu 2021-11-29 05:44:21 PST
Created attachment 445271 [details]
Issue with Safari

The event.dataTransfer.items.length is showing 0 in dragenter and dragover event. Chrome and firefox shows the count of the dataTransferItems.


Reproduction steps
1. Open following link in safari https://codepen.io/rohinikumar4073/pen/poRWvEX?editors=1011
2. Drag and drop files in the red box
3. Observer logs
4. Trying in Chrome the issue is not present
Comment 1 Alexey Proskuryakov 2021-11-29 17:16:20 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.
Comment 2 Radar WebKit Bug Importer 2021-12-06 05:45:31 PST
<rdar://problem/86100318>
Comment 3 alexreardon 2022-08-09 16:46:43 PDT
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