Skip to content

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

fix: screencast JS hardening & dashboard improvements (#376)

luigiagentf217eba03138
diff --git a/.gitignore b/.gitignore
index d333910f..290ce1f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,53 +1,50 @@
-node_modules/
-.venv/
-plugins/*/.venv/
-__pycache__/
-*.pyc
-browser-bridge
-/pinchtab
-cover.out
-coverage.out
-# Build artifacts and test output
-dist/
-*.js
-!scripts/**/*.js
!dashboard/eslint.config.js
!dashboard/vite.config.ts
+!internal/assets/*.js
!npm/bin/pinchtab
-# React dashboard build output (generated by scripts/build-dashboard.sh)
+!scripts/**/*.js
+!tests/e2e/results/.gitkeep
+# Build artifacts and test output
+# E2E test results
# Go code serves a built-in fallback when these files are absent.
-internal/dashboard/dashboard/assets/
-internal/dashboard/dashboard/dashboard.html
-
+# Local development files
+# OpenClaw workspace files (should never be committed)
+# React dashboard build output (generated by scripts/build-dashboard.sh)
# npm package
-npm/node_modules/
# package-lock.json is committed for reproducible installs via npm ci
-
-# OpenClaw workspace files (should never be committed)
+*.js
+*.pyc
+*.test
+.DS_Store
+.gocache
+.gomodcache/
.openclaw/
-SOUL.md
+.tools/
+.venv/
+/pinchtab
+AGENTS.md
+BOOTSTRAP.md
HEARTBEAT.md
IDENTITY.md
-USER.md
-BOOTSTRAP.md
-TOOLS.md
MEMORY.md
-AGENTS.md
-*.test
-memory/
-pinchtab-small
-
-# Local development files
MY_PROJECT_NOTES.md
+SOUL.md
+TOOLS.md
+USER.md
+__pycache__/
+browser-bridge
+cover.out
+coverage.out
debug.log
+dist/
+internal/dashboard/dashboard/assets/
+internal/dashboard/dashboard/dashboard.html
+memory/
+node_modules/
+npm/node_modules/
+pinchtab-dev
+pinchtab-small
pinchtab.exe
-.tools/
-
-.gomodcache/
-.gocache
-.DS_Store
-# E2E test results
+plugins/*/.venv/
tests/e2e/results/*
-!tests/e2e/results/.gitkeep
-cover.out
diff --git a/README.md b/README.md
index 2372f4e3..18843868 100644
--- a/README.md
+++ b/README.md
@@ -69,6 +69,8 @@ PinchTab defaults to a **local-first security posture**:
> By default, IDPI restricts browsing to **locally hosted websites only**.
> This prevents agents from navigating the public internet until you explicitly allow it.
> The restriction exists to make the security implications of browser automation clear before enabling wider access.
+>
+> Expanding browsing to non-local or non-trusted websites is a security-reducing choice. Hostile pages can still increase browser attack surface and interact badly with enabled automation features even when PinchTab's content defenses are on.
See the full guide: [docs/guides/security.md](docs/guides/security.md)
diff --git a/dashboard/src/components/profiles/ProfileLiveViewPanel.tsx b/dashboard/src/components/profiles/ProfileLiveViewPanel.tsx
index 301c213d..9ad98c71 100644
--- a/dashboard/src/components/profiles/ProfileLiveViewPanel.tsx
+++ b/dashboard/src/components/profiles/ProfileLiveViewPanel.tsx
@@ -13,6 +13,8 @@ export default function ProfileLiveViewPanel({
tabs,
isRunning,
}: Props) {
+ const sortedTabs = [...tabs].sort((a, b) => a.id.localeCompare(b.id));
+
return (
<div className="h-full overflow-y-auto">
{isRunning && instance ? (
@@ -20,7 +22,7 @@ export default function ProfileLiveViewPanel({
<EmptyView message="No tabs open" />
) : (
<div className="p-4 grid grid-cols-1 gap-4 lg:grid-cols-2">
- {tabs.map((tab) => (
+ {sortedTabs.map((tab) => (
<div key={tab.id} className="aspect-video">
<ScreencastTile
instanceId={instance.id}
diff --git a/dashboard/src/components/screencast/ScreencastTile.test.tsx b/dashboard/src/components/screencast/ScreencastTile.test.tsx
index 836dd556..fff47f21 100644
--- a/dashboard/src/components/screencast/ScreencastTile.test.tsx
+++ b/dashboard/src/components/screencast/ScreencastTile.test.tsx
@@ -60,7 +60,7 @@ describe("ScreencastTile", () => {
await waitFor(() => expect(webSocketMock).toHaveBeenCalledTimes(1));
expect(webSocketMock).toHaveBeenCalledWith(
- "wss://pinchtab.com/instances/inst_123/proxy/screencast?tabId=tab_456&quality=30&maxWidth=800&fps=1",
+ "wss://pinchtab.com/instances/inst_123/proxy/screencast?tabId=tab_456&quality=40&maxWidth=800&fps=1",
);
});
@@ -88,6 +88,90 @@ describe("ScreencastTile", () => {
);
});
+ it("renders streamed frames with createImageBitmap when available", async () => {
+ const drawImage = vi.fn();
+ vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue({
+ drawImage,
+ } as unknown as CanvasRenderingContext2D);
+
+ const bitmap = {
+ width: 640,
+ height: 360,
+ close: vi.fn(),
+ } as unknown as ImageBitmap;
+ const createImageBitmapMock = vi.fn().mockResolvedValue(bitmap);
+ vi.stubGlobal("createImageBitmap", createImageBitmapMock);
+
+ render(
+ <ScreencastTile
+ instanceId="inst_123"
+ tabId="tab_456"
+ label="Example"
+ url="https://pinchtab.com"
+ />,
+ );
+
+ await waitFor(() => expect(webSocketMock).toHaveBeenCalledTimes(1));
+
+ const socket = webSocketInstances[0] as {
+ onmessage?: (event: MessageEvent<ArrayBuffer>) => void;
+ };
+ await act(async () => {
+ socket.onmessage?.({
+ data: new Uint8Array([1, 2, 3]).buffer,
+ } as MessageEvent<ArrayBuffer>);
+ });
+
+ await waitFor(() => expect(drawImage).toHaveBeenCalledWith(bitmap, 0, 0));
+ expect(createImageBitmapMock).toHaveBeenCalledTimes(1);
+ expect(bitmap.close).toHaveBeenCalledTimes(1);
+ });
+
+ it("keeps rendering after a frame decode failure", async () => {
+ const drawImage = vi.fn();
+ vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue({
+ drawImage,
+ } as unknown as CanvasRenderingContext2D);
+
+ const bitmap = {
+ width: 800,
+ height: 600,
+ close: vi.fn(),
+ } as unknown as ImageBitmap;
+ const createImageBitmapMock = vi
+ .fn()
+ .mockRejectedValueOnce(new Error("decode failed"))
+ .mockResolvedValueOnce(bitmap);
+ vi.stubGlobal("createImageBitmap", createImageBitmapMock);
+ vi.spyOn(console, "error").mockImplementation(() => {});
+
+ render(
+ <ScreencastTile
+ instanceId="inst_123"
+ tabId="tab_456"
+ label="Example"
+ url="https://pinchtab.com"
+ />,
+ );
+
+ await waitFor(() => expect(webSocketMock).toHaveBeenCalledTimes(1));
+
+ const socket = webSocketInstances[0] as {
+ onmessage?: (event: MessageEvent<ArrayBuffer>) => void;
+ };
+ await act(async () => {
+ socket.onmessage?.({
+ data: new Uint8Array([1, 2, 3]).buffer,
+ } as MessageEvent<ArrayBuffer>);
+ socket.onmessage?.({
+ data: new Uint8Array([4, 5, 6]).buffer,
+ } as MessageEvent<ArrayBuffer>);
+ });
+
+ await waitFor(() => expect(drawImage).toHaveBeenCalledWith(bitmap, 0, 0));
+ expect(createImageBitmapMock).toHaveBeenCalledTimes(2);
+ });
+
it("reconnects when retry is clicked after the socket closes", async () => {
render(
<ScreencastTile
diff --git a/dashboard/src/components/screencast/ScreencastTile.tsx b/dashboard/src/components/screencast/ScreencastTile.tsx
index 1c7ac25b..4b157180 100644
--- a/dashboard/src/components/screencast/ScreencastTile.tsx
+++ b/dashboard/src/components/screencast/ScreencastTile.tsx
@@ -16,12 +16,58 @@ interface Props {
showTitle?: boolean;
}
+function loadImageElement(blob: Blob): Promise<HTMLImageElement> {
+ return new Promise((resolve, reject) => {
+ const imgUrl = URL.createObjectURL(blob);
+ const img = new Image();
+
+ img.onload = () => {
+ URL.revokeObjectURL(imgUrl);
+ resolve(img);
+ };
+ img.onerror = () => {
+ URL.revokeObjectURL(imgUrl);
+ reject(new Error("Failed to decode screencast frame"));
+ };
+
+ img.src = imgUrl;
+ });
+}
+
+async function drawFrameToCanvas(
+ canvas: HTMLCanvasElement,
+ ctx: CanvasRenderingContext2D,
+ frameData: ArrayBuffer | Blob,
+): Promise<void> {
+ const blob =
+ frameData instanceof Blob
+ ? frameData
+ : new Blob([frameData], { type: "image/jpeg" });
+
+ if (typeof window.createImageBitmap === "function") {
+ const bitmap = await window.createImageBitmap(blob);
+ try {
+ canvas.width = bitmap.width;
+ canvas.height = bitmap.height;
+ ctx.drawImage(bitmap, 0, 0);
+ return;
+ } finally {
+ bitmap.close();
+ }
+ }
+
+ const image = await loadImageElement(blob);
+ canvas.width = image.width;
+ canvas.height = image.height;
+ ctx.drawImage(image, 0, 0);
+}
+
export default function ScreencastTile({
instanceId,
tabId,
label,
url,
- quality = 30,
+ quality = 40,
maxWidth = 800,
fps = 1,
showTitle = true,
@@ -195,16 +241,45 @@ export default function ScreencastTile({
setHasFrame(false);
let disposed = false;
- let fallbackCaptured = false;
+ let hasRenderedFrame = false;
+ let pendingFrame: ArrayBuffer | Blob | null = null;
+ let renderInFlight = false;
let frameCount = 0;
let lastFpsTime = Date.now();
const fallbackTimer = window.setTimeout(() => {
- if (!disposed && !fallbackCaptured) {
+ if (!disposed && !hasRenderedFrame) {
void captureFallback();
}
}, 1500);
+ const renderNextFrame = async () => {
+ if (disposed || renderInFlight || !pendingFrame) return;
+
+ renderInFlight = true;
+ const frameData = pendingFrame;
+ pendingFrame = null;
+
+ try {
+ await drawFrameToCanvas(canvas, ctx, frameData);
+ if (disposed) return;
+
+ hasRenderedFrame = true;
+ window.clearTimeout(fallbackTimer);
+ setHasFrame(true);
+ setStatus("streaming");
+ } catch (err) {
+ if (!disposed) {
+ console.error("screencast frame render failed", err);
+ }
+ } finally {
+ renderInFlight = false;
+ if (!disposed && pendingFrame) {
+ void renderNextFrame();
+ }
+ }
+ };
+
socket.onopen = () => {
if (!disposed) {
setStatus("connecting");
@@ -213,25 +288,8 @@ export default function ScreencastTile({
socket.onmessage = (evt) => {
if (disposed) return;
- fallbackCaptured = true;
- window.clearTimeout(fallbackTimer);
-
- const blob = new Blob([evt.data], { type: "image/jpeg" });
- const imgUrl = URL.createObjectURL(blob);
- const img = new Image();
- img.onload = () => {
- if (disposed) {
- URL.revokeObjectURL(imgUrl);
- return;
- }
- canvas.width = img.width;
- canvas.height = img.height;
- ctx.drawImage(img, 0, 0);
- URL.revokeObjectURL(imgUrl);
- };
- img.src = imgUrl;
- setHasFrame(true);
- setStatus("streaming");
+ pendingFrame = evt.data;
+ void renderNextFrame();
frameCount++;
const now = Date.now();
diff --git a/dashboard/src/components/tabs/IdBadge.test.tsx b/dashboard/src/components/tabs/IdBadge.test.tsx
index 07ede0c0..b0cf8a1c 100644
--- a/dashboard/src/components/tabs/IdBadge.test.tsx
+++ b/dashboard/src/components/tabs/IdBadge.test.tsx
@@ -48,4 +48,11 @@ describe("IdBadge", () => {
expect(screen.queryByRole("button")).not.toBeInTheDocument();
expect(screen.getByText("12345678")).toBeInTheDocument();
});
+
+ it("renders compact variant with correct classes", () => {
+ const { container } = render(<IdBadge id={mockId} variant="compact" />);
+ const badge = container.firstChild;
+ expect(badge).toHaveClass("bg-primary/10");
+ expect(badge).toHaveClass("text-primary");
+ });
});
diff --git a/dashboard/src/components/tabs/IdBadge.tsx b/dashboard/src/components/tabs/IdBadge.tsx
index e5741ba7..a8746f9b 100644
--- a/dashboard/src/components/tabs/IdBadge.tsx
+++ b/dashboard/src/components/tabs/IdBadge.tsx
@@ -3,9 +3,14 @@ import { useState } from "react";
interface Props {
id: string;
copyable?: boolean;
+ variant?: "default" | "compact";
}
-export default function IdBadge({ id, copyable = true }: Props) {
+export default function IdBadge({
+ id,
+ copyable = true,
+ variant = "default",
+}: Props) {
const [copied, setCopied] = useState(false);
const handleCopy = (e: React.MouseEvent) => {
@@ -17,24 +22,43 @@ export default function IdBadge({ id, copyable = true }: Props) {
const shortId = id.split("_").pop()?.substring(0, 8) || id;
+ const baseStyles =
+ "flex shrink-0 items-center transition-colors focus:outline-none font-mono";
+
+ const variantStyles = {
+ default:
+ "rounded bg-bg-elevated px-1.5 py-0.5 text-[10px] text-text-muted hover:bg-border-subtle hover:text-text-primary",
+ compact:
+ "rounded bg-primary/10 px-1.5 py-0.5 text-[9px] text-primary hover:bg-primary/20",
+ };
+
+ const content = (
+ <>
+ <span>{variant === "compact" ? "ID" : shortId}</span>
+ {copyable && variant === "default" && (
+ <span className="text-[8px] opacity-0 transition-opacity group-hover:opacity-100">
+ {copied ? "✅" : "📋"}
+ </span>
+ )}
+ {copyable && variant === "compact" && copied && (
+ <span className="ml-1 text-[8px]">✅</span>
+ )}
+ </>
+ );
+
if (copyable) {
return (
<button
onClick={handleCopy}
title={`Click to copy full ID: ${id}`}
- className="group flex shrink-0 items-center gap-1.5 rounded bg-bg-elevated px-1.5 py-0.5 text-[10px] font-mono text-text-muted transition-colors hover:bg-border-subtle hover:text-text-primary focus:outline-none"
+ className={`group ${baseStyles} ${variantStyles[variant]}`}
>
- <span>{shortId}</span>
- <span className="text-[8px] opacity-0 transition-opacity group-hover:opacity-100">
- {copied ? "✅" : "📋"}
- </span>
+ {content}
</button>
);
}
return (
- <div className="flex shrink-0 items-center gap-1.5 rounded bg-bg-elevated px-1.5 py-0.5 text-[10px] font-mono text-text-muted">
- <span>{shortId}</span>
- </div>
+ <div className={`${baseStyles} ${variantStyles[variant]}`}>{content}</div>
);
}
diff --git a/dashboard/src/components/tabs/InstanceTabsPanel.test.tsx b/dashboard/src/components/tabs/InstanceTabsPanel.test.tsx
index ee989b27..6dac847f 100644
--- a/dashboard/src/components/tabs/InstanceTabsPanel.test.tsx
+++ b/dashboard/src/components/tabs/InstanceTabsPanel.test.tsx
@@ -23,8 +23,6 @@ describe("InstanceTabsPanel", () => {
it("auto-selects the first tab and shows its details", () => {
render(<InstanceTabsPanel tabs={tabs} />);
- expect(screen.getByText("Open Tabs (2)")).toBeInTheDocument();
-
// Find heading for first tab title
const titleHeading = screen.getByRole("heading", { name: "Alpha Tab" });
const detailPanel = titleHeading.closest(".rounded-xl") as HTMLElement;
@@ -33,8 +31,8 @@ describe("InstanceTabsPanel", () => {
within(detailPanel).getByText("https://example.com/alpha"),
).toBeInTheDocument();
- // IdBadge will show "alpha" instead of "tab_alpha"
- expect(within(detailPanel).getByText("alpha")).toBeInTheDocument();
+ // IdBadge will show "ID" instead of "alpha" (shortened tab_alpha)
+ expect(within(detailPanel).getByText("ID")).toBeInTheDocument();
});
it("updates the selected tab details when a tab is clicked", async () => {
@@ -42,9 +40,7 @@ describe("InstanceTabsPanel", () => {
render(<InstanceTabsPanel tabs={tabs} />);
// Select Beta tab from list
- const betaTabItem = screen.getByRole("button", {
- name: /Beta Tab.*tab_beta/,
- });
+ const betaTabItem = screen.getByRole("button", { name: /^Beta Tab$/ });
await user.click(betaTabItem);
// Find heading for beta tab title
@@ -54,13 +50,48 @@ describe("InstanceTabsPanel", () => {
expect(
within(detailPanel).getByText("https://example.com/beta"),
).toBeInTheDocument();
- expect(within(detailPanel).getByText("beta")).toBeInTheDocument();
+ expect(within(detailPanel).getByText("ID")).toBeInTheDocument();
+ expect(
+ screen.getByRole("button", { name: "Unpin Beta Tab and follow focus" }),
+ ).toBeInTheDocument();
+ });
+
+ it("follows the focused tab until a manual selection is pinned", async () => {
+ const user = userEvent.setup();
+ const { rerender } = render(<InstanceTabsPanel tabs={tabs} />);
+
+ rerender(<InstanceTabsPanel tabs={[tabs[1], tabs[0]]} />);
+ expect(
+ screen.getByRole("heading", { name: "Beta Tab" }),
+ ).toBeInTheDocument();
+
+ await user.click(screen.getByRole("button", { name: /^Alpha Tab$/ }));
+ expect(
+ screen.getByRole("heading", { name: "Alpha Tab" }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("button", { name: "Unpin Alpha Tab and follow focus" }),
+ ).toBeInTheDocument();
+
+ rerender(<InstanceTabsPanel tabs={[tabs[1], tabs[0]]} />);
+ expect(
+ screen.getByRole("heading", { name: "Alpha Tab" }),
+ ).toBeInTheDocument();
+
+ await user.click(
+ screen.getByRole("button", { name: "Unpin Alpha Tab and follow focus" }),
+ );
+ expect(
+ screen.getByRole("button", { name: "Pin Beta Tab" }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("heading", { name: "Beta Tab" }),
+ ).toBeInTheDocument();
});
it("shows an empty state when there are no tabs", () => {
render(<InstanceTabsPanel tabs={[]} />);
- expect(screen.getByText("Open Tabs (0)")).toBeInTheDocument();
expect(screen.getByText("No tabs open")).toBeInTheDocument();
});
});
diff --git a/dashboard/src/components/tabs/InstanceTabsPanel.tsx b/dashboard/src/components/tabs/InstanceTabsPanel.tsx
index 6b083d3e..46570523 100644
--- a/dashboard/src/components/tabs/InstanceTabsPanel.tsx
+++ b/dashboard/src/components/tabs/InstanceTabsPanel.tsx
@@ -15,31 +15,40 @@ export default function InstanceTabsPanel({
instanceId,
}: Props) {
const [selectedTabId, setSelectedTabId] = useState<string | null>(null);
+ const [selectionPinned, setSelectionPinned] = useState(false);
useEffect(() => {
if (tabs.length === 0) {
setSelectedTabId(null);
+ setSelectionPinned(false);
return;
}
- if (!tabs.some((tab) => tab.id === selectedTabId)) {
- setSelectedTabId(tabs[0].id);
+ if (selectionPinned && tabs.some((tab) => tab.id === selectedTabId)) {
+ return;
+ }
+
+ if (
+ !tabs.some((tab) => tab.id === selectedTabId) ||
+ selectedTabId !== tabs[0].id
+ ) {
+ if (selectedTabId !== tabs[0].id) {
+ setSelectedTabId(tabs[0].id);
+ }
+ if (selectionPinned) {
+ setSelectionPinned(false);
+ }
}
- }, [selectedTabId, tabs]);
+ }, [selectedTabId, selectionPinned, tabs]);
const selectedTab = useMemo(
() => tabs.find((tab) => tab.id === selectedTabId) ?? null,
[selectedTabId, tabs],
);
- const heading = `Open Tabs (${tabs.length})`;
-
if (tabs.length === 0) {
return (
<div className="flex min-h-0 flex-1 flex-col">
- <div className="border-b border-border-subtle px-4 py-3">
- <h2 className="text-sm font-medium text-text-primary">{heading}</h2>
- </div>
<div className="flex flex-1 items-center justify-center py-8 text-sm text-text-muted">
{emptyMessage}
</div>
@@ -49,13 +58,23 @@ export default function InstanceTabsPanel({
return (
<div className="flex min-h-0 flex-1 flex-col">
- <div className="border-b border-border-subtle px-4 py-3">
- <h2 className="text-sm font-medium text-text-primary">{heading}</h2>
- </div>
<TabBar
tabs={tabs}
selectedTabId={selectedTabId}
- onSelect={setSelectedTabId}
+ pinnedTabId={selectionPinned ? selectedTabId : null}
+ onSelect={(id) => {
+ setSelectedTabId(id);
+ setSelectionPinned(true);
+ }}
+ onTogglePinned={(id) => {
+ if (selectionPinned && selectedTabId === id) {
+ setSelectionPinned(false);
+ setSelectedTabId(tabs[0]?.id ?? null);
+ return;
+ }
+ setSelectedTabId(id);
+ setSelectionPinned(true);
+ }}
/>
<SelectedTabPanel selectedTab={selectedTab} instanceId={instanceId} />
</div>
diff --git a/dashboard/src/components/tabs/SelectedTabPanel.tsx b/dashboard/src/components/tabs/SelectedTabPanel.tsx
index 3829f7c5..0c7aa5a0 100644
--- a/dashboard/src/components/tabs/SelectedTabPanel.tsx
+++ b/dashboard/src/components/tabs/SelectedTabPanel.tsx
@@ -1,9 +1,9 @@
import { useState } from "react";
import { ActivityExplorer } from "../../activities";
import type { InstanceTab } from "../../generated/types";
-import IdBadge from "./IdBadge";
import { TabsLayout, EmptyView } from "../molecules";
import ScreencastTile from "../screencast/ScreencastTile";
+import SelectedTabTitle from "./SelectedTabTitle";
interface Props {
selectedTab: InstanceTab | null;
@@ -12,20 +12,6 @@ interface Props {
type SubTabId = "actions" | "live" | "console" | "errors";
-function TabInfo({ tab }: { tab: InstanceTab }) {
- return (
- <div className="flex flex-col gap-0.5 text-right">
- <div className="flex items-center justify-end gap-1.5">
- <h3 className="truncate text-xs font-medium text-text-secondary">
- {tab.title || "Untitled"}
- </h3>
- <IdBadge id={tab.id} />
- </div>
- <div className="truncate text-[10px] text-text-muted">{tab.url}</div>
- </div>
- );
-}
-
export default function SelectedTabPanel({ selectedTab, instanceId }: Props) {
const [activeSubTab, setActiveSubTab] = useState<SubTabId>("live");
@@ -51,7 +37,7 @@ export default function SelectedTabPanel({ selectedTab, instanceId }: Props) {
tabs={subTabs}
activeTab={activeSubTab}
onChange={(id) => setActiveSubTab(id)}
- rightSlot={<TabInfo tab={selectedTab} />}
+ rightSlot={<SelectedTabTitle tab={selectedTab} />}
>
{activeSubTab === "actions" && (
<div className="h-full">
diff --git a/dashboard/src/components/tabs/SelectedTabTitle.tsx b/dashboard/src/components/tabs/SelectedTabTitle.tsx
new file mode 100644
index 00000000..8067a03f
--- /dev/null
+++ b/dashboard/src/components/tabs/SelectedTabTitle.tsx
@@ -0,0 +1,22 @@
+import type { InstanceTab } from "../../generated/types";
+import IdBadge from "./IdBadge";
+
+interface Props {
+ tab: InstanceTab;
+}
+
+export default function SelectedTabTitle({ tab }: Props) {
+ return (
+ <div className="flex min-w-0 items-center gap-3">
+ <div className="flex min-w-0 flex-col gap-0.5 text-right">
+ <div className="flex items-center justify-end gap-1.5">
+ <h3 className="truncate text-xs font-medium text-text-secondary">
+ {tab.title || "Untitled"}
+ </h3>
+ <IdBadge id={tab.id} variant="compact" />
+ </div>
+ <div className="truncate text-[10px] text-text-muted">{tab.url}</div>
+ </div>
+ </div>
+ );
+}
diff --git a/dashboard/src/components/tabs/TabBar.tsx b/dashboard/src/components/tabs/TabBar.tsx
index c3e3e141..51ddfac0 100644
--- a/dashboard/src/components/tabs/TabBar.tsx
+++ b/dashboard/src/components/tabs/TabBar.tsx
@@ -4,14 +4,37 @@ import * as api from "../../services/api";
interface Props {
tabs: InstanceTab[];
selectedTabId: string | null;
+ pinnedTabId?: string | null;
onSelect: (id: string) => void;
+ onTogglePinned?: (id: string) => void;
onTabClosed?: () => void;
}
+function PinIcon({ pinned }: { pinned: boolean }) {
+ return (
+ <svg
+ viewBox="0 0 24 24"
+ aria-hidden="true"
+ className={`h-3.5 w-3.5 transition-colors ${pinned ? "opacity-100" : ""}`}
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ >
+ <path d="M15 4.5l-4 4l-4 1.5l-1.5 1.5l7 7l1.5 -1.5l1.5 -4l4 -4" />
+ <path d="M9 15l-4.5 4.5" />
+ <path d="M14.5 4l5.5 5.5" />
+ </svg>
+ );
+}
+
export default function TabBar({
tabs,
selectedTabId,
+ pinnedTabId,
onSelect,
+ onTogglePinned,
onTabClosed,
}: Props) {
const handleClose = async (e: React.MouseEvent, tabId: string) => {
@@ -29,39 +52,59 @@ export default function TabBar({
<div className="flex min-h-0 items-end gap-px overflow-x-auto border-b border-border-subtle bg-black/10 px-1 pt-1">
{tabs.map((tab) => {
const isSelected = tab.id === selectedTabId;
+ const isPinned = tab.id === pinnedTabId;
const title = tab.title || "Untitled";
- const shortId = tab.id.substring(0, 8);
return (
- <button
+ <div
key={tab.id}
- onClick={() => onSelect(tab.id)}
- title={`${title}\n${tab.url}\n${tab.id}`}
className={`group relative flex max-w-52 min-w-0 items-center gap-1 rounded-t-md pl-3 pr-1.5 py-1.5 text-left transition-colors ${
isSelected
? "bg-bg-surface text-text-primary border-x border-t border-border-subtle"
: "text-text-muted hover:bg-white/5 hover:text-text-secondary"
}`}
>
- <span className="truncate text-xs font-medium">{title}</span>
- <span
- className={`shrink-0 font-mono text-[9px] ${isSelected ? "text-text-muted" : "text-text-muted/50"}`}
+ <button
+ type="button"
+ onClick={() => onSelect(tab.id)}
+ title={`${title}\n${tab.url}`}
+ className="min-w-0 flex-1 truncate text-left"
>
- {shortId}
- </span>
- <span
- role="button"
- tabIndex={0}
+ <span className="truncate text-xs font-medium">{title}</span>
+ </button>
+ {onTogglePinned && (
+ <button
+ type="button"
+ onClick={(e) => {
+ e.stopPropagation();
+ onTogglePinned(tab.id);
+ }}
+ aria-label={
+ isPinned ? `Unpin ${title} and follow focus` : `Pin ${title}`
+ }
+ title={
+ isPinned
+ ? "Unpin and follow the focused tab again"
+ : "Pin this tab selection"
+ }
+ className={`shrink-0 rounded p-0.5 transition-all ${
+ isPinned
+ ? "text-text-primary opacity-100"
+ : "text-text-muted/50 opacity-0 hover:bg-white/10 hover:text-text-primary group-hover:opacity-100"
+ }`}
+ >
+ <PinIcon pinned={isPinned} />
+ </button>
+ )}
+ <button
+ type="button"
onClick={(e) => handleClose(e, tab.id)}
- onKeyDown={(e) => {
- if (e.key === "Enter")
- handleClose(e as unknown as React.MouseEvent, tab.id);
- }}
+ aria-label={`Close ${title}`}
className="ml-0.5 shrink-0 rounded p-0.5 text-[10px] leading-none text-text-muted/40 opacity-0 transition-all hover:bg-white/10 hover:text-text-primary group-hover:opacity-100"
>
✕
- </span>
- </button>
+ </button>
+ </div>
);
})}
</div>
diff --git a/dashboard/src/components/tabs/TabItem.tsx b/dashboard/src/components/tabs/TabItem.tsx
index 74a4e5a2..ea587720 100644
--- a/dashboard/src/components/tabs/TabItem.tsx
+++ b/dashboard/src/components/tabs/TabItem.tsx
@@ -6,7 +6,7 @@ interface Props {
export default function TabItem({ tab }: Props) {
return (
- <div className="rounded-md border border-border-subtle/80 bg-white/2 px-3 py-2.5 transition-colors hover:border-border-default hover:bg-white/[0.03]">
+ <div className="rounded-md border border-border-subtle/80 bg-white/2 px-3 py-2.5 transition-colors hover:border-border-default hover:bg-white/3">
<div className="truncate text-sm font-medium text-text-primary">
{tab.title || "Untitled"}
</div>
diff --git a/dashboard/src/components/tabs/index.ts b/dashboard/src/components/tabs/index.ts
index 0d693424..72b04cfe 100644
--- a/dashboard/src/components/tabs/index.ts
+++ b/dashboard/src/components/tabs/index.ts
@@ -1,5 +1,6 @@
export { default as InstanceTabsPanel } from "./InstanceTabsPanel";
export { default as SelectedTabPanel } from "./SelectedTabPanel";
+export { default as SelectedTabTitle } from "./SelectedTabTitle";
export { default as TabBar } from "./TabBar";
export { default as TabItem } from "./TabItem";
export { default as IdBadge } from "./IdBadge";
diff --git a/dashboard/src/pages/SettingsPage.tsx b/dashboard/src/pages/SettingsPage.tsx
index 45e074bd..e012c74a 100644
--- a/dashboard/src/pages/SettingsPage.tsx
+++ b/dashboard/src/pages/SettingsPage.tsx
@@ -1200,7 +1200,9 @@ export default function SettingsPage() {
/>
<div className="rounded-sm border border-warning/25 bg-warning/10 px-3 py-2 text-xs leading-5 text-warning">
Keep this list narrow. Empty or wildcard entries weaken
- the main IDPI boundary.
+ the main IDPI boundary. Allowing non-local or
+ non-trusted sites increases browser attack surface even
+ when IDPI is enabled.
</div>
</div>
</SettingRow>
diff --git a/dashboard/src/stores/useAppStore.ts b/dashboard/src/stores/useAppStore.ts
index 027d1fe5..21f092e8 100644
--- a/dashboard/src/stores/useAppStore.ts
+++ b/dashboard/src/stores/useAppStore.ts
@@ -78,7 +78,7 @@ interface AppState {
}
const defaultSettings: Settings = {
- screencast: { fps: 1, quality: 30, maxWidth: 800 },
+ screencast: { fps: 1, quality: 40, maxWidth: 800 },
stealth: "light",
browser: { blockImages: false, blockMedia: false, noAnimations: false },
monitoring: { memoryMetrics: false, pollInterval: 30 },
diff --git a/dashboard/vite.config.ts b/dashboard/vite.config.ts
index 3a7074fd..e162da7d 100644
--- a/dashboard/vite.config.ts
+++ b/dashboard/vite.config.ts
@@ -1,11 +1,37 @@
/// <reference types="vitest/config" />
-import { defineConfig } from 'vite'
+import { defineConfig, type ProxyOptions } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig(() => {
const backendPort = process.env.PINCHTAB_DEV_PORT || '9867'
const backendUrl = `http://localhost:${backendPort}`
+ const devToken = process.env.PINCHTAB_TOKEN?.trim() || ''
+
+ const createProxyOptions = (): ProxyOptions => {
+ const authHeader = devToken === '' ? '' : `Bearer ${devToken}`
+ const options: ProxyOptions = {
+ target: backendUrl,
+ changeOrigin: false,
+ ws: true,
+ }
+
+ if (authHeader !== '') {
+ options.headers = {
+ Authorization: authHeader,
+ }
+ options.configure = (proxy) => {
+ proxy.on('proxyReq', (proxyReq) => {
+ proxyReq.setHeader('Authorization', authHeader)
+ })
+ proxy.on('proxyReqWs', (proxyReq) => {
+ proxyReq.setHeader('Authorization', authHeader)
+ })
+ }
+ }
+
+ return options
+ }
// In dev mode, proxy all API routes to the Go backend.
// Add new top-level API paths here as they're created.
@@ -14,9 +40,9 @@ export default defineConfig(() => {
'/navigate', '/action', '/screenshot', '/evaluate', '/find', '/text',
'/snapshot', '/download', '/upload', '/cookies', '/fingerprint', '/scheduler',
]
- const proxy: Record<string, string> = {}
+ const proxy: Record<string, ProxyOptions> = {}
for (const path of apiPaths) {
- proxy[path] = backendUrl
+ proxy[path] = createProxyOptions()
}
return {
diff --git a/docs/guides/security.md b/docs/guides/security.md
index 087a37bc..fcfe2798 100644
--- a/docs/guides/security.md
+++ b/docs/guides/security.md
@@ -218,6 +218,7 @@ Important notes:
- `strictMode = false` allows the request but emits warnings instead
- `scanContent` protects `/text` and `/snapshot` style extraction paths
- `wrapContent` adds explicit untrusted-content framing for downstream consumers
+- widening navigation to non-local or non-trusted sites is still a security-reducing choice; IDPI lowers risk, but it does not make hostile pages safe or remove browser attack surface
Supported domain patterns are:
diff --git a/internal/assets/assets.go b/internal/assets/assets.go
index 042ddbe5..c6b27440 100644
--- a/internal/assets/assets.go
+++ b/internal/assets/assets.go
@@ -10,5 +10,11 @@ var StealthScript string
//go:embed readability.js
var ReadabilityJS string
+//go:embed screencast_repaint_start.js
+var ScreencastRepaintStartJS string
+
+//go:embed screencast_repaint_stop.js
+var ScreencastRepaintStopJS string
+
//go:embed welcome.html
var WelcomeHTML string
diff --git a/internal/assets/screencast_repaint_start.js b/internal/assets/screencast_repaint_start.js
new file mode 100644
index 00000000..1ee74887
--- /dev/null
+++ b/internal/assets/screencast_repaint_start.js
@@ -0,0 +1,40 @@
+(function() {
+ const key = "__pinchtabScreencastRepaint";
+ const state = globalThis[key] || (globalThis[key] = { refs: 0, tick: 0 });
+ state.refs += 1;
+ if (state.refs > 1) {
+ return state.refs;
+ }
+
+ const host = document.createElement("div");
+ host.setAttribute("aria-hidden", "true");
+ host.style.cssText = "position:fixed;left:0;top:0;width:0;height:0;overflow:hidden;pointer-events:none;z-index:2147483647;";
+
+ const shadow = host.attachShadow({ mode: "closed" });
+ const el = document.createElement("div");
+ el.style.cssText = "position:fixed;left:0;top:0;width:1px;height:1px;pointer-events:none;background:rgba(0,0,0,0.001);opacity:0.999;transform:translateZ(0) scale(1);will-change:opacity,transform;";
+ shadow.appendChild(el);
+
+ const mount = () => {
+ const parent = document.body || document.documentElement;
+ if (parent && !host.isConnected) {
+ parent.appendChild(host);
+ }
+ };
+
+ const tick = () => {
+ mount();
+ state.tick = (state.tick + 1) % 2;
+ el.style.opacity = state.tick === 0 ? "0.999" : "1";
+ el.style.transform = state.tick === 0 ? "translateZ(0) scale(1)" : "translateZ(0) scale(1.0001)";
+ };
+
+ mount();
+ tick();
+
+ state.host = host;
+ state.element = el;
+ state.mount = mount;
+ state.timer = setInterval(tick, 250);
+ return state.refs;
+})()
diff --git a/internal/assets/screencast_repaint_stop.js b/internal/assets/screencast_repaint_stop.js
new file mode 100644
index 00000000..56fe4941
--- /dev/null
+++ b/internal/assets/screencast_repaint_stop.js
@@ -0,0 +1,29 @@
+(function() {
+ const key = "__pinchtabScreencastRepaint";
+ const state = globalThis[key];
+ if (!state) {
+ return 0;
+ }
+
+ state.refs = Math.max(0, (state.refs || 1) - 1);
+ if (state.refs > 0) {
+ return state.refs;
+ }
+
+ try {
+ if (state.timer) {
+ clearInterval(state.timer);
+ }
+ } catch (_) {}
+
+ try {
+ if (state.host) {
+ state.host.remove();
+ } else if (state.element) {
+ state.element.remove();
+ }
+ } catch (_) {}
+
+ delete globalThis[key];
+ return 0;
+})()
diff --git a/internal/bridge/action_pointer.go b/internal/bridge/action_pointer.go
index db5ad741..9acb10a2 100644
--- a/internal/bridge/action_pointer.go
+++ b/internal/bridge/action_pointer.go
@@ -8,6 +8,21 @@ import (
"github.com/chromedp/chromedp"
)
+var scrollByCoordinateAction = ScrollByCoordinate
+var scrollViewportCenter = func(ctx context.Context) (float64, float64, error) {
+ var viewport struct {
+ X float64 `json:"x"`
+ Y float64 `json:"y"`
+ }
+ if err := chromedp.Run(ctx, chromedp.Evaluate(`({
+ x: Math.max(1, Math.floor(window.innerWidth / 2)),
+ y: Math.max(1, Math.floor(window.innerHeight / 2))
+ })`, &viewport)); err != nil {
+ return 0, 0, err
+ }
+ return viewport.X, viewport.Y, nil
+}
+
func (b *Bridge) actionClick(ctx context.Context, req ActionRequest) (map[string]any, error) {
var err error
if req.Selector != "" {
@@ -64,13 +79,25 @@ func (b *Bridge) actionScroll(ctx context.Context, req ActionRequest) (map[strin
if req.NodeID > 0 {
return map[string]any{"scrolled": true}, ScrollByNodeID(ctx, req.NodeID)
}
- if req.ScrollX != 0 || req.ScrollY != 0 {
- js := fmt.Sprintf("window.scrollBy(%d, %d)", req.ScrollX, req.ScrollY)
- return map[string]any{"scrolled": true, "x": req.ScrollX, "y": req.ScrollY},
- chromedp.Run(ctx, chromedp.Evaluate(js, nil))
+
+ scrollX := req.ScrollX
+ scrollY := req.ScrollY
+ if scrollX == 0 && scrollY == 0 {
+ scrollY = 800
+ }
+
+ scrollTargetX := req.X
+ scrollTargetY := req.Y
+ if !req.HasXY {
+ var err error
+ scrollTargetX, scrollTargetY, err = scrollViewportCenter(ctx)
+ if err != nil {
+ return nil, fmt.Errorf("resolve scroll viewport center: %w", err)
+ }
}
- return map[string]any{"scrolled": true, "y": 800},
- chromedp.Run(ctx, chromedp.Evaluate("window.scrollBy(0, 800)", nil))
+
+ return map[string]any{"scrolled": true, "x": scrollX, "y": scrollY},
+ scrollByCoordinateAction(ctx, scrollTargetX, scrollTargetY, scrollX, scrollY)
}
func (b *Bridge) actionDrag(ctx context.Context, req ActionRequest) (map[string]any, error) {
diff --git a/internal/bridge/actions_test.go b/internal/bridge/actions_test.go
index 8944f94b..b60e3fb9 100644
--- a/internal/bridge/actions_test.go
+++ b/internal/bridge/actions_test.go
@@ -53,6 +53,114 @@ func TestHoverAction_UsesCoordinatePath(t *testing.T) {
}
}
+func TestScrollAction_UsesCoordinateWheelPath(t *testing.T) {
+ b := New(context.TODO(), nil, &config.RuntimeConfig{})
+
+ origScrollByCoordinate := scrollByCoordinateAction
+ origScrollViewportCenter := scrollViewportCenter
+ t.Cleanup(func() {
+ scrollByCoordinateAction = origScrollByCoordinate
+ scrollViewportCenter = origScrollViewportCenter
+ })
+
+ called := false
+ scrollByCoordinateAction = func(ctx context.Context, x, y float64, deltaX, deltaY int) error {
+ called = true
+ if x != 12.5 || y != 34.5 {
+ t.Fatalf("wheel coordinates = (%v, %v), want (12.5, 34.5)", x, y)
+ }
+ if deltaX != 0 || deltaY != 50 {
+ t.Fatalf("wheel delta = (%d, %d), want (0, 50)", deltaX, deltaY)
+ }
+ return nil
+ }
+ scrollViewportCenter = func(context.Context) (float64, float64, error) {
+ t.Fatal("viewport center should not be used when explicit coordinates are provided")
+ return 0, 0, nil
+ }
+
+ result, err := b.Actions[ActionScroll](context.Background(), ActionRequest{
+ HasXY: true,
+ X: 12.5,
+ Y: 34.5,
+ ScrollY: 50,
+ })
+ if err != nil {
+ t.Fatalf("scroll returned error: %v", err)
+ }
+ if !called {
+ t.Fatal("expected coordinate wheel path to be used")
+ }
+ if result["x"] != 0 || result["y"] != 50 {
+ t.Fatalf("unexpected result payload: %#v", result)
+ }
+}
+
+func TestScrollAction_UsesViewportCenterWhenCoordinatesMissing(t *testing.T) {
+ b := New(context.TODO(), nil, &config.RuntimeConfig{})
+
+ origScrollByCoordinate := scrollByCoordinateAction
+ origScrollViewportCenter := scrollViewportCenter
+ t.Cleanup(func() {
+ scrollByCoordinateAction = origScrollByCoordinate
+ scrollViewportCenter = origScrollViewportCenter
+ })
+
+ scrollViewportCenter = func(context.Context) (float64, float64, error) {
+ return 400, 300, nil
+ }
+
+ called := false
+ scrollByCoordinateAction = func(ctx context.Context, x, y float64, deltaX, deltaY int) error {
+ called = true
+ if x != 400 || y != 300 {
+ t.Fatalf("wheel coordinates = (%v, %v), want (400, 300)", x, y)
+ }
+ if deltaX != 0 || deltaY != 800 {
+ t.Fatalf("wheel delta = (%d, %d), want (0, 800)", deltaX, deltaY)
+ }
+ return nil
+ }
+
+ result, err := b.Actions[ActionScroll](context.Background(), ActionRequest{})
+ if err != nil {
+ t.Fatalf("scroll returned error: %v", err)
+ }
+ if !called {
+ t.Fatal("expected viewport-center wheel path to be used")
+ }
+ if result["x"] != 0 || result["y"] != 800 {
+ t.Fatalf("unexpected result payload: %#v", result)
+ }
+}
+
+func TestScrollAction_PropagatesViewportCenterError(t *testing.T) {
+ b := New(context.TODO(), nil, &config.RuntimeConfig{})
+
+ origScrollByCoordinate := scrollByCoordinateAction
+ origScrollViewportCenter := scrollViewportCenter
+ t.Cleanup(func() {
+ scrollByCoordinateAction = origScrollByCoordinate
+ scrollViewportCenter = origScrollViewportCenter
+ })
+
+ scrollViewportCenter = func(context.Context) (float64, float64, error) {
+ return 0, 0, context.Canceled
+ }
+ scrollByCoordinateAction = func(context.Context, float64, float64, int, int) error {
+ t.Fatal("wheel dispatch should not be called when viewport center resolution fails")
+ return nil
+ }
+
+ _, err := b.Actions[ActionScroll](context.Background(), ActionRequest{})
+ if err == nil {
+ t.Fatal("expected error when viewport center resolution fails")
+ }
+ if !strings.Contains(err.Error(), "resolve scroll viewport center") {
+ t.Fatalf("unexpected error: %v", err)
+ }
+}
+
func TestCheckAction_Registered(t *testing.T) {
b := New(context.TODO(), nil, &config.RuntimeConfig{})
if _, ok := b.Actions[ActionCheck]; !ok {
diff --git a/internal/bridge/cdpops/pointer.go b/internal/bridge/cdpops/pointer.go
index 2470f56b..bbb2b4e8 100644
--- a/internal/bridge/cdpops/pointer.go
+++ b/internal/bridge/cdpops/pointer.go
@@ -202,6 +202,31 @@ func HoverByCoordinate(ctx context.Context, x, y float64) error {
}))
}
+func ScrollByCoordinate(ctx context.Context, x, y float64, deltaX, deltaY int) error {
+ if x < 0 || y < 0 {
+ return fmt.Errorf("x/y coordinates must be >= 0")
+ }
+
+ return chromedp.Run(ctx,
+ chromedp.ActionFunc(func(ctx context.Context) error {
+ return chromedp.FromContext(ctx).Target.Execute(ctx, "Input.dispatchMouseEvent", map[string]any{
+ "type": "mouseMoved",
+ "x": x,
+ "y": y,
+ }, nil)
+ }),
+ chromedp.ActionFunc(func(ctx context.Context) error {
+ return chromedp.FromContext(ctx).Target.Execute(ctx, "Input.dispatchMouseEvent", map[string]any{
+ "type": "mouseWheel",
+ "x": x,
+ "y": y,
+ "deltaX": deltaX,
+ "deltaY": deltaY,
+ }, nil)
+ }),
+ )
+}
+
func HoverByNodeID(ctx context.Context, nodeID int64) error {
x, y, err := GetElementCenter(ctx, nodeID)
if err != nil {
diff --git a/internal/bridge/cdpops_facade.go b/internal/bridge/cdpops_facade.go
index ace55d5d..68e5dc04 100644
--- a/internal/bridge/cdpops_facade.go
+++ b/internal/bridge/cdpops_facade.go
@@ -67,6 +67,10 @@ func HoverByCoordinate(ctx context.Context, x, y float64) error {
return bridgecdpops.HoverByCoordinate(ctx, x, y)
}
+func ScrollByCoordinate(ctx context.Context, x, y float64, deltaX, deltaY int) error {
+ return bridgecdpops.ScrollByCoordinate(ctx, x, y, deltaX, deltaY)
+}
+
func HoverByNodeID(ctx context.Context, nodeID int64) error {
return bridgecdpops.HoverByNodeID(ctx, nodeID)
}
diff --git a/internal/handlers/health_tabs.go b/internal/handlers/health_tabs.go
index 6e544c53..a26606bb 100644
--- a/internal/handlers/health_tabs.go
+++ b/internal/handlers/health_tabs.go
@@ -5,6 +5,7 @@ import (
"net/http"
"time"
+ "github.com/chromedp/cdproto/target"
"github.com/pinchtab/pinchtab/internal/bridge"
"github.com/pinchtab/pinchtab/internal/engine"
"github.com/pinchtab/pinchtab/internal/httpx"
@@ -122,11 +123,16 @@ func (h *Handlers) HandleTabs(w http.ResponseWriter, r *http.Request) {
return
}
+ currentTabID := ""
+ if _, resolvedID, err := h.Bridge.TabContext(""); err == nil {
+ currentTabID = resolvedID
+ }
+
tabs := make([]map[string]any, 0, len(targets))
- for _, t := range targets {
+ appendTab := func(t *target.Info) {
// Skip the initial about:blank tab that Chrome creates on launch
if bridge.IsTransientURL(t.URL) {
- continue
+ return
}
tabID := string(t.TargetID)
entry := map[string]any{
@@ -141,5 +147,19 @@ func (h *Handlers) HandleTabs(w http.ResponseWriter, r *http.Request) {
}
tabs = append(tabs, entry)
}
+
+ // First pass: add the current focused tab
+ for _, t := range targets {
+ if string(t.TargetID) == currentTabID {
+ appendTab(t)
+ }
+ }
+ // Second pass: add all other tabs
+ for _, t := range targets {
+ if string(t.TargetID) == currentTabID {
+ continue
+ }
+ appendTab(t)
+ }
httpx.JSON(w, 200, map[string]any{"tabs": tabs})
}
diff --git a/internal/handlers/health_tabs_test.go b/internal/handlers/health_tabs_test.go
index 3b94be89..ab5930f0 100644
--- a/internal/handlers/health_tabs_test.go
+++ b/internal/handlers/health_tabs_test.go
@@ -173,6 +173,47 @@ func TestHandleTabs_Success(t *testing.T) {
}
}
+func TestHandleTabs_CurrentTrackedTabIsReturnedFirst(t *testing.T) {
+ mockBridge := &MockBridge{
+ targets: []*target.Info{
+ {TargetID: "tab1", URL: "https://pinchtab.com", Title: "Example", Type: "page"},
+ {TargetID: "tab2", URL: "https://google.com", Title: "Google", Type: "page"},
+ {TargetID: "tab3", URL: "https://example.com", Title: "Example 2", Type: "page"},
+ },
+ currentTabID: "tab2",
+ }
+
+ h := &Handlers{
+ Bridge: mockBridge,
+ Config: &config.RuntimeConfig{},
+ }
+
+ req := httptest.NewRequest("GET", "/tabs", nil)
+ w := httptest.NewRecorder()
+
+ h.HandleTabs(w, req)
+
+ if w.Code != http.StatusOK {
+ t.Fatalf("expected 200, got %d", w.Code)
+ }
+
+ var resp struct {
+ Tabs []struct {
+ ID string `json:"id"`
+ } `json:"tabs"`
+ }
+ if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
+ t.Fatalf("failed to parse response: %v", err)
+ }
+
+ if len(resp.Tabs) != 3 {
+ t.Fatalf("expected 3 tabs, got %d", len(resp.Tabs))
+ }
+ if resp.Tabs[0].ID != "tab2" {
+ t.Fatalf("expected current tracked tab first, got %q", resp.Tabs[0].ID)
+ }
+}
+
// TestHandleHealth_EnsureChromeFailure verifies /health returns 503 when Chrome initialization fails
func TestHandleHealth_EnsureChromeFailure(t *testing.T) {
mockBridge := &MockBridge{
@@ -309,6 +350,7 @@ type MockBridge struct {
listTargetsErr string
ensureChromeCalled bool
ensureChromeErr string
+ currentTabID string
}
func (m *MockBridge) ListTargets() ([]*target.Info, error) {
@@ -323,6 +365,9 @@ func (m *MockBridge) BrowserContext() context.Context {
}
func (m *MockBridge) TabContext(tabID string) (context.Context, string, error) {
+ if tabID == "" && m.currentTabID != "" {
+ return context.Background(), m.currentTabID, nil
+ }
return context.Background(), tabID, nil
}
diff --git a/internal/handlers/screencast.go b/internal/handlers/screencast.go
index b3303edc..c5b2bb56 100644
--- a/internal/handlers/screencast.go
+++ b/internal/handlers/screencast.go
@@ -3,68 +3,37 @@ package handlers
import (
"context"
"encoding/base64"
+ "errors"
"fmt"
"log/slog"
+ "net"
"net/http"
"sync"
"time"
+ "github.com/chromedp/cdproto/cdp"
"github.com/chromedp/cdproto/page"
+ "github.com/chromedp/cdproto/runtime"
"github.com/chromedp/chromedp"
"github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil"
+ "github.com/pinchtab/pinchtab/internal/assets"
"github.com/pinchtab/pinchtab/internal/httpx"
)
-const screencastRepaintStartJS = `(function() {
- const key = "__pinchtabScreencastRepaint";
- const state = globalThis[key] || (globalThis[key] = { refs: 0 });
- state.refs += 1;
- if (state.refs > 1) {
- return state.refs;
- }
-
- const el = document.createElement("div");
- el.id = "__pinchtab_screencast_repaint";
- el.setAttribute("aria-hidden", "true");
- el.style.cssText = "position:fixed;left:0;top:0;width:1px;height:1px;pointer-events:none;opacity:0.999;background:rgba(0,0,0,0.001);transform:translateZ(0);will-change:opacity;z-index:2147483647;";
- (document.body || document.documentElement).appendChild(el);
-
- state.element = el;
- state.animation = el.animate(
- [{ opacity: 0.999 }, { opacity: 1 }],
- { duration: 1000, iterations: Infinity, direction: "alternate", easing: "linear" }
- );
- return state.refs;
-})()`
-
-const screencastRepaintStopJS = `(function() {
- const key = "__pinchtabScreencastRepaint";
- const state = globalThis[key];
- if (!state) {
- return 0;
- }
-
- state.refs = Math.max(0, (state.refs || 1) - 1);
- if (state.refs > 0) {
- return state.refs;
- }
-
- try {
- if (state.animation) {
- state.animation.cancel();
- }
- } catch (_) {}
-
- try {
- if (state.element) {
- state.element.remove();
- }
- } catch (_) {}
-
- delete globalThis[key];
- return 0;
-})()`
+const screencastRepaintWorldName = "__pinchtab_screencast"
+
+var getScreencastFrameTree = func(ctx context.Context) (*page.FrameTree, error) {
+ return page.GetFrameTree().Do(ctx)
+}
+
+var createScreencastIsolatedWorld = func(ctx context.Context, params *page.CreateIsolatedWorldParams) (runtime.ExecutionContextID, error) {
+ return params.Do(ctx)
+}
+
+var evaluateScreencastInWorld = func(ctx context.Context, params *runtime.EvaluateParams) (*runtime.RemoteObject, *runtime.ExceptionDetails, error) {
+ return params.Do(ctx)
+}
// HandleScreencast upgrades to WebSocket and streams screencast frames for a tab.
// Query params: tabId (required), quality (1-100, default 40), maxWidth (default 800), fps (1-30, default 5)
@@ -112,27 +81,67 @@ func (h *Handlers) HandleScreencast(w http.ResponseWriter, r *http.Request) {
return
}
- stopRepaintLoop := func() {}
+ var once sync.Once
+ done := make(chan struct{})
+
+ slog.Info("screencast started", "tab", resolvedTabID, "quality", quality, "maxWidth", maxWidth)
+
+ go func() {
+ for {
+ _, _, err := wsutil.ReadClientData(conn)
+ if err != nil {
+ once.Do(func() { close(done) })
+ return
+ }
+ }
+ }()
+
if h.Config != nil && h.Config.Headless {
- stopRepaintLoop = startScreencastRepaintLoop(ctx)
+ h.streamHeadlessScreencast(ctx, conn, quality, minFrameInterval, done)
+ return
}
+ stopRepaintLoop := func() {}
frameCh := make(chan []byte, 3)
- var once sync.Once
- done := make(chan struct{})
+ ackCh := make(chan int64, 128)
+
+ go func() {
+ for {
+ select {
+ case sessionID := <-ackCh:
+ if err := chromedp.Run(ctx,
+ chromedp.ActionFunc(func(c context.Context) error {
+ return page.ScreencastFrameAck(sessionID).Do(c)
+ }),
+ ); err != nil && !errors.Is(err, context.Canceled) {
+ slog.Debug("screencast ack failed", "err", err, "tab", resolvedTabID)
+ }
+ case <-done:
+ return
+ }
+ }
+ }()
// Listen for screencast frames with rate limiting
var lastFrame time.Time
chromedp.ListenTarget(ctx, func(ev interface{}) {
switch e := ev.(type) {
case *page.EventScreencastFrame:
- go func() {
- _ = chromedp.Run(ctx,
- chromedp.ActionFunc(func(c context.Context) error {
- return page.ScreencastFrameAck(e.SessionID).Do(c)
- }),
- )
- }()
+ select {
+ case ackCh <- e.SessionID:
+ case <-done:
+ return
+ default:
+ go func(sessionID int64) {
+ if err := chromedp.Run(ctx,
+ chromedp.ActionFunc(func(c context.Context) error {
+ return page.ScreencastFrameAck(sessionID).Do(c)
+ }),
+ ); err != nil && !errors.Is(err, context.Canceled) {
+ slog.Debug("screencast ack fallback failed", "err", err, "tab", resolvedTabID)
+ }
+ }(e.SessionID)
+ }
now := time.Now()
if now.Sub(lastFrame) < minFrameInterval {
@@ -168,6 +177,8 @@ func (h *Handlers) HandleScreencast(w http.ResponseWriter, r *http.Request) {
return
}
+ stopRepaintLoop = startScreencastRepaintLoop(ctx)
+
defer func() {
once.Do(func() { close(done) })
stopRepaintLoop()
@@ -178,18 +189,6 @@ func (h *Handlers) HandleScreencast(w http.ResponseWriter, r *http.Request) {
)
}()
- slog.Info("screencast started", "tab", resolvedTabID, "quality", quality, "maxWidth", maxWidth)
-
- go func() {
- for {
- _, _, err := wsutil.ReadClientData(conn)
- if err != nil {
- once.Do(func() { close(done) })
- return
- }
- }
- }()
-
for {
select {
case frame := <-frameCh:
@@ -206,19 +205,117 @@ func (h *Handlers) HandleScreencast(w http.ResponseWriter, r *http.Request) {
}
}
+func (h *Handlers) streamHeadlessScreencast(ctx context.Context, conn net.Conn, quality int, frameInterval time.Duration, done <-chan struct{}) {
+ if frameInterval <= 0 {
+ frameInterval = time.Second
+ }
+
+ sendFrame := func() error {
+ frame, err := captureScreencastJPEG(ctx, quality)
+ if err != nil {
+ return err
+ }
+ return wsutil.WriteServerBinary(conn, frame)
+ }
+
+ if err := sendFrame(); err != nil {
+ return
+ }
+
+ frameTicker := time.NewTicker(frameInterval)
+ defer frameTicker.Stop()
+
+ pingTicker := time.NewTicker(10 * time.Second)
+ defer pingTicker.Stop()
+
+ for {
+ select {
+ case <-frameTicker.C:
+ if err := sendFrame(); err != nil {
+ return
+ }
+ case <-pingTicker.C:
+ if err := wsutil.WriteServerMessage(conn, ws.OpPing, nil); err != nil {
+ return
+ }
+ case <-done:
+ return
+ }
+ }
+}
+
+func captureScreencastJPEG(ctx context.Context, quality int) ([]byte, error) {
+ var buf []byte
+ err := chromedp.Run(ctx,
+ chromedp.ActionFunc(func(c context.Context) error {
+ var err error
+ buf, err = page.CaptureScreenshot().
+ WithFormat(page.CaptureScreenshotFormatJpeg).
+ WithQuality(int64(quality)).
+ Do(c)
+ return err
+ }),
+ )
+ if err != nil {
+ return nil, err
+ }
+ return buf, nil
+}
+
func startScreencastRepaintLoop(ctx context.Context) func() {
- if err := chromedp.Run(ctx, chromedp.Evaluate(screencastRepaintStartJS, nil)); err != nil {
+ execCtxID, err := createScreencastExecutionContext(ctx)
+ if err != nil {
+ slog.Warn("enable screencast repaint loop failed", "err", err)
+ return func() {}
+ }
+
+ if err := evaluateScreencastJS(ctx, execCtxID, assets.ScreencastRepaintStartJS); err != nil {
slog.Warn("enable screencast repaint loop failed", "err", err)
return func() {}
}
return func() {
- if err := chromedp.Run(ctx, chromedp.Evaluate(screencastRepaintStopJS, nil)); err != nil {
+ if err := evaluateScreencastJS(ctx, execCtxID, assets.ScreencastRepaintStopJS); err != nil {
slog.Warn("disable screencast repaint loop failed", "err", err)
}
}
}
+func createScreencastExecutionContext(ctx context.Context) (runtime.ExecutionContextID, error) {
+ frameTree, err := getScreencastFrameTree(ctx)
+ if err != nil {
+ return 0, fmt.Errorf("get frame tree: %w", err)
+ }
+ if frameTree == nil || frameTree.Frame == nil {
+ return 0, errors.New("missing top frame")
+ }
+
+ execCtxID, err := createScreencastIsolatedWorld(ctx, newScreencastIsolatedWorldParams(frameTree.Frame.ID))
+ if err != nil {
+ return 0, fmt.Errorf("create isolated world: %w", err)
+ }
+ return execCtxID, nil
+}
+
+func evaluateScreencastJS(ctx context.Context, execCtxID runtime.ExecutionContextID, expression string) error {
+ _, exceptionDetails, err := evaluateScreencastInWorld(ctx, newScreencastEvaluateParams(execCtxID, expression))
+ if err != nil {
+ return fmt.Errorf("evaluate in isolated world: %w", err)
+ }
+ if exceptionDetails != nil {
+ return fmt.Errorf("evaluate in isolated world: %w", exceptionDetails)
+ }
+ return nil
+}
+
+func newScreencastIsolatedWorldParams(frameID cdp.FrameID) *page.CreateIsolatedWorldParams {
+ return page.CreateIsolatedWorld(frameID).WithWorldName(screencastRepaintWorldName)
+}
+
+func newScreencastEvaluateParams(execCtxID runtime.ExecutionContextID, expression string) *runtime.EvaluateParams {
+ return runtime.Evaluate(expression).WithContextID(execCtxID)
+}
+
// HandleScreencastAll returns info for building a multi-tab screencast view.
func (h *Handlers) HandleScreencastAll(w http.ResponseWriter, r *http.Request) {
if !h.Config.AllowScreencast {
diff --git a/internal/handlers/screencast_test.go b/internal/handlers/screencast_test.go
index 8a58f839..654cb871 100644
--- a/internal/handlers/screencast_test.go
+++ b/internal/handlers/screencast_test.go
@@ -1,10 +1,15 @@
package handlers
import (
+ "context"
"net/http"
"net/http/httptest"
"testing"
+ "github.com/chromedp/cdproto/cdp"
+ "github.com/chromedp/cdproto/page"
+ "github.com/chromedp/cdproto/runtime"
+ "github.com/pinchtab/pinchtab/internal/assets"
"github.com/pinchtab/pinchtab/internal/authn"
"github.com/pinchtab/pinchtab/internal/config"
)
@@ -78,3 +83,92 @@ func TestHandleScreencast_Disabled(t *testing.T) {
t.Errorf("expected 403 when screencast disabled, got %d", w.Code)
}
}
+
+func TestCreateScreencastExecutionContext_UsesTopFrameNamedWorld(t *testing.T) {
+ origGetFrameTree := getScreencastFrameTree
+ origCreateWorld := createScreencastIsolatedWorld
+ defer func() {
+ getScreencastFrameTree = origGetFrameTree
+ createScreencastIsolatedWorld = origCreateWorld
+ }()
+
+ getScreencastFrameTree = func(context.Context) (*page.FrameTree, error) {
+ return &page.FrameTree{Frame: &cdp.Frame{ID: cdp.FrameID("frame-top")}}, nil
+ }
+
+ var gotParams *page.CreateIsolatedWorldParams
+ createScreencastIsolatedWorld = func(_ context.Context, params *page.CreateIsolatedWorldParams) (runtime.ExecutionContextID, error) {
+ gotParams = params
+ return runtime.ExecutionContextID(77), nil
+ }
+
+ execCtxID, err := createScreencastExecutionContext(context.Background())
+ if err != nil {
+ t.Fatalf("createScreencastExecutionContext returned error: %v", err)
+ }
+ if execCtxID != runtime.ExecutionContextID(77) {
+ t.Fatalf("createScreencastExecutionContext returned %v, want 77", execCtxID)
+ }
+ if gotParams == nil {
+ t.Fatal("createScreencastExecutionContext did not create isolated world params")
+ }
+ if gotParams.FrameID != cdp.FrameID("frame-top") {
+ t.Fatalf("isolated world frame id = %q, want %q", gotParams.FrameID, cdp.FrameID("frame-top"))
+ }
+ if gotParams.WorldName != screencastRepaintWorldName {
+ t.Fatalf("isolated world name = %q, want %q", gotParams.WorldName, screencastRepaintWorldName)
+ }
+}
+
+func TestStartScreencastRepaintLoop_ReusesExecutionContextForStop(t *testing.T) {
+ origGetFrameTree := getScreencastFrameTree
+ origCreateWorld := createScreencastIsolatedWorld
+ origEvaluate := evaluateScreencastInWorld
+ defer func() {
+ getScreencastFrameTree = origGetFrameTree
+ createScreencastIsolatedWorld = origCreateWorld
+ evaluateScreencastInWorld = origEvaluate
+ }()
+
+ getScreencastFrameTree = func(context.Context) (*page.FrameTree, error) {
+ return &page.FrameTree{Frame: &cdp.Frame{ID: cdp.FrameID("frame-top")}}, nil
+ }
+ createScreencastIsolatedWorld = func(_ context.Context, _ *page.CreateIsolatedWorldParams) (runtime.ExecutionContextID, error) {
+ return runtime.ExecutionContextID(91), nil
+ }
+
+ type evalCall struct {
+ ContextID runtime.ExecutionContextID
+ Expression string
+ }
+ var gotCalls []evalCall
+ evaluateScreencastInWorld = func(_ context.Context, params *runtime.EvaluateParams) (*runtime.RemoteObject, *runtime.ExceptionDetails, error) {
+ gotCalls = append(gotCalls, evalCall{
+ ContextID: params.ContextID,
+ Expression: params.Expression,
+ })
+ return &runtime.RemoteObject{}, nil, nil
+ }
+
+ stop := startScreencastRepaintLoop(context.Background())
+ if len(gotCalls) != 1 {
+ t.Fatalf("start calls = %d, want 1", len(gotCalls))
+ }
+ if gotCalls[0].ContextID != runtime.ExecutionContextID(91) {
+ t.Fatalf("start context id = %v, want 91", gotCalls[0].ContextID)
+ }
+ if gotCalls[0].Expression != assets.ScreencastRepaintStartJS {
+ t.Fatalf("start expression = %q, want screencast repaint start asset", gotCalls[0].Expression)
+ }
+
+ stop()
+ if len(gotCalls) != 2 {
+ t.Fatalf("start+stop calls = %d, want 2", len(gotCalls))
+ }
+ if gotCalls[1].ContextID != runtime.ExecutionContextID(91) {
+ t.Fatalf("stop context id = %v, want 91", gotCalls[1].ContextID)
+ }
+ if gotCalls[1].Expression != assets.ScreencastRepaintStopJS {
+ t.Fatalf("stop expression = %q, want screencast repaint stop asset", gotCalls[1].Expression)
+ }
+}
diff --git a/internal/orchestrator/health.go b/internal/orchestrator/health.go
index 2b99ef67..33163f20 100644
--- a/internal/orchestrator/health.go
+++ b/internal/orchestrator/health.go
@@ -27,6 +27,10 @@ func (o *Orchestrator) monitor(inst *InstanceInternal) {
}()
var waitErr error
started := time.Now()
+ probePort, portErr := parsePortNumber(inst.Port)
+ if portErr != nil {
+ lastProbe = portErr.Error()
+ }
for time.Since(started) < instanceStartupTimeout {
select {
case waitErr = <-waitCh:
@@ -36,9 +40,33 @@ func (o *Orchestrator) monitor(inst *InstanceInternal) {
if exitedEarly {
break
}
+ if portErr != nil {
+ break
+ }
time.Sleep(instanceHealthPollInterval)
- healthy, resolvedURL, lastProbe = o.probeInstanceHealth(inst)
+ // monitor only probes child bridge processes started by Launch.
+ // Attached remote bridges are validated and probed during attach.
+ for _, baseURL := range instanceBaseURLs(probePort) {
+ req, reqErr := http.NewRequest(http.MethodGet, baseURL+"/health", nil)
+ if reqErr != nil {
+ lastProbe = fmt.Sprintf("%s -> %s", baseURL, reqErr.Error())
+ continue
+ }
+ o.applyInstanceAuth(req, inst)
+ resp, err := o.client.Do(req)
+ if err == nil {
+ _ = resp.Body.Close()
+ lastProbe = fmt.Sprintf("%s -> HTTP %d", baseURL, resp.StatusCode)
+ if isInstanceHealthyStatus(resp.StatusCode) {
+ healthy = true
+ resolvedURL = baseURL
+ break
+ }
+ } else {
+ lastProbe = fmt.Sprintf("%s -> %s", baseURL, err.Error())
+ }
+ }
if healthy {
break
}
@@ -144,13 +172,29 @@ func (o *Orchestrator) checkAttachedBridgeHealth(inst *InstanceInternal) bool {
func (o *Orchestrator) probeInstanceHealth(inst *InstanceInternal) (bool, string, string) {
lastProbe := "no response"
- for _, baseURL := range instanceBaseURLs(inst.URL, inst.Port) {
- baseParsed, parseErr := url.Parse(baseURL)
- if parseErr != nil {
- lastProbe = fmt.Sprintf("%s -> %s", baseURL, parseErr.Error())
+ var baseURLs []string
+ if inst.URL != "" {
+ baseURLs = []string{strings.TrimRight(inst.URL, "/")}
+ } else {
+ probePort, err := parsePortNumber(inst.Port)
+ if err != nil {
+ return false, "", err.Error()
+ }
+ baseURLs = instanceBaseURLs(probePort)
+ }
+
+ for _, baseURL := range baseURLs {
+ parsed, err := url.Parse(baseURL)
+ if err != nil {
+ lastProbe = fmt.Sprintf("%s -> %s", baseURL, err.Error())
continue
}
- target := &url.URL{Scheme: baseParsed.Scheme, Host: baseParsed.Host, Path: "/health"}
+ target := &url.URL{
+ Scheme: parsed.Scheme,
+ Host: parsed.Host,
+ Path: "/health",
+ }
+
req, reqErr := http.NewRequest(http.MethodGet, target.String(), nil)
if reqErr != nil {
lastProbe = fmt.Sprintf("%s -> %s", baseURL, reqErr.Error())
@@ -252,13 +296,10 @@ func isInstanceHealthyStatus(code int) bool {
return code > 0 && code < http.StatusInternalServerError
}
-func instanceBaseURLs(rawURL, port string) []string {
- if rawURL != "" {
- return []string{strings.TrimRight(rawURL, "/")}
- }
+func instanceBaseURLs(port int) []string {
return []string{
- fmt.Sprintf("http://127.0.0.1:%s", port),
- fmt.Sprintf("http://[::1]:%s", port),
- fmt.Sprintf("http://localhost:%s", port),
+ fmt.Sprintf("http://127.0.0.1:%d", port),
+ fmt.Sprintf("http://[::1]:%d", port),
+ fmt.Sprintf("http://localhost:%d", port),
}
}
diff --git a/internal/orchestrator/health_test.go b/internal/orchestrator/health_test.go
index 447fcbd2..51440594 100644
--- a/internal/orchestrator/health_test.go
+++ b/internal/orchestrator/health_test.go
@@ -26,8 +26,7 @@ func TestIsInstanceHealthyStatus(t *testing.T) {
}
func TestInstanceBaseURLs(t *testing.T) {
- port := "1234"
- urls := instanceBaseURLs("", port)
+ urls := instanceBaseURLs(1234)
expected := []string{
"http://127.0.0.1:1234",
@@ -45,13 +44,3 @@ func TestInstanceBaseURLs(t *testing.T) {
}
}
}
-
-func TestInstanceBaseURLs_UsesCanonicalURLWhenPresent(t *testing.T) {
- urls := instanceBaseURLs("https://bridge.example.com:9868/", "1234")
- if len(urls) != 1 {
- t.Fatalf("expected 1 URL, got %d", len(urls))
- }
- if urls[0] != "https://bridge.example.com:9868" {
- t.Fatalf("url = %q, want %q", urls[0], "https://bridge.example.com:9868")
- }
-}
diff --git a/internal/orchestrator/orchestrator.go b/internal/orchestrator/orchestrator.go
index a88725d1..a17e6b68 100644
--- a/internal/orchestrator/orchestrator.go
+++ b/internal/orchestrator/orchestrator.go
@@ -264,13 +264,16 @@ func (o *Orchestrator) Launch(name, port string, headless bool, extensionPaths [
o.mu.Lock()
} else {
o.mu.Unlock()
- if portInt, err := strconv.Atoi(port); err == nil {
- if err := o.portAllocator.ReservePort(portInt); err != nil {
- return nil, fmt.Errorf("failed to reserve port %s: %w", port, err)
- }
- if portInt >= o.portAllocator.start && portInt <= o.portAllocator.end {
- reservedPorts = append(reservedPorts, portInt)
- }
+ portInt, err := parsePortNumber(port)
+ if err != nil {
+ return nil, err
+ }
+ port = strconv.Itoa(portInt)
+ if err := o.portAllocator.ReservePort(portInt); err != nil {
+ return nil, fmt.Errorf("failed to reserve port %s: %w", port, err)
+ }
+ if portInt >= o.portAllocator.start && portInt <= o.portAllocator.end {
+ reservedPorts = append(reservedPorts, portInt)
}
o.mu.Lock()
}
diff --git a/internal/orchestrator/orchestrator_test.go b/internal/orchestrator/orchestrator_test.go
index 024e4d6f..089157e1 100644
--- a/internal/orchestrator/orchestrator_test.go
+++ b/internal/orchestrator/orchestrator_test.go
@@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"os"
+ "strconv"
"strings"
"testing"
@@ -189,7 +190,7 @@ func TestOrchestrator_Launch_AcceptsValidNames(t *testing.T) {
for i, name := range validNames {
t.Run(name, func(t *testing.T) {
port := 9100 + i
- inst, err := o.Launch(name, string(rune('0'+port%10))+string(rune('0'+(port/10)%10))+string(rune('0'+(port/100)%10))+string(rune('0'+(port/1000)%10)), true, nil)
+ inst, err := o.Launch(name, strconv.Itoa(port), true, nil)
if err != nil {
t.Errorf("Launch(%q) unexpected error: %v", name, err)
return
@@ -201,6 +202,17 @@ func TestOrchestrator_Launch_AcceptsValidNames(t *testing.T) {
}
}
+func TestOrchestrator_Launch_RejectsInvalidPort(t *testing.T) {
+ runner := &mockRunner{portAvail: true}
+ o := NewOrchestratorWithRunner(t.TempDir(), runner)
+
+ for _, raw := range []string{"abc", "0x1234", "65536"} {
+ if _, err := o.Launch("profile1", raw, true, nil); err == nil {
+ t.Fatalf("Launch should reject invalid port %q", raw)
+ }
+ }
+}
+
func TestOrchestrator_Launch_ReservesDistinctChromeDebugPort(t *testing.T) {
old := processAliveFunc
processAliveFunc = func(pid int) bool { return pid > 0 }
diff --git a/internal/orchestrator/ports.go b/internal/orchestrator/ports.go
index d989149a..ec9668b0 100644
--- a/internal/orchestrator/ports.go
+++ b/internal/orchestrator/ports.go
@@ -4,6 +4,8 @@ import (
"fmt"
"log/slog"
"net"
+ "strconv"
+ "strings"
"sync"
)
@@ -122,3 +124,18 @@ func isPortAvailableInt(port int) bool {
_ = listener.Close()
return true
}
+
+func parsePortNumber(port string) (int, error) {
+ value := strings.TrimSpace(port)
+ if len(value) > 1 && value[0] == '0' {
+ return 0, fmt.Errorf("invalid port %q: leading zeros not allowed", port)
+ }
+ portNum, err := strconv.Atoi(value)
+ if err != nil {
+ return 0, fmt.Errorf("invalid port %q", port)
+ }
+ if portNum < 1 || portNum > 65535 {
+ return 0, fmt.Errorf("port %d out of range", portNum)
+ }
+ return portNum, nil
+}
diff --git a/internal/orchestrator/ports_test.go b/internal/orchestrator/ports_test.go
new file mode 100644
index 00000000..95527c87
--- /dev/null
+++ b/internal/orchestrator/ports_test.go
@@ -0,0 +1,21 @@
+package orchestrator
+
+import "testing"
+
+func TestParsePortNumber(t *testing.T) {
+ port, err := parsePortNumber("1234")
+ if err != nil {
+ t.Fatalf("parsePortNumber returned error: %v", err)
+ }
+ if port != 1234 {
+ t.Fatalf("port = %d, want 1234", port)
+ }
+}
+
+func TestParsePortNumber_RejectsInvalidValues(t *testing.T) {
+ for _, raw := range []string{"", "abc", "0", "65536", "001234", "0x1234"} {
+ if _, err := parsePortNumber(raw); err == nil {
+ t.Fatalf("parsePortNumber(%q) should reject invalid port", raw)
+ }
+ }
+}
diff --git a/internal/orchestrator/process.go b/internal/orchestrator/process.go
index 247ec8b9..fa9d7326 100644
--- a/internal/orchestrator/process.go
+++ b/internal/orchestrator/process.go
@@ -1,6 +1,7 @@
package orchestrator
import (
+ "fmt"
"net"
"sort"
"strings"
@@ -39,7 +40,11 @@ func isProcessAlive(pid int) bool {
}
func isPortAvailable(port string) bool {
- ln, err := net.Listen("tcp", ":"+port)
+ portNum, err := parsePortNumber(port)
+ if err != nil {
+ return false
+ }
+ ln, err := net.Listen("tcp", fmt.Sprintf(":%d", portNum))
if err != nil {
return false
}
diff --git a/scripts/dev-dashboard.sh b/scripts/dev-dashboard.sh
index b9e61336..c9a4e7f1 100755
--- a/scripts/dev-dashboard.sh
+++ b/scripts/dev-dashboard.sh
@@ -1,18 +1,17 @@
#!/bin/bash
-# dev-dashboard.sh — Run pinchtab + Vite dev server for hot-reload dashboard development
+# dev-dashboard.sh — full-stack dashboard development with frontend hot reload
+# and backend auto-rebuild/restart.
#
# This starts:
-# 1. pinchtab backend (Go) on port 9867
+# 1. pinchtab backend (Go) on port 9867, rebuilt on file changes
# 2. Vite dev server (React) on port 5173 with proxy to backend
#
# Access the dashboard at:
-# - http://localhost:5173/dashboard/ (hot reload via Vite)
-# - http://localhost:9867/dashboard/ (backend-served build, no hot reload)
-# Changes to dashboard/src/* will hot-reload instantly.
+# - http://localhost:5173/dashboard/ (use this during development)
#
-# Usage: ./scripts/dev-dashboard.sh [pinchtab args...]
+# Usage: ./scripts/dev-dashboard.sh [pinchtab server args...]
-set -e
+set -euo pipefail
cd "$(dirname "$0")/.."
@@ -20,79 +19,243 @@ BOLD=$'\033[1m'
ACCENT=$'\033[38;2;251;191;36m'
MUTED=$'\033[38;2;90;100;128m'
SUCCESS=$'\033[38;2;0;229;204m'
+ERROR=$'\033[38;2;255;107;107m'
NC=$'\033[0m'
+DEV_PORT=${PINCHTAB_DEV_PORT:-9867}
+SERVER_ARGS=("$@")
+WATCH_INTERVAL_SECONDS="${PINCHTAB_DEV_WATCH_INTERVAL:-1}"
+DEV_TOKEN=""
+DEV_CONFIG=""
+BACKEND_PID=""
+VITE_PID=""
+LAST_BACKEND_SIGNATURE=""
+GO_BUILD_CACHE_DIR="${PWD}/.gocache/build"
+GO_MOD_CACHE_DIR="${PWD}/.gocache/mod"
+
cleanup() {
+ trap - SIGINT SIGTERM EXIT
echo ""
echo " ${MUTED}Shutting down...${NC}"
- kill $BACKEND_PID 2>/dev/null || true
- kill $VITE_PID 2>/dev/null || true
- [ -n "${DEV_CONFIG:-}" ] && rm -f "$DEV_CONFIG" 2>/dev/null
+ if [ -n "${BACKEND_PID:-}" ]; then
+ kill "${BACKEND_PID}" 2>/dev/null || true
+ wait "${BACKEND_PID}" 2>/dev/null || true
+ fi
+ if [ -n "${VITE_PID:-}" ]; then
+ kill "${VITE_PID}" 2>/dev/null || true
+ wait "${VITE_PID}" 2>/dev/null || true
+ fi
+ if [ -n "${DEV_CONFIG:-}" ] && [ -f "${DEV_CONFIG}" ]; then
+ rm -f "${DEV_CONFIG}" 2>/dev/null || true
+ fi
exit 0
}
-trap cleanup SIGINT SIGTERM
+trap cleanup SIGINT SIGTERM EXIT
-echo ""
-echo " ${ACCENT}${BOLD}🔥 Dashboard Hot-Reload Dev Mode${NC}"
-echo ""
+watch_signature() {
+ local files=()
+ while IFS= read -r file; do
+ files+=("$file")
+ done < <(
+ find cmd internal \
+ -type f \
+ \( \
+ -name '*.go' -o \
+ -name '*.js' -o \
+ -name '*.json' \
+ \) \
+ | sort
+ )
-# Build Go binary (without embedded dashboard - it won't be used)
-echo " ${MUTED}Building Go backend...${NC}"
-go build -o pinchtab ./cmd/pinchtab
+ files+=("go.mod" "go.sum")
-# Start backend on port 9867 (matches Vite proxy target)
-DEV_PORT=${PINCHTAB_DEV_PORT:-9867}
-DEV_CONFIG=$(mktemp -d)/pinchtab.json
-echo "{\"server\":{\"port\":\"${DEV_PORT}\"}}" > "$DEV_CONFIG"
-echo " ${MUTED}Starting pinchtab backend on :${DEV_PORT}...${NC}"
-PINCHTAB_CONFIG="$DEV_CONFIG" ./pinchtab server "$@" &
-BACKEND_PID=$!
-
-# Wait for backend to be ready
-echo " ${MUTED}Waiting for backend...${NC}"
-for i in {1..30}; do
- if curl -s http://localhost:${DEV_PORT}/health >/dev/null 2>&1; then
- break
+ if [ "${#files[@]}" -eq 0 ]; then
+ echo ""
+ return
fi
- sleep 0.5
-done
-if ! curl -s http://localhost:${DEV_PORT}/health >/dev/null 2>&1; then
- echo " ${BOLD}Backend failed to start${NC}"
- kill $BACKEND_PID 2>/dev/null || true
- exit 1
-fi
+ shasum "${files[@]}" 2>/dev/null | shasum | awk '{print $1}'
+}
-echo " ${SUCCESS}✓${NC} Backend ready"
-echo ""
+load_token_from_config() {
+ local config_path=""
+ local config_token=""
+
+ if [ ! -x "./pinchtab-dev" ]; then
+ return
+ fi
+
+ config_path="$(./pinchtab-dev config path 2>/dev/null | tail -n 1)"
+ if [ -z "${config_path}" ] || [ ! -f "${config_path}" ]; then
+ return
+ fi
+
+ config_token="$(sed -nE 's/.*"token"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/p' "${config_path}" | head -n 1)"
+ if [ -n "${config_token}" ]; then
+ DEV_TOKEN="${config_token}"
+ fi
+}
+
+build_backend() {
+ local target="./pinchtab-dev"
+ echo " ${MUTED}Building Go backend...${NC}"
+ mkdir -p "${GO_BUILD_CACHE_DIR}" "${GO_MOD_CACHE_DIR}"
+ if GOCACHE="${GO_BUILD_CACHE_DIR}" GOMODCACHE="${GO_MOD_CACHE_DIR}" go build -o "${target}" ./cmd/pinchtab; then
+ echo " ${SUCCESS}✓${NC} Backend build succeeded"
+ return 0
+ fi
+
+ echo " ${ERROR}✗${NC} Backend build failed. Keeping the last good server running."
+ return 1
+}
-# Start Vite dev server
-echo " ${MUTED}Starting Vite dev server on :5173...${NC}"
-cd dashboard
+resolve_dev_token() {
+ if [ -n "${PINCHTAB_TOKEN:-}" ]; then
+ DEV_TOKEN="${PINCHTAB_TOKEN}"
+ return 0
+ fi
+
+ load_token_from_config
+ if [ -n "${DEV_TOKEN}" ]; then
+ return 0
+ fi
+
+ echo " ${ERROR}✗${NC} No server token found in your current PinchTab config."
+ echo " ${MUTED}Set PINCHTAB_TOKEN or add server.token to your normal config, then retry.${NC}"
+ return 1
+}
+
+wait_for_backend() {
+ local tries=0
+ while [ "${tries}" -lt 30 ]; do
+ if curl -fsS -H "Authorization: Bearer ${DEV_TOKEN}" "http://localhost:${DEV_PORT}/health" >/dev/null 2>&1; then
+ return 0
+ fi
+ tries=$((tries + 1))
+ sleep 0.5
+ done
+ return 1
+}
-if command -v bun >/dev/null 2>&1; then
- bun run dev &
-else
- npm run dev &
+start_backend() {
+ if ! build_backend; then
+ return 1
+ fi
+
+ if [ -n "${BACKEND_PID:-}" ]; then
+ kill "${BACKEND_PID}" 2>/dev/null || true
+ wait "${BACKEND_PID}" 2>/dev/null || true
+ BACKEND_PID=""
+ fi
+
+ echo " ${MUTED}Starting pinchtab backend on :${DEV_PORT}...${NC}"
+ PINCHTAB_CONFIG="${DEV_CONFIG}" PINCHTAB_TOKEN="${DEV_TOKEN}" ./pinchtab-dev server "${SERVER_ARGS[@]}" &
+ BACKEND_PID=$!
+
+ if wait_for_backend; then
+ echo " ${SUCCESS}✓${NC} Backend ready"
+ return 0
+ fi
+
+ echo " ${ERROR}✗${NC} Backend failed to start"
+ kill "${BACKEND_PID}" 2>/dev/null || true
+ wait "${BACKEND_PID}" 2>/dev/null || true
+ BACKEND_PID=""
+ return 1
+}
+
+start_vite() {
+ echo " ${MUTED}Starting Vite dev server on :5173...${NC}"
+ cd dashboard
+
+ if command -v bun >/dev/null 2>&1; then
+ PINCHTAB_DEV_PORT="${DEV_PORT}" PINCHTAB_TOKEN="${DEV_TOKEN}" bun run dev &
+ else
+ PINCHTAB_DEV_PORT="${DEV_PORT}" PINCHTAB_TOKEN="${DEV_TOKEN}" npm run dev &
+ fi
+ VITE_PID=$!
+
+ cd ..
+}
+
+monitor_backend_changes() {
+ LAST_BACKEND_SIGNATURE="$(watch_signature)"
+
+ while true; do
+ sleep "${WATCH_INTERVAL_SECONDS}"
+
+ if [ -n "${BACKEND_PID:-}" ] && ! kill -0 "${BACKEND_PID}" 2>/dev/null; then
+ echo ""
+ echo " ${ERROR}Backend process exited. Restarting...${NC}"
+ start_backend || true
+ LAST_BACKEND_SIGNATURE="$(watch_signature)"
+ continue
+ fi
+
+ local current_signature
+ current_signature="$(watch_signature)"
+ if [ "${current_signature}" = "${LAST_BACKEND_SIGNATURE}" ]; then
+ continue
+ fi
+
+ LAST_BACKEND_SIGNATURE="${current_signature}"
+ echo ""
+ echo " ${ACCENT}${BOLD}↻ Change detected${NC}"
+ start_backend || true
+ done
+}
+
+echo ""
+echo " ${ACCENT}${BOLD}🔥 Dashboard Full-Stack Dev Mode${NC}"
+echo ""
+
+if ! resolve_dev_token; then
+ exit 1
fi
-VITE_PID=$!
-cd ..
+DEV_CONFIG="$(mktemp -t pinchtab-dev-config.XXXXXX)"
+cat > "${DEV_CONFIG}" <<EOF
+{
+ "configVersion": "0.8.0",
+ "server": {
+ "bind": "127.0.0.1",
+ "port": "${DEV_PORT}",
+ "token": "${DEV_TOKEN}"
+ },
+ "security": {
+ "allowEvaluate": true,
+ "allowMacro": true,
+ "allowScreencast": true,
+ "allowDownload": true,
+ "allowUpload": true,
+ "idpi": {
+ "enabled": false,
+ "strictMode": false,
+ "scanContent": false,
+ "wrapContent": false
+ }
+ }
+}
+EOF
-# Wait for Vite
-sleep 3
+if ! start_backend; then
+ exit 1
+fi
+
+echo ""
+start_vite
echo ""
echo " ${SUCCESS}${BOLD}✓ Ready!${NC}"
echo ""
-echo " ${BOLD}Hot reload at:${NC} ${ACCENT}http://localhost:5173/dashboard/${NC}"
-echo " ${BOLD}Dashboard:${NC} ${ACCENT}http://localhost:${DEV_PORT}/dashboard/${NC}"
+echo " ${BOLD}Use:${NC} ${ACCENT}http://localhost:5173/dashboard/${NC}"
echo " ${BOLD}Backend:${NC} http://localhost:${DEV_PORT}"
echo ""
-echo " ${MUTED}Edit dashboard/src/* and use the Vite URL above for live updates.${NC}"
+echo " ${MUTED}Frontend changes hot-reload through Vite.${NC}"
+echo " ${MUTED}Backend changes rebuild and restart the server automatically.${NC}"
+echo " ${MUTED}The Vite proxy uses your configured PinchTab token automatically.${NC}"
echo " ${MUTED}Press Ctrl+C to stop.${NC}"
echo ""
-# Wait for either process to exit
-wait $BACKEND_PID $VITE_PID
+monitor_backend_changes
diff --git a/tests/e2e/scenarios-api/dashboard-full.sh b/tests/e2e/scenarios-api/dashboard-full.sh
new file mode 100644
index 00000000..ec78c770
--- /dev/null
+++ b/tests/e2e/scenarios-api/dashboard-full.sh
@@ -0,0 +1,171 @@
+#!/bin/bash
+# dashboard-full.sh — API full dashboard scenarios.
+
+GROUP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+source "${GROUP_DIR}/../helpers/api.sh"
+
+if [ -z "${E2E_FULL_SERVER:-}" ]; then
+ echo " E2E_FULL_SERVER not set, skipping dashboard full scenarios"
+ return 0 2>/dev/null || exit 0
+fi
+
+DASHBOARD_OLD_SERVER=""
+DASHBOARD_WS_HEADERS_FILE=""
+DASHBOARD_WS_BODY_FILE=""
+DASHBOARD_WS_PID=""
+DASHBOARD_WS_STATUS=""
+DASHBOARD_FRAME_BYTES=0
+DASHBOARD_TAB_ID=""
+DASHBOARD_INST_ID=""
+
+dashboard_use_full_server() {
+ DASHBOARD_OLD_SERVER="$E2E_SERVER"
+ E2E_SERVER="${E2E_FULL_SERVER:-$E2E_SERVER}"
+}
+
+dashboard_restore_server() {
+ if [ -n "${DASHBOARD_OLD_SERVER}" ]; then
+ E2E_SERVER="${DASHBOARD_OLD_SERVER}"
+ DASHBOARD_OLD_SERVER=""
+ fi
+}
+
+dashboard_cleanup_screencast() {
+ if [ -n "${DASHBOARD_WS_PID}" ]; then
+ kill "${DASHBOARD_WS_PID}" 2>/dev/null || true
+ wait "${DASHBOARD_WS_PID}" 2>/dev/null || true
+ DASHBOARD_WS_PID=""
+ fi
+ rm -f "${DASHBOARD_WS_HEADERS_FILE}" "${DASHBOARD_WS_BODY_FILE}"
+ DASHBOARD_WS_HEADERS_FILE=""
+ DASHBOARD_WS_BODY_FILE=""
+}
+
+dashboard_assert_instance_found() {
+ pt_get /instances
+ DASHBOARD_INST_ID=$(echo "$RESULT" | jq -r '.[0].id // empty')
+ if [ -n "${DASHBOARD_INST_ID}" ]; then
+ echo -e " ${GREEN}✓${NC} found instance for screencast proxy: ${DASHBOARD_INST_ID}"
+ ((ASSERTIONS_PASSED++)) || true
+ else
+ echo -e " ${RED}✗${NC} could not find instance for screencast proxy"
+ ((ASSERTIONS_FAILED++)) || true
+ fi
+}
+
+dashboard_start_screencast_stream() {
+ DASHBOARD_WS_HEADERS_FILE=$(mktemp)
+ DASHBOARD_WS_BODY_FILE=$(mktemp)
+ (
+ e2e_curl -s --http1.1 \
+ -X GET \
+ "${E2E_SERVER}/instances/${DASHBOARD_INST_ID}/proxy/screencast?tabId=${DASHBOARD_TAB_ID}&fps=5&everyNthFrame=1&quality=20&maxWidth=320" \
+ -D "${DASHBOARD_WS_HEADERS_FILE}" \
+ -o "${DASHBOARD_WS_BODY_FILE}" \
+ -H "Origin: ${E2E_SERVER}" \
+ -H "Connection: Upgrade" \
+ -H "Upgrade: websocket" \
+ -H "Sec-WebSocket-Version: 13" \
+ -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" \
+ --max-time 5 >/dev/null 2>&1 || true
+ ) &
+ DASHBOARD_WS_PID=$!
+
+ DASHBOARD_WS_STATUS=""
+ for _ in $(seq 1 20); do
+ DASHBOARD_WS_STATUS=$(grep '^HTTP/' "${DASHBOARD_WS_HEADERS_FILE}" | tail -n 1 | awk '{print $2}')
+ if [ -n "${DASHBOARD_WS_STATUS}" ]; then
+ break
+ fi
+ sleep 0.2
+ done
+}
+
+dashboard_assert_screencast_streaming() {
+ if [ "${DASHBOARD_WS_STATUS}" = "101" ]; then
+ echo -e " ${GREEN}✓${NC} screencast websocket upgraded"
+ ((ASSERTIONS_PASSED++)) || true
+ else
+ echo -e " ${RED}✗${NC} screencast websocket upgrade failed (status: ${DASHBOARD_WS_STATUS:-none})"
+ ((ASSERTIONS_FAILED++)) || true
+ fi
+
+ DASHBOARD_FRAME_BYTES=0
+ if [ "${DASHBOARD_WS_STATUS}" = "101" ]; then
+ for _ in $(seq 1 20); do
+ DASHBOARD_FRAME_BYTES=$(wc -c < "${DASHBOARD_WS_BODY_FILE}" | tr -d '[:space:]')
+ if [ "${DASHBOARD_FRAME_BYTES}" -gt 0 ]; then
+ break
+ fi
+ sleep 0.2
+ done
+ fi
+
+ if [ "${DASHBOARD_FRAME_BYTES}" -gt 0 ]; then
+ echo -e " ${GREEN}✓${NC} screencast streamed bytes (${DASHBOARD_FRAME_BYTES})"
+ ((ASSERTIONS_PASSED++)) || true
+ else
+ echo -e " ${RED}✗${NC} screencast did not stream any bytes"
+ ((ASSERTIONS_FAILED++)) || true
+ fi
+}
+
+dashboard_assert_screencast_continues() {
+ local label="$1"
+ local before_bytes="${DASHBOARD_FRAME_BYTES:-0}"
+ local current_bytes="$before_bytes"
+
+ if [ "${DASHBOARD_WS_STATUS}" = "101" ]; then
+ for _ in $(seq 1 20); do
+ current_bytes=$(wc -c < "${DASHBOARD_WS_BODY_FILE}" | tr -d '[:space:]')
+ if [ "${current_bytes}" -gt "${before_bytes}" ]; then
+ break
+ fi
+ sleep 0.2
+ done
+ fi
+
+ if [ "${current_bytes}" -gt "${before_bytes}" ]; then
+ DASHBOARD_FRAME_BYTES="${current_bytes}"
+ echo -e " ${GREEN}✓${NC} screencast kept streaming ${label} (${current_bytes} bytes)"
+ ((ASSERTIONS_PASSED++)) || true
+ else
+ echo -e " ${RED}✗${NC} screencast stopped streaming ${label}"
+ ((ASSERTIONS_FAILED++)) || true
+ fi
+}
+
+dashboard_assert_screencast_hidden() {
+ local label="$1"
+ pt_post /evaluate -d '{"expression":"({ hasGlobal: Object.prototype.hasOwnProperty.call(globalThis, \"__pinchtabScreencastRepaint\"), hasIdentifiableElement: !!document.querySelector(\"[id*=pinchtab],[class*=pinchtab],[data-pinchtab]\") })"}'
+ assert_ok "evaluate main world ${label}"
+ assert_result_eq ".result.hasGlobal" "false" "main world cannot see screencast global ${label}"
+ assert_result_eq ".result.hasIdentifiableElement" "false" "no pinchtab-identifiable element leaks into DOM ${label}"
+}
+
+# ─────────────────────────────────────────────────────────────────
+start_test "dashboard: screencast injection stays isolated from main world"
+
+dashboard_use_full_server
+
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/evaluate.html\"}"
+assert_ok "navigate for screencast isolation"
+DASHBOARD_TAB_ID=$(get_tab_id)
+sleep 1
+
+dashboard_assert_instance_found
+dashboard_start_screencast_stream
+dashboard_assert_screencast_streaming
+dashboard_assert_screencast_hidden "during screencast"
+
+pt_post /action -d '{"kind":"scroll","scrollY":100}'
+assert_ok "scroll while screencast active"
+sleep 1
+
+dashboard_assert_screencast_continues "after scroll"
+dashboard_assert_screencast_hidden "after scroll"
+
+dashboard_cleanup_screencast
+dashboard_restore_server
+
+end_test