feat(locator): add drop API for files and clipboard-like data#40283
Merged
pavelfeldman merged 1 commit intomicrosoft:mainfrom Apr 17, 2026
Merged
feat(locator): add drop API for files and clipboard-like data#40283pavelfeldman merged 1 commit intomicrosoft:mainfrom
pavelfeldman merged 1 commit intomicrosoft:mainfrom
Conversation
Simulates an external OS/clipboard drag-and-drop of files and/or mime-typed string data onto a locator. Dispatches native DragEvents (dragenter, dragover, drop) with a DataTransfer constructed in the page's main world, so it works cross-browser and carries real file buffers — unlike the previous evaluateHandle + dispatchEvent workaround.
Contributor
Test results for "MCP"6096 passed, 976 skipped Merge workflow run. |
yury-s
approved these changes
Apr 17, 2026
| - `buffer` <[Buffer]> File content | ||
|
|
||
| ## drop-payload | ||
| - `payload` <[Object]> |
Contributor
Test results for "tests 1"6 flaky39242 passed, 847 skipped Merge workflow run. |
dgozman
reviewed
Apr 17, 2026
|
|
||
| Dispatches the native `dragenter`, `dragover`, and `drop` events at the center of the | ||
| target element with a synthetic [DataTransfer] carrying the provided files and/or data | ||
| entries. Works cross-browser by constructing the [DataTransfer] in the page context. |
Collaborator
There was a problem hiding this comment.
Suggested change
| entries. Works cross-browser by constructing the [DataTransfer] in the page context. | |
| entries. |
|
|
||
| **Details** | ||
|
|
||
| Dispatches the native `dragenter`, `dragover`, and `drop` events at the center of the |
Collaborator
There was a problem hiding this comment.
at the center is wrong when position is passed. I'd recommend inside the target element instead.
| } | ||
|
|
||
| async _drop(progress: Progress, inputFileItems: InputFilesItems, data: { mimeType: string, value: string }[], options: types.PointerActionWaitOptions): Promise<'error:notconnected' | 'done'> { | ||
| const { filePayloads, localPaths } = inputFileItems; |
Collaborator
There was a problem hiding this comment.
Why don't we reuse prepareFilesForUpload?
| const disposeHandle = handle !== this; | ||
| try { | ||
| const result = await progress.race(handle.evaluate((node: Node, { payloads, data, point }) => { | ||
| if (!node.isConnected || node.nodeType !== 1 /* ELEMENT_NODE */) |
Collaborator
There was a problem hiding this comment.
Can we please extract this large evaluated function into InjectedScript.drop()?
Comment on lines
+666
to
+682
| if (localPaths && !filePayloads) { | ||
| // Co-located server/browser: read files into buffers so File objects can be | ||
| // constructed in page context. | ||
| payloads = await Promise.all(localPaths.map(async p => ({ | ||
| name: path.basename(p), | ||
| mimeType: mime.getType(p) || 'application/octet-stream', | ||
| buffer: (await fs.promises.readFile(p)).toString('base64'), | ||
| lastModifiedMs: (await fs.promises.stat(p)).mtimeMs, | ||
| }))); | ||
| } else { | ||
| payloads = (filePayloads ?? []).map(p => ({ | ||
| name: p.name, | ||
| mimeType: p.mimeType || 'application/octet-stream', | ||
| buffer: p.buffer, | ||
| lastModifiedMs: p.lastModifiedMs, | ||
| })); | ||
| } |
Collaborator
There was a problem hiding this comment.
Can we instead force prepareFilesForUpload to read files into payloads right away?
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
locator.drop(payload, options?)that simulates an external OS/clipboard drop onto a target element, dispatching nativedragenter/dragover/dropevents with a realDataTransfer.payloadaccepts{ files?, data? }— files as paths orFilePayloadbuffers, data as a mime-type → string map.DataTransferin the page's main world so Firefox doesn't strip file content at the isolated-world boundary.dragoverhandler does not callpreventDefault().