Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(chat): image paste now works reliably

Louis Beaumont33b5d0ac2d9c
diff --git a/screenpipe-app-tauri/components/standalone-chat.tsx b/screenpipe-app-tauri/components/standalone-chat.tsx
index e1a5d3722..4f5c39385 100644
--- a/screenpipe-app-tauri/components/standalone-chat.tsx
+++ b/screenpipe-app-tauri/components/standalone-chat.tsx
@@ -169,22 +169,42 @@ export function StandaloneChat() {
// Handle paste events to capture images
const handlePaste = useCallback((e: React.ClipboardEvent) => {
const items = e.clipboardData?.items;
- if (!items) return;
-
- for (let i = 0; i < items.length; i++) {
- const item = items[i];
- if (item.type.startsWith("image/")) {
- e.preventDefault();
- const file = item.getAsFile();
- if (file) {
+ const files = e.clipboardData?.files;
+
+ // Try items first (works in most browsers)
+ if (items) {
+ for (let i = 0; i < items.length; i++) {
+ const item = items[i];
+ if (item.type.startsWith("image/")) {
+ e.preventDefault();
+ const file = item.getAsFile();
+ if (file) {
+ const reader = new FileReader();
+ reader.onload = (event) => {
+ const base64 = event.target?.result as string;
+ setPastedImage(base64);
+ };
+ reader.readAsDataURL(file);
+ }
+ return;
+ }
+ }
+ }
+
+ // Fallback: try files array (some browsers put images here)
+ if (files && files.length > 0) {
+ for (let i = 0; i < files.length; i++) {
+ const file = files[i];
+ if (file.type.startsWith("image/")) {
+ e.preventDefault();
const reader = new FileReader();
reader.onload = (event) => {
const base64 = event.target?.result as string;
setPastedImage(base64);
};
reader.readAsDataURL(file);
+ return;
}
- break; // Only handle first image
}
}
}, []);
@@ -1170,7 +1190,7 @@ export function StandaloneChat() {
</div>
)}
- <form onSubmit={handleSubmit} className="p-3">
+ <form onSubmit={handleSubmit} className="p-3" onPaste={handlePaste}>
<div className="flex gap-2">
<div className="relative flex-1">
<Input
@@ -1178,7 +1198,6 @@ export function StandaloneChat() {
value={input}
onChange={handleInputChange}
onKeyDown={handleKeyDown}
- onPaste={handlePaste}
placeholder={
disabledReason
? disabledReason