Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

feat: add live screencast in profile details modal

Bosch02d7f8a2bea9
diff --git a/dashboard/src/components/molecules/ProfileDetailsModal.tsx b/dashboard/src/components/molecules/ProfileDetailsModal.tsx
index 1ae0e9a7..0fa370cc 100644
--- a/dashboard/src/components/molecules/ProfileDetailsModal.tsx
+++ b/dashboard/src/components/molecules/ProfileDetailsModal.tsx
@@ -1,5 +1,6 @@
import { useState, useEffect, useCallback } from 'react'
import { Modal, Button, Input } from '../atoms'
+import ScreencastTile from './ScreencastTile'
import type { Profile, Instance, InstanceTab, Agent } from '../../generated/types'
import * as api from '../../services/api'
@@ -183,7 +184,7 @@ export default function ProfileDetailsModal({
{activeTab === 'live' && (
<div>
- {isRunning ? (
+ {isRunning && instance ? (
<div>
<div className="mb-3 flex items-center justify-between">
<span className="text-sm text-text-muted">{tabs.length} tab(s)</span>
@@ -198,15 +199,13 @@ export default function ProfileDetailsModal({
) : (
<div className="grid gap-3 sm:grid-cols-2">
{tabs.map((tab) => (
- <div
+ <ScreencastTile
key={tab.id}
- className="rounded border border-border-subtle bg-bg-elevated p-3"
- >
- <div className="truncate text-sm font-medium text-text-primary">
- {tab.title || 'Untitled'}
- </div>
- <div className="truncate text-xs text-text-muted">{tab.url}</div>
- </div>
+ instanceId={instance.id}
+ tabId={tab.id}
+ label={tab.title?.slice(0, 20) || tab.id.slice(0, 8)}
+ url={tab.url}
+ />
))}
</div>
)}
diff --git a/dashboard/src/components/molecules/ScreencastTile.tsx b/dashboard/src/components/molecules/ScreencastTile.tsx
new file mode 100644
index 00000000..a1122e15
--- /dev/null
+++ b/dashboard/src/components/molecules/ScreencastTile.tsx
@@ -0,0 +1,128 @@
+import { useEffect, useRef, useState } from 'react'
+
+interface Props {
+ instanceId: string
+ tabId: string
+ label: string
+ url: string
+ quality?: number
+ maxWidth?: number
+ fps?: number
+}
+
+type Status = 'connecting' | 'streaming' | 'error'
+
+export default function ScreencastTile({
+ instanceId,
+ tabId,
+ label,
+ url,
+ quality = 30,
+ maxWidth = 800,
+ fps = 1,
+}: Props) {
+ const canvasRef = useRef<HTMLCanvasElement>(null)
+ const socketRef = useRef<WebSocket | null>(null)
+ const [status, setStatus] = useState<Status>('connecting')
+ const [fpsDisplay, setFpsDisplay] = useState('—')
+ const [sizeDisplay, setSizeDisplay] = useState('—')
+
+ useEffect(() => {
+ const canvas = canvasRef.current
+ if (!canvas) return
+
+ const ctx = canvas.getContext('2d')
+ if (!ctx) return
+
+ // Connect to screencast WebSocket
+ const wsProto = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
+ const wsUrl = `${wsProto}//${window.location.host}/instances/${instanceId}/screencast?tabId=${encodeURIComponent(tabId)}&quality=${quality}&maxWidth=${maxWidth}&fps=${fps}`
+
+ const socket = new WebSocket(wsUrl)
+ socket.binaryType = 'arraybuffer'
+ socketRef.current = socket
+
+ let frameCount = 0
+ let lastFpsTime = Date.now()
+
+ socket.onopen = () => {
+ setStatus('streaming')
+ }
+
+ socket.onmessage = (evt) => {
+ const blob = new Blob([evt.data], { type: 'image/jpeg' })
+ const imgUrl = URL.createObjectURL(blob)
+ const img = new Image()
+ img.onload = () => {
+ canvas.width = img.width
+ canvas.height = img.height
+ ctx.drawImage(img, 0, 0)
+ URL.revokeObjectURL(imgUrl)
+ }
+ img.src = imgUrl
+
+ frameCount++
+ const now = Date.now()
+ if (now - lastFpsTime >= 1000) {
+ setFpsDisplay(`${frameCount} fps`)
+ setSizeDisplay(`${(evt.data.byteLength / 1024).toFixed(0)} KB/frame`)
+ frameCount = 0
+ lastFpsTime = now
+ }
+ }
+
+ socket.onerror = () => {
+ setStatus('error')
+ }
+
+ socket.onclose = () => {
+ setStatus('error')
+ }
+
+ return () => {
+ socket.close()
+ socketRef.current = null
+ }
+ }, [instanceId, tabId, quality, maxWidth, fps])
+
+ const statusColor =
+ status === 'streaming'
+ ? 'bg-success'
+ : status === 'connecting'
+ ? 'bg-warning'
+ : 'bg-destructive'
+
+ return (
+ <div className="overflow-hidden rounded-lg border border-border-subtle bg-bg-elevated">
+ {/* Header */}
+ <div className="flex items-center justify-between border-b border-border-subtle px-3 py-2">
+ <div className="flex items-center gap-2">
+ <span className="font-mono text-xs text-text-secondary">{label}</span>
+ <div className={`h-2 w-2 rounded-full ${statusColor}`} />
+ </div>
+ <span className="max-w-[200px] truncate text-xs text-text-muted">{url}</span>
+ </div>
+
+ {/* Canvas */}
+ <div className="relative aspect-video bg-black">
+ <canvas
+ ref={canvasRef}
+ className="h-full w-full object-contain"
+ width={800}
+ height={600}
+ />
+ {status === 'error' && (
+ <div className="absolute inset-0 flex items-center justify-center bg-black/80 text-sm text-text-muted">
+ Connection lost
+ </div>
+ )}
+ </div>
+
+ {/* Footer */}
+ <div className="flex justify-between border-t border-border-subtle px-3 py-1 text-xs text-text-muted">
+ <span>{fpsDisplay}</span>
+ <span>{sizeDisplay}</span>
+ </div>
+ </div>
+ )
+}
diff --git a/dashboard/src/components/molecules/index.ts b/dashboard/src/components/molecules/index.ts
index 29dc0a0f..7648aa95 100644
--- a/dashboard/src/components/molecules/index.ts
+++ b/dashboard/src/components/molecules/index.ts
@@ -1,6 +1,7 @@
export { default as NavBar } from './NavBar'
export { default as ProfileCard } from './ProfileCard'
export { default as ProfileDetailsModal } from './ProfileDetailsModal'
+export { default as ScreencastTile } from './ScreencastTile'
export { default as InstanceCard } from './InstanceCard'
export { default as AgentItem } from './AgentItem'
export { default as ActivityLine } from './ActivityLine'