macOS: forward Finder drops through WKWebView - #12
Merged
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WKContentViewreceives Finder drag events before theWKWebViewsubclass. The subclass hooks therefore do not run, and the page does not receiveDataTransfer.files.This change:
dropevents remain active;Tests
MIX_ENV=test NO_WX=1 mix test --exclude e2eMIX_ENV=test NO_WX=1 mix test.e2e./scripts/build_macos.shNote
Medium Risk
Relies on runtime method swizzling and private WebKit view class names, which can break on OS/WebKit updates and is harder to validate automatically than public APIs.
Overview
Finder drag-and-drop into the webview was ineffective because WebKit’s internal
WKContentView/WKViewhandles drags beforeFileDropWebViewoverrides run, so pages never gotDataTransfer.files.FileDropWebViewnow discovers those private subviews, registers file URL and file-promise pasteboard types on them, and installs a one-timeFileDropBridgevia Objective-C runtime swizzling. The bridge delegates to WebKit’s saved implementations while OR-ing in file-drop acceptance (including.copywhen WebKit would return no operation). Installation runs on init and again inviewDidMoveToWindow(plus an async pass) sowebview.rebuildstill picks up the bridge.Docs note the private drag bridge; the
file_input.htmlfixture gains a#drop-targetdrop zone, and the shared E2E asserts that element is present (actual Finder drops remain manual).Reviewed by Cursor Bugbot for commit b6a20b4. Configure here.