High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(dashboard): proxy screencast live preview
Jamil Zakirovdbdb4b4e68ff
diff --git a/dashboard/src/components/molecules/ProfileDetailsModal.tsx b/dashboard/src/components/molecules/ProfileDetailsModal.tsxindex f2046bd0..e64ca1bb 100644--- a/dashboard/src/components/molecules/ProfileDetailsModal.tsx+++ b/dashboard/src/components/molecules/ProfileDetailsModal.tsx@@ -248,7 +248,7 @@ export default function ProfileDetailsModal({{tabs.map((tab) => (<ScreencastTilekey={tab.id}- instancePort={instance.port}+ instanceId={instance.id}tabId={tab.id}label={tab.title?.slice(0, 20) || tab.id.slice(0, 8)}url={tab.url}diff --git a/dashboard/src/components/molecules/ProfileDetailsPanel.tsx b/dashboard/src/components/molecules/ProfileDetailsPanel.tsxindex a19ad7d3..0132b948 100644--- a/dashboard/src/components/molecules/ProfileDetailsPanel.tsx+++ b/dashboard/src/components/molecules/ProfileDetailsPanel.tsx@@ -362,7 +362,7 @@ export default function ProfileDetailsPanel({{tabs.map((tab) => (<ScreencastTilekey={tab.id}- instancePort={instance.port}+ instanceId={instance.id}tabId={tab.id}label={tab.title?.slice(0, 20) || tab.id.slice(0, 8)}url={tab.url}diff --git a/dashboard/src/components/molecules/ScreencastTile.test.tsx b/dashboard/src/components/molecules/ScreencastTile.test.tsxnew file mode 100644index 00000000..240ba79f--- /dev/null+++ b/dashboard/src/components/molecules/ScreencastTile.test.tsx@@ -0,0 +1,45 @@+import { render, waitFor } from "@testing-library/react";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import ScreencastTile from "./ScreencastTile";++const webSocketMock = vi.fn(function MockWebSocket(this: Record<string, unknown>) {+ this.close = vi.fn();+});++describe("ScreencastTile", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ vi.stubGlobal(+ "location",+ new URL("https://browser.zakirov.dev/dashboard/profiles"),+ );+ window.localStorage.setItem("pinchtab.auth.token", "secret-token");+ vi+ .spyOn(HTMLCanvasElement.prototype, "getContext")+ .mockReturnValue({ drawImage: vi.fn() } as unknown as CanvasRenderingContext2D);+ vi.stubGlobal("WebSocket", webSocketMock);+ });++ afterEach(() => {+ window.localStorage.clear();+ vi.unstubAllGlobals();+ vi.restoreAllMocks();+ });++ it("connects through the same-origin screencast proxy on secure deployments", async () => {+ render(+ <ScreencastTile+ instanceId="inst_123"+ tabId="tab_456"+ label="Example"+ url="https://example.com"+ />,+ );++ await waitFor(() => expect(webSocketMock).toHaveBeenCalledTimes(1));++ expect(webSocketMock).toHaveBeenCalledWith(+ "wss://browser.zakirov.dev/instances/inst_123/proxy/screencast?tabId=tab_456&quality=30&maxWidth=800&fps=1&token=secret-token",+ );+ });+});diff --git a/dashboard/src/components/molecules/ScreencastTile.tsx b/dashboard/src/components/molecules/ScreencastTile.tsxindex 06632ec6..afb0ddaa 100644--- a/dashboard/src/components/molecules/ScreencastTile.tsx+++ b/dashboard/src/components/molecules/ScreencastTile.tsx@@ -1,8 +1,8 @@import { useEffect, useRef, useState } from "react";-import { getStoredAuthToken } from "../../services/auth";+import { addTokenToUrl } from "../../services/auth";interface Props {- instancePort: string;+ instanceId: string;tabId: string;label: string;url: string;@@ -14,7 +14,7 @@ interface Props {type Status = "connecting" | "streaming" | "error";export default function ScreencastTile({- instancePort,+ instanceId,tabId,label,url,@@ -35,23 +35,19 @@ export default function ScreencastTile({const ctx = canvas.getContext("2d");if (!ctx) return;- // Connect directly to instance's screencast WebSocket.- // Use window.location.hostname so this works when the dashboard is served- // from a remote host (e.g. a headless Ubuntu server) instead of localhost.- const host = window.location.hostname;- const token = getStoredAuthToken();const params = new URLSearchParams({tabId,quality: String(quality),maxWidth: String(maxWidth),fps: String(fps),});- if (token) {- params.set("token", token);- }- const wsUrl = `ws://${host}:${instancePort}/screencast?${params.toString()}`;+ const path = addTokenToUrl(+ `/instances/${encodeURIComponent(instanceId)}/proxy/screencast?${params.toString()}`,+ );+ const wsUrl = new URL(path, window.location.origin);+ wsUrl.protocol = window.location.protocol === "https:" ? "wss:" : "ws:";- const socket = new WebSocket(wsUrl);+ const socket = new WebSocket(wsUrl.toString());socket.binaryType = "arraybuffer";socketRef.current = socket;@@ -96,7 +92,7 @@ export default function ScreencastTile({socket.close();socketRef.current = null;};- }, [instancePort, tabId, quality, maxWidth, fps]);+ }, [instanceId, tabId, quality, maxWidth, fps]);const statusColor =status === "streaming"