Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
fix: preserve text in mixed image clipboard payloads
Emre Sokullu25d9f9e7aba7
diff --git a/src/chrome/src/ui/attachment-drop.js b/src/chrome/src/ui/attachment-drop.jsindex d771b5614..aafc70f49 100644--- a/src/chrome/src/ui/attachment-drop.js+++ b/src/chrome/src/ui/attachment-drop.js@@ -23,13 +23,19 @@ export function clipboardImageFiles(event) {));}+function clipboardHasText(clipboardData) {+ return Array.from(clipboardData?.types || []).some(type => (+ type === 'text/plain' || type === 'text/html'+ ));+}+export function installClipboardImagePasteHandler(target, onFiles) {if (!target?.addEventListener || typeof onFiles !== 'function') return () => {};const onPaste = (event) => {const files = clipboardImageFiles(event);if (!files.length) return;- event.preventDefault();+ if (!clipboardHasText(event?.clipboardData)) event.preventDefault();onFiles(files);};diff --git a/src/firefox/src/ui/attachment-drop.js b/src/firefox/src/ui/attachment-drop.jsindex d771b5614..aafc70f49 100644--- a/src/firefox/src/ui/attachment-drop.js+++ b/src/firefox/src/ui/attachment-drop.js@@ -23,13 +23,19 @@ export function clipboardImageFiles(event) {));}+function clipboardHasText(clipboardData) {+ return Array.from(clipboardData?.types || []).some(type => (+ type === 'text/plain' || type === 'text/html'+ ));+}+export function installClipboardImagePasteHandler(target, onFiles) {if (!target?.addEventListener || typeof onFiles !== 'function') return () => {};const onPaste = (event) => {const files = clipboardImageFiles(event);if (!files.length) return;- event.preventDefault();+ if (!clipboardHasText(event?.clipboardData)) event.preventDefault();onFiles(files);};diff --git a/test/attachment-drop.mjs b/test/attachment-drop.mjsindex 45f1387f7..2bdf5aeb1 100644--- a/test/attachment-drop.mjs+++ b/test/attachment-drop.mjs@@ -287,10 +287,17 @@ for (const [label, relativeModule] of implementations) {clipboardData: { files: [pastedImage] },});assert.equal(imagePaste.defaultPrevented, true, `${label}: image paste should be consumed as an attachment`);- assert.deepEqual(pasted, [[pastedImage]], `${label}: image paste should forward clipboard files to the attachment reader`);+ const mixedPaste = pasteTarget.dispatch('paste', null, {+ clipboardData: {+ files: [pastedImage],+ types: ['text/plain', 'image/png'],+ },+ });+ assert.equal(mixedPaste.defaultPrevented, false, `${label}: mixed text+image paste should preserve native text insertion`);+ assert.deepEqual(pasted, [[pastedImage], [pastedImage]], `${label}: image paste should forward clipboard files to the attachment reader`);cleanupPaste();pasteTarget.dispatch('paste', null, { clipboardData: { files: [pastedImage] } });- assert.deepEqual(pasted, [[pastedImage]], `${label}: paste cleanup should remove its listener`);+ assert.deepEqual(pasted, [[pastedImage], [pastedImage]], `${label}: paste cleanup should remove its listener`);}console.log('attachment drag-and-drop tests passed for Chrome and Firefox');