Skip to content

Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.

fix(app): guard live screen socket against non-object payloads (#388)

Felix-Ayush4213cfd15c8d
diff --git a/app/src/components/computer/live-screen.tsx b/app/src/components/computer/live-screen.tsx
index bbc98938..37023112 100644
--- a/app/src/components/computer/live-screen.tsx
+++ b/app/src/components/computer/live-screen.tsx
@@ -64,18 +64,30 @@ export function LiveScreen({ computerId, driving, onProblem }: Props) {
};
socket.onmessage = async (event) => {
- let message: {
+ let parsed: unknown;
+ try {
+ parsed = JSON.parse(String(event.data));
+ } catch {
+ return;
+ }
+ // A frame that is not an object (`null`, a number, a string, an array) has
+ // no `type` to read: reaching for it throws a `TypeError` inside this
+ // handler and stops the live view from drawing further frames. Drop it.
+ if (
+ typeof parsed !== "object" ||
+ parsed === null ||
+ Array.isArray(parsed)
+ ) {
+ return;
+ }
+ const message = parsed as {
type: string;
data?: string;
width?: number;
height?: number;
error?: string;
};
- try {
- message = JSON.parse(String(event.data));
- } catch {
- return;
- }
+ if (typeof message.type !== "string") return;
if (message.type === "error") {
onProblem?.(message.error ?? "The screen could not be shown.");
return;