WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
202418
MouseEvent altKey property only changes on dragStart
https://bugs.webkit.org/show_bug.cgi?id=202418
Summary
MouseEvent altKey property only changes on dragStart
Jay C
Reported
2019-10-01 12:03:54 PDT
Created
attachment 379924
[details]
Screen recording of problem Safari Version 13.0.1 macOS Version 10.14.6 (18G95) While dragging a draggable element, `event.altKey` should change to true/false depending if I hold the option key on my Mac. In Firefox, I can start a drag, and then toggle the option key to see the altKey value change from false to true. I do not need to have the option key pressed before I start dragging. In Safari, I have to start the drag operation with option already held down in order for the MouseEvent's altKey property to be true. If I let go of the option key, the altKey value never changes. In Safari, if I start a drag event without holding the option key down, the MouseEvent's altKey property will never change. Here is a video logging out the value of altKey as I dragEnter and dragOver the items on the left. The item I am dragging has the following in its dragStart handler ``` e.dataTransfer.effectAllowed = 'copyMove' e.dataTransfer.dropEffect = 'move' ``` the item I am dropping on has the following events. e.altKey will *always* be false in webkit if I don't start the drag operation with option held down. It will *always* be true if I start the drag operation with option held down. ``` function dropHandler(e) { e.preventDefault() e.dataTransfer.effectAllowed = 'copyMove' ... // If we're copying if (e.altKey) { fieldCopyHandler(oldDocumentId, thisDocumentId, fieldId) } else { fieldMoveHandler(oldDocumentId, thisDocumentId, fieldId) } } function dragEnterHandler(e) { console.log(e.altKey) } function dragOverHandler(e) { console.log(e.altKey) } ``` I have attached a video
Attachments
Screen recording of problem
(34.95 MB, video/quicktime)
2019-10-01 12:03 PDT
,
Jay C
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Jay C
Comment 1
2019-10-01 12:12:52 PDT
I wrote out a long bug report when submitting this, but not seeing that text here so I will rewrite it (ugh). Problem: The MouseEvent's "altKey" property doesn't change when pressing/releasing the option key. Example: I have a set of list items that I can drag and drop, and another set of list items that can handle a drop. in the drag start handler for the items I can drag, I have set the dataTransfer effectAllowed value to "copyMove". in the drop Handler, dragEnter handler, and dragOver handler on the droppable list items, I am logging out the altKey property. If I start the drag operation with the option key held down, the altKey property will always be true, no matter if I release the key or not. If I start the drag operation without the option key held down, the altKey property will always be false, no matter what I do. I have attached a screen recording showing Firefox vs Safari
Radar WebKit Bug Importer
Comment 2
2019-10-02 08:03:56 PDT
<
rdar://problem/55909813
>
Jay C
Comment 3
2019-10-02 09:10:53 PDT
This may be related to
https://bugs.webkit.org/show_bug.cgi?id=101853
as I am seeing that as well with the same dropevent
Stefano Delli Ponti
Comment 4
2020-04-01 05:58:47 PDT
I confirm this bug also in Safari 13.1 and macOS 10.15.4. The problem has been present in Safari for at least three years, perhaps more. Unfortunately I don't remember the first version where it appeared, but I am sure it was not present at the beginning. Both Chrome and Firefox allow to discover the values of the modifier keys after starting dragging, keeping them updated if changed later. I think that a workaround can be to query the dataTransfer.effectAllowed, which is changed dynamically when toggling ctrl, alt or meta. Unfortunately I didn't find a way to query for the shiftKey status.
Nazar Chobaniuk
Comment 5
2026-08-12 10:01:12 PDT
Still reproducible in Safari 26.4 and Safari Technology Preview 27 (measured 2026-07), with real OS-level drag gestures (CGEvent-driven, so the modifier is held by the window server exactly as a hand holds it). Same behavior as
bug 77465
(2012). What we measured, altKey read off the drag events of one drag: - held from before dragstart: true for the whole drag (correct) - pressed mid-flight: stays false through the drop ~580 ms later (stale) - released mid-flight: stays true (stale) Two adjacent signals, same runs: - dataTransfer.effectAllowed is re-derived live on every drag event — it narrows to copy within ~3 ms of the key going down and widens back on release. So the engine tracks the key; only the event flags do not. It is the one live modifier signal on the event, and what we use as a workaround. - dropEffect reports none throughout, at dragover and drop alike, so it cannot substitute. Impact: a page deciding copy-vs-move from modifier flags mid-drag is wrong exactly when the user changes the modifier mid-drag. Drag-and-drop libraries that snapshot flags into their own payloads (for example pragmatic-drag-and-drop's input object) faithfully carry the stale value to every consumer. Disclosure: human posted; prepared with Claude (Fable) over multiple measurement sessions.
Nazar Chobaniuk
Comment 6
2026-08-12 14:24:26 PDT
Two further measurements, 2026-08-12, on Safari 26.4 and Safari Technology Preview 27. Method as in the previous comment: real OS-level drag gestures (CGEvent-driven), against an isolated page holding one draggable="true" element and a drop target whose only behavior is preventDefault on dragenter and dragover. 1. The stale value is not the state at dragstart. dragover and drop carry the last modifier state the engine observed outside a drag session. mousedown and dragstart carry the live state and are correct. The two disagree whenever a modifier is released during a drag, because that release is never observed. Reproduction: a. Hold Command, press the element, release Command halfway across, drop. metaKey reads true on dragover and drop. b. Start a second drag holding nothing at all. mousedown reads false and dragstart reads false, while every dragover and the drop read metaKey true. c. Press and release any modifier with no drag in progress, then drag again. metaKey reads false throughout. A page therefore reads a modifier as held on a drag during which the user pressed nothing, and the value survives every later drag until an unrelated keypress clears it. Nothing on the event distinguishes this case from a real press. 2. The engine tracks the key; only the event flags do not. In the mid-flight press case, one screen capture holds both facts at the same instant: WebKit paints the green copy badge on the drag image, and the page's own rendered readout of that same dragover reads altKey false with effectAllowed copy. The user is shown a copy operation while the page is told no modifier is down. Both measurements reproduce under an automated harness, so a fix has a mechanical check available. As in the previous comment: effectAllowed is the only live modifier signal on the event, and dropEffect reads none throughout, at dragover and drop alike. Disclosure: human reproduced (Safari 26.4 part) and posted; prepared with Claude (Opus).
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug