From 339ff7fdf4f4778782193275e7f51712ec5f2cb2 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Fri, 3 Apr 2026 17:47:33 +0200 Subject: [PATCH] add screenshot capture module using desktopCapturer --- .../src/modules/autocomplete/screenshot.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 surfsense_desktop/src/modules/autocomplete/screenshot.ts diff --git a/surfsense_desktop/src/modules/autocomplete/screenshot.ts b/surfsense_desktop/src/modules/autocomplete/screenshot.ts new file mode 100644 index 000000000..22b7c1b14 --- /dev/null +++ b/surfsense_desktop/src/modules/autocomplete/screenshot.ts @@ -0,0 +1,27 @@ +import { desktopCapturer, screen } from 'electron'; + +/** + * Captures the primary display as a base64-encoded PNG data URL. + * Uses the display's actual size for full-resolution capture. + */ +export async function captureScreen(): Promise { + try { + const primaryDisplay = screen.getPrimaryDisplay(); + const { width, height } = primaryDisplay.size; + + const sources = await desktopCapturer.getSources({ + types: ['screen'], + thumbnailSize: { width, height }, + }); + + if (!sources.length) { + console.error('[screenshot] No screen sources found'); + return null; + } + + return sources[0].thumbnail.toDataURL(); + } catch (err) { + console.error('[screenshot] Failed to capture screen:', err); + return null; + } +}