Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(desktop): capture a region of the app window (#107438)

Shy Altercfbd7a8ed0ee
diff --git a/products/desktop/apps/code/src/main/di/bindings.ts b/products/desktop/apps/code/src/main/di/bindings.ts
index d25246052dcf..cd3971b09994 100644
--- a/products/desktop/apps/code/src/main/di/bindings.ts
+++ b/products/desktop/apps/code/src/main/di/bindings.ts
@@ -135,6 +135,7 @@ import type { IMAGE_PROCESSOR_SERVICE } from "@posthog/platform/image-processor"
import type { MAIN_WINDOW_SERVICE } from "@posthog/platform/main-window";
import type { NOTIFIER_SERVICE } from "@posthog/platform/notifier";
import type { POWER_MANAGER_SERVICE } from "@posthog/platform/power-manager";
+import type { SCREEN_CAPTURE_SERVICE } from "@posthog/platform/screen-capture";
import type { SECURE_STORAGE_SERVICE } from "@posthog/platform/secure-storage";
import type {
ISettingsBackupFiles,
@@ -253,6 +254,7 @@ import type { ElectronMainWindow } from "../platform-adapters/electron-main-wind
import type { MissionControlService } from "../platform-adapters/electron-mission-control";
import type { ElectronNotifier } from "../platform-adapters/electron-notifier";
import type { ElectronPowerManager } from "../platform-adapters/electron-power-manager";
+import type { ElectronScreenCapture } from "../platform-adapters/electron-screen-capture";
import type { ElectronSecureStorage } from "../platform-adapters/electron-secure-storage";
import type { ElectronStoragePaths } from "../platform-adapters/electron-storage-paths";
import type { ElectronUpdater } from "../platform-adapters/electron-updater";
@@ -333,6 +335,7 @@ export interface MainBindings {
[SETTINGS_BACKUP_FILES]: ISettingsBackupFiles;
// Platform adapters
[URL_LAUNCHER_SERVICE]: ElectronUrlLauncher;
+ [SCREEN_CAPTURE_SERVICE]: ElectronScreenCapture;
[STORAGE_PATHS_SERVICE]: ElectronStoragePaths;
[APP_META_SERVICE]: ElectronAppMeta;
[DIALOG_SERVICE]: ElectronDialog;
diff --git a/products/desktop/apps/code/src/main/di/container.ts b/products/desktop/apps/code/src/main/di/container.ts
index 2b81f869b62a..6d82831840ac 100644
--- a/products/desktop/apps/code/src/main/di/container.ts
+++ b/products/desktop/apps/code/src/main/di/container.ts
@@ -121,6 +121,7 @@ import { IMAGE_PROCESSOR_SERVICE } from "@posthog/platform/image-processor";
import { MAIN_WINDOW_SERVICE } from "@posthog/platform/main-window";
import { NOTIFIER_SERVICE } from "@posthog/platform/notifier";
import { POWER_MANAGER_SERVICE } from "@posthog/platform/power-manager";
+import { SCREEN_CAPTURE_SERVICE } from "@posthog/platform/screen-capture";
import { SECURE_STORAGE_SERVICE } from "@posthog/platform/secure-storage";
import { STORAGE_PATHS_SERVICE } from "@posthog/platform/storage-paths";
import { UPDATER_SERVICE } from "@posthog/platform/updater";
@@ -254,6 +255,7 @@ import { ElectronMainWindow } from "../platform-adapters/electron-main-window";
import { MissionControlService } from "../platform-adapters/electron-mission-control";
import { ElectronNotifier } from "../platform-adapters/electron-notifier";
import { ElectronPowerManager } from "../platform-adapters/electron-power-manager";
+import { ElectronScreenCapture } from "../platform-adapters/electron-screen-capture";
import { ElectronSecureStorage } from "../platform-adapters/electron-secure-storage";
import { ElectronStoragePaths } from "../platform-adapters/electron-storage-paths";
import { ElectronUpdater } from "../platform-adapters/electron-updater";
@@ -352,6 +354,7 @@ export const container = new TypedContainer<MainBindings>({
});
container.bind(URL_LAUNCHER_SERVICE).to(ElectronUrlLauncher);
+container.bind(SCREEN_CAPTURE_SERVICE).to(ElectronScreenCapture);
container.bind(STORAGE_PATHS_SERVICE).to(ElectronStoragePaths);
container.bind(APP_META_SERVICE).to(ElectronAppMeta);
container.bind(DIALOG_SERVICE).to(ElectronDialog);
diff --git a/products/desktop/apps/code/src/main/platform-adapters/electron-screen-capture.test.ts b/products/desktop/apps/code/src/main/platform-adapters/electron-screen-capture.test.ts
new file mode 100644
index 000000000000..612d154478d7
--- /dev/null
+++ b/products/desktop/apps/code/src/main/platform-adapters/electron-screen-capture.test.ts
@@ -0,0 +1,129 @@
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+vi.mock("inversify", () => ({
+ injectable: () => (target: unknown) => target,
+ inject: () => () => undefined,
+}));
+
+import { ElectronScreenCapture } from "./electron-screen-capture";
+
+function image(width: number, height: number) {
+ const resize = vi.fn(
+ ({ width, height }: { width: number; height: number }) => ({
+ toDataURL: () => `data:image/png;${width}x${height}`,
+ }),
+ );
+ return {
+ isEmpty: () => false,
+ getSize: () => ({ width, height }),
+ resize,
+ toDataURL: () => `data:image/png;${width}x${height}`,
+ };
+}
+
+function makeCapture(
+ capturePage: (rect: unknown) => Promise<unknown>,
+ zoom = 1,
+ contentSize: [number, number] = [2_000, 5_000],
+) {
+ const webContents = {
+ capturePage: vi.fn(capturePage),
+ getZoomFactor: () => zoom,
+ };
+ const mainWindow = {
+ getBrowserWindow: () => ({
+ webContents,
+ getContentSize: () => contentSize,
+ }),
+ };
+ return {
+ capture: new ElectronScreenCapture(mainWindow as never),
+ webContents,
+ };
+}
+
+describe("ElectronScreenCapture.captureRegion", () => {
+ afterEach(() => {
+ vi.useRealTimers();
+ });
+
+ it("captures the region the page measured, at the window zoom", async () => {
+ const { capture, webContents } = makeCapture(
+ async () => image(600, 300),
+ 1.5,
+ );
+
+ await expect(
+ capture.captureRegion({ x: 10, y: 20, width: 400, height: 200 }),
+ ).resolves.toBe("data:image/png;600x300");
+ expect(webContents.capturePage).toHaveBeenCalledWith({
+ x: 15,
+ y: 30,
+ width: 600,
+ height: 300,
+ });
+ });
+
+ it.each([
+ ["a tall capture", 1_000, 4_000, "data:image/png;320x1280"],
+ ["a narrow tall capture", 1, 4_000, "data:image/png;1x1280"],
+ ])(
+ "scales %s so both sides fit and stay positive",
+ async (_name, width, height, expected) => {
+ const { capture } = makeCapture(async () => image(width, height));
+
+ await expect(
+ capture.captureRegion({ x: 0, y: 0, width, height }),
+ ).resolves.toBe(expected);
+ },
+ );
+
+ it("clips the region to the window before it captures", async () => {
+ const { capture, webContents } = makeCapture(
+ async () => image(200, 100),
+ 1,
+ [1_000, 700],
+ );
+
+ await capture.captureRegion({
+ x: 800,
+ y: 600,
+ width: 9_000,
+ height: 9_000,
+ });
+ expect(webContents.capturePage).toHaveBeenCalledWith({
+ x: 800,
+ y: 600,
+ width: 200,
+ height: 100,
+ });
+ });
+
+ it.each([
+ ["smaller than a pixel", { x: 10, y: 10, width: 0.2, height: 0.2 }],
+ ["outside the window", { x: 3_000, y: 10, width: 50, height: 50 }],
+ ])("never captures the whole page for a region %s", async (_name, region) => {
+ const { capture, webContents } = makeCapture(async () => image(1, 1));
+
+ await expect(capture.captureRegion(region)).resolves.toBeNull();
+ expect(webContents.capturePage).not.toHaveBeenCalled();
+ });
+
+ it.each([
+ ["the capture fails", () => Promise.reject(new Error("gone"))],
+ ["the capture never settles", () => new Promise(() => {})],
+ ])("gives no image when %s", async (_name, capturePage) => {
+ vi.useFakeTimers();
+ const { capture } = makeCapture(capturePage);
+
+ const pending = capture.captureRegion({
+ x: 0,
+ y: 0,
+ width: 10,
+ height: 10,
+ });
+ await vi.advanceTimersByTimeAsync(2_000);
+
+ await expect(pending).resolves.toBeNull();
+ });
+});
diff --git a/products/desktop/apps/code/src/main/platform-adapters/electron-screen-capture.ts b/products/desktop/apps/code/src/main/platform-adapters/electron-screen-capture.ts
new file mode 100644
index 000000000000..08d9d4e89136
--- /dev/null
+++ b/products/desktop/apps/code/src/main/platform-adapters/electron-screen-capture.ts
@@ -0,0 +1,64 @@
+import { MAIN_WINDOW_SERVICE } from "@posthog/platform/main-window";
+import type {
+ CaptureRegion,
+ IScreenCapture,
+} from "@posthog/platform/screen-capture";
+import { withTimeout } from "@posthog/shared";
+import { inject, injectable } from "inversify";
+import type { ElectronMainWindow } from "./electron-main-window";
+
+const CAPTURE_DEADLINE_MS = 2_000;
+const MAX_SIDE = 1_280;
+
+function clamp(value: number, limit: number): number {
+ return Math.min(Math.max(value, 0), limit);
+}
+
+@injectable()
+export class ElectronScreenCapture implements IScreenCapture {
+ public constructor(
+ @inject(MAIN_WINDOW_SERVICE)
+ private readonly mainWindow: ElectronMainWindow,
+ ) {}
+
+ public async captureRegion(region: CaptureRegion): Promise<string | null> {
+ const browserWindow = this.mainWindow.getBrowserWindow();
+ if (!browserWindow) return null;
+ const zoom = browserWindow.webContents.getZoomFactor();
+ const [contentWidth, contentHeight] = browserWindow.getContentSize();
+ const left = clamp(Math.round(region.x * zoom), contentWidth);
+ const top = clamp(Math.round(region.y * zoom), contentHeight);
+ const right = clamp(
+ Math.round((region.x + region.width) * zoom),
+ contentWidth,
+ );
+ const bottom = clamp(
+ Math.round((region.y + region.height) * zoom),
+ contentHeight,
+ );
+ if (right - left < 1 || bottom - top < 1) return null;
+ const capture = await withTimeout(
+ browserWindow.webContents.capturePage({
+ x: left,
+ y: top,
+ width: right - left,
+ height: bottom - top,
+ }),
+ CAPTURE_DEADLINE_MS,
+ ).catch(() => null);
+ if (!capture || capture.result === "timeout" || capture.value.isEmpty()) {
+ return null;
+ }
+ const image = capture.value;
+ const { width, height } = image.getSize();
+ const scale = Math.min(1, MAX_SIDE / width, MAX_SIDE / height);
+ const resized =
+ scale < 1
+ ? image.resize({
+ width: Math.max(1, Math.round(width * scale)),
+ height: Math.max(1, Math.round(height * scale)),
+ })
+ : image;
+ return resized.toDataURL();
+ }
+}
diff --git a/products/desktop/apps/code/src/main/trpc/router.ts b/products/desktop/apps/code/src/main/trpc/router.ts
index 018a0bfe11cc..8b32b0113263 100644
--- a/products/desktop/apps/code/src/main/trpc/router.ts
+++ b/products/desktop/apps/code/src/main/trpc/router.ts
@@ -43,6 +43,7 @@ import { piSessionRouter } from "@posthog/host-router/routers/pi-session.router"
import { processTrackingRouter } from "@posthog/host-router/routers/process-tracking.router";
import { provisioningRouter } from "@posthog/host-router/routers/provisioning.router";
import { releaseFeedRouter } from "@posthog/host-router/routers/release-feed.router";
+import { screenCaptureRouter } from "@posthog/host-router/routers/screen-capture.router";
import { secureStoreRouter } from "@posthog/host-router/routers/secure-store.router";
import { settingsBackupRouter } from "@posthog/host-router/routers/settings-backup.router";
import { shellRouter } from "@posthog/host-router/routers/shell.router";
@@ -86,6 +87,7 @@ export const trpcRouter = router({
encryption: encryptionRouter,
externalApps: externalAppsRouter,
feedbackContext: feedbackContextRouter,
+ screenCapture: screenCaptureRouter,
fileWatcher: fileWatcherRouter,
focus: focusRouter,
folders: foldersRouter,
diff --git a/products/desktop/apps/code/src/renderer/di/bindings.ts b/products/desktop/apps/code/src/renderer/di/bindings.ts
index 9ebd05d56cfb..e08ce9f3c1ee 100644
--- a/products/desktop/apps/code/src/renderer/di/bindings.ts
+++ b/products/desktop/apps/code/src/renderer/di/bindings.ts
@@ -173,6 +173,10 @@ import {
type INotifications,
NOTIFICATIONS_SERVICE,
} from "@posthog/platform/notifications";
+import type {
+ IScreenCapture,
+ SCREEN_CAPTURE_SERVICE,
+} from "@posthog/platform/screen-capture";
import type {
ISettingsBackupFiles,
SETTINGS_BACKUP_FILES,
@@ -310,6 +314,7 @@ export interface RendererBindings {
[TRPC_CLIENT]: TRPCClient<TrpcRouter>;
[HOST_TRPC_CLIENT]: HostTrpcClient;
[FEEDBACK_CONTEXT_SERVICE]: IFeedbackContext;
+ [SCREEN_CAPTURE_SERVICE]: IScreenCapture;
[UPDATES_CLIENT]: UpdatesClient;
[DEV_MODE_CLIENT]: DevModeClient;
[CONNECTIVITY_CLIENT]: ConnectivityClient;
diff --git a/products/desktop/apps/code/src/renderer/di/container.ts b/products/desktop/apps/code/src/renderer/di/container.ts
index 3f1fa7937dbc..e156f75c387d 100644
--- a/products/desktop/apps/code/src/renderer/di/container.ts
+++ b/products/desktop/apps/code/src/renderer/di/container.ts
@@ -94,6 +94,10 @@ import {
FEEDBACK_CONTEXT_SERVICE,
type IFeedbackContext,
} from "@posthog/platform/feedback-context";
+import {
+ type IScreenCapture,
+ SCREEN_CAPTURE_SERVICE,
+} from "@posthog/platform/screen-capture";
import {
BROWSER_TABS_CLIENT,
type BrowserTabsClient,
@@ -181,6 +185,10 @@ container.bind<TRPCClient<TrpcRouter>>(TRPC_CLIENT).toConstantValue(trpcClient);
container.bind(HOST_TRPC_CLIENT).toConstantValue(hostTrpcClient);
+container.bind(SCREEN_CAPTURE_SERVICE).toConstantValue({
+ captureRegion: (region) =>
+ hostTrpcClient.screenCapture.captureRegion.query(region),
+} satisfies IScreenCapture);
container.bind(FEEDBACK_CONTEXT_SERVICE).toConstantValue({
captureScreenshot: () =>
hostTrpcClient.feedbackContext.captureScreenshot.query(),
diff --git a/products/desktop/packages/host-router/src/router.ts b/products/desktop/packages/host-router/src/router.ts
index ace126ca631e..4103928051ed 100644
--- a/products/desktop/packages/host-router/src/router.ts
+++ b/products/desktop/packages/host-router/src/router.ts
@@ -42,6 +42,7 @@ import { piSessionRouter } from "./routers/pi-session.router";
import { processTrackingRouter } from "./routers/process-tracking.router";
import { provisioningRouter } from "./routers/provisioning.router";
import { releaseFeedRouter } from "./routers/release-feed.router";
+import { screenCaptureRouter } from "./routers/screen-capture.router";
import { secureStoreRouter } from "./routers/secure-store.router";
import { settingsBackupRouter } from "./routers/settings-backup.router";
import { shellRouter } from "./routers/shell.router";
@@ -77,6 +78,7 @@ export const hostRouter = router({
environment: environmentRouter,
externalApps: externalAppsRouter,
feedbackContext: feedbackContextRouter,
+ screenCapture: screenCaptureRouter,
fileWatcher: fileWatcherRouter,
focus: focusRouter,
folders: foldersRouter,
diff --git a/products/desktop/packages/host-router/src/routers/screen-capture.router.ts b/products/desktop/packages/host-router/src/routers/screen-capture.router.ts
new file mode 100644
index 000000000000..e4bd1152188f
--- /dev/null
+++ b/products/desktop/packages/host-router/src/routers/screen-capture.router.ts
@@ -0,0 +1,24 @@
+import { publicProcedure, router } from "@posthog/host-trpc/trpc";
+import {
+ type IScreenCapture,
+ SCREEN_CAPTURE_SERVICE,
+} from "@posthog/platform/screen-capture";
+import { z } from "zod";
+
+const regionInput = z.object({
+ x: z.number().finite().min(0),
+ y: z.number().finite().min(0),
+ width: z.number().finite().positive().max(10_000),
+ height: z.number().finite().positive().max(10_000),
+});
+
+export const screenCaptureRouter = router({
+ captureRegion: publicProcedure
+ .input(regionInput)
+ .output(z.string().max(12_000_000).nullable())
+ .query(({ ctx, input }) =>
+ ctx.container
+ .get<IScreenCapture>(SCREEN_CAPTURE_SERVICE)
+ .captureRegion(input),
+ ),
+});
diff --git a/products/desktop/packages/platform/package.json b/products/desktop/packages/platform/package.json
index 763fcff19d77..7d514f89e2fa 100644
--- a/products/desktop/packages/platform/package.json
+++ b/products/desktop/packages/platform/package.json
@@ -80,6 +80,10 @@
"types": "./dist/bundled-resources.d.ts",
"import": "./dist/bundled-resources.js"
},
+ "./screen-capture": {
+ "types": "./dist/screen-capture.d.ts",
+ "import": "./dist/screen-capture.js"
+ },
"./image-processor": {
"types": "./dist/image-processor.d.ts",
"import": "./dist/image-processor.js"
diff --git a/products/desktop/packages/platform/src/screen-capture.ts b/products/desktop/packages/platform/src/screen-capture.ts
new file mode 100644
index 000000000000..7082252e238f
--- /dev/null
+++ b/products/desktop/packages/platform/src/screen-capture.ts
@@ -0,0 +1,14 @@
+export interface CaptureRegion {
+ x: number;
+ y: number;
+ width: number;
+ height: number;
+}
+
+export interface IScreenCapture {
+ captureRegion(region: CaptureRegion): Promise<string | null>;
+}
+
+export const SCREEN_CAPTURE_SERVICE = Symbol.for(
+ "posthog.platform.screenCapture",
+);
diff --git a/products/desktop/packages/platform/tsup.config.ts b/products/desktop/packages/platform/tsup.config.ts
index 8dbea961439d..db28e1346596 100644
--- a/products/desktop/packages/platform/tsup.config.ts
+++ b/products/desktop/packages/platform/tsup.config.ts
@@ -29,6 +29,7 @@ export default defineConfig({
"src/app-metrics.ts",
"src/dev-host-actions.ts",
"src/disk-cache.ts",
+ "src/screen-capture.ts",
],
format: ["esm"],
dts: true,
diff --git a/products/desktop/packages/shared/package.json b/products/desktop/packages/shared/package.json
index 138a182f68cb..942b00ffe5cb 100644
--- a/products/desktop/packages/shared/package.json
+++ b/products/desktop/packages/shared/package.json
@@ -56,6 +56,10 @@
"types": "./dist/mcp-sandbox-proxy.d.ts",
"import": "./dist/mcp-sandbox-proxy.js"
},
+ "./screenshot-area": {
+ "types": "./dist/screenshot-area.d.ts",
+ "import": "./dist/screenshot-area.js"
+ },
"./rich-output-prompt": {
"types": "./dist/rich-output-prompt.d.ts",
"import": "./dist/rich-output-prompt.js"
diff --git a/products/desktop/packages/shared/src/screenshot-area.test.ts b/products/desktop/packages/shared/src/screenshot-area.test.ts
new file mode 100644
index 000000000000..b7d790c3b8ab
--- /dev/null
+++ b/products/desktop/packages/shared/src/screenshot-area.test.ts
@@ -0,0 +1,65 @@
+import { describe, expect, it } from "vitest";
+import { screenshotArea } from "./screenshot-area";
+
+function rect(left: number, top: number, width: number, height: number) {
+ return {
+ left,
+ top,
+ width,
+ height,
+ right: left + width,
+ bottom: top + height,
+ };
+}
+
+describe("screenshotArea", () => {
+ it.each([
+ {
+ name: "a small element in the middle gets room around it",
+ element: rect(500, 400, 40, 20),
+ expected: { x: 340, y: 300, width: 360, height: 220 },
+ },
+ {
+ name: "an element at the top left corner stays inside the page",
+ element: rect(0, 0, 100, 30),
+ expected: { x: 0, y: 0, width: 360, height: 222 },
+ },
+ {
+ name: "a wide element that ends near the left edge keeps a small area",
+ element: rect(-10_000, 400, 10_020, 20),
+ expected: { x: 0, y: 300, width: 360, height: 220 },
+ },
+ {
+ name: "an element bigger than the page is cut to the page",
+ element: rect(-50, -50, 2_000, 2_000),
+ expected: { x: 0, y: 0, width: 1200, height: 800 },
+ },
+ ])("$name", ({ element, expected }) => {
+ expect(screenshotArea(element, { width: 1200, height: 800 })).toEqual(
+ expected,
+ );
+ });
+
+ it.each([
+ { name: "a hidden webview", element: rect(0, 0, 10, 10), width: 0 },
+ {
+ name: "an element right of the page",
+ element: rect(1300, 400, 40, 20),
+ width: 1200,
+ },
+ {
+ name: "an element above the page",
+ element: rect(500, -80, 40, 20),
+ width: 1200,
+ },
+ {
+ name: "an element with a missing position",
+ element: rect(Number.NaN, 400, 40, 20),
+ width: 1200,
+ },
+ ])("gives no area for $name", ({ element, width }) => {
+ expect(
+ screenshotArea(element, { width, height: width === 0 ? 0 : 800 }),
+ ).toBeNull();
+ });
+});
diff --git a/products/desktop/packages/shared/src/screenshot-area.ts b/products/desktop/packages/shared/src/screenshot-area.ts
new file mode 100644
index 000000000000..07a1feb9eeca
--- /dev/null
+++ b/products/desktop/packages/shared/src/screenshot-area.ts
@@ -0,0 +1,76 @@
+const MARGIN = 96;
+const MIN_WIDTH = 360;
+const MIN_HEIGHT = 220;
+
+export type ScreenshotArea = {
+ x: number;
+ y: number;
+ width: number;
+ height: number;
+};
+
+function span(
+ start: number,
+ end: number,
+ minimum: number,
+ limit: number,
+): [number, number] {
+ let from = start - MARGIN;
+ let to = end + MARGIN;
+ const missing = minimum - (to - from);
+ if (missing > 0) {
+ from -= missing / 2;
+ to += missing / 2;
+ }
+ if (from < 0) {
+ to -= from;
+ from = 0;
+ }
+ if (to > limit) {
+ from = Math.max(0, from - (to - limit));
+ to = limit;
+ }
+ return [Math.round(from), Math.round(to)];
+}
+
+export type ScreenshotTarget = {
+ top: number;
+ left: number;
+ right: number;
+ bottom: number;
+};
+
+export function screenshotArea(
+ element: ScreenshotTarget,
+ viewport: { width: number; height: number },
+): ScreenshotArea | null {
+ const values = [
+ element.left,
+ element.right,
+ element.top,
+ element.bottom,
+ viewport.width,
+ viewport.height,
+ ];
+ if (!values.every(Number.isFinite)) return null;
+ if (viewport.width <= 0 || viewport.height <= 0) return null;
+ const visibleLeft = Math.max(0, element.left);
+ const visibleRight = Math.min(viewport.width, element.right);
+ const visibleTop = Math.max(0, element.top);
+ const visibleBottom = Math.min(viewport.height, element.bottom);
+ if (visibleRight <= visibleLeft || visibleBottom <= visibleTop) return null;
+ const [left, right] = span(
+ visibleLeft,
+ visibleRight,
+ MIN_WIDTH,
+ viewport.width,
+ );
+ const [top, bottom] = span(
+ visibleTop,
+ visibleBottom,
+ MIN_HEIGHT,
+ viewport.height,
+ );
+ if (right - left <= 0 || bottom - top <= 0) return null;
+ return { x: left, y: top, width: right - left, height: bottom - top };
+}
diff --git a/products/desktop/packages/shared/tsup.config.ts b/products/desktop/packages/shared/tsup.config.ts
index 4444bc82ba5b..852f1c40517c 100644
--- a/products/desktop/packages/shared/tsup.config.ts
+++ b/products/desktop/packages/shared/tsup.config.ts
@@ -16,6 +16,7 @@ export default defineConfig({
"src/posthog-property-headers.ts",
"src/product-engineer-prompt.ts",
"src/rich-output-prompt.ts",
+ "src/screenshot-area.ts",
"src/task-context.ts",
"src/types.ts",
],