Skip to content

Commit b576dcd

Browse files
revert: revert broken chrome-devtools-mcp + browser panel PRs, will re-implement
* Revert "feat(desktop): add embedded browser panel with WebContentsView (anomalyco#1671)" This reverts commit 610ae1c. * Revert "feat(desktop): bundle chrome-devtools-mcp as dependency, eliminate npx requirement (anomalyco#1670)" This reverts commit fe9881b. * feat(desktop): bundle chrome-devtools-mcp + embedded browser panel (fixed) Re-implements both features with fixes for the issues found in anomalyco#1670/anomalyco#1671: Fixes from PR1 (chrome-devtools-mcp bundling): - Use 'node' string literal instead of process.execPath in the IPC handler — process.execPath in Electron is the Electron binary, not node, so OpenCode couldn't spawn the command - Fix args filter to only carry --prefixed flags (not -y from npx) - Fix mcp.add fallback path to use resolved command from mcpEntryConfig instead of the original entry.command Fixes from PR2 (embedded browser panel): - Guard against zero-dimension bounds on first render — skip browser.show() until the panel has non-zero dimensions, let ResizeObserver trigger the actual show - Defensive try/catch in destroyBrowserView for already-destroyed webContents Verified: - resolveChromeDevtoolsMcpBin returns ['node', '<abs-path>'] (not ['Electron', '<path>']) - All 17 existing tests pass - Electron app starts and loads successfully - CDP targets visible at the remote debugging port * feat(desktop): auto-inject chrome-devtools MCP into opencode.json on engine start When the OpenCode engine starts in the Electron desktop app, ensureOpencodeConfig now automatically adds a chrome-devtools MCP entry to opencode.json if one doesn't already exist. The command uses the bundled chrome-devtools-mcp package (['node', '<abs-path>']) so no npm/npx is needed at runtime. This mirrors what Tauri's ensure_workspace_files() does in files.rs for the starter preset, making Control Chrome a zero-setup default for all Electron workspaces. * fix(desktop): seed chrome-devtools MCP at workspace creation time ensureOpencodeConfig in runtime.mjs only runs when the OpenCode engine starts, which happens asynchronously after the workspace is selected. New workspaces were left without a chrome-devtools entry because the engine hadn't started yet. Fix: call seedChromeDevtoolsMcp(folderPath) directly inside the workspaceCreate IPC handler so the config is written synchronously during workspace creation. The runtime.mjs ensureOpencodeConfig remains as a backup for workspaces created before this change. Verified: created a workspace via IPC, confirmed opencode.jsonc contains chrome-devtools with ['node', '<bundled-bin-path>']. * fix(desktop): migrate legacy npx/bare chrome-devtools commands to bundled node path Existing workspaces created by Tauri or older Electron versions have chrome-devtools MCP entries with npx-based or bare-binary commands like ['npx','-y','chrome-devtools-mcp@latest'] or ['chrome-devtools-mcp']. Both seedChromeDevtoolsMcp (main.mjs, runs at workspace creation) and ensureOpencodeConfig (runtime.mjs, runs at engine start) now detect these legacy commands and migrate them to the bundled ['node', path] command. User-customised commands (absolute paths, etc.) are preserved.
1 parent 610ae1c commit b576dcd

11 files changed

Lines changed: 229 additions & 442 deletions

File tree

‎apps/app/src/app/lib/desktop.ts‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,9 @@ declare global {
5050
forward?: () => Promise<void>;
5151
reload?: () => Promise<void>;
5252
setBounds?: (bounds: { x: number; y: number; width: number; height: number }) => Promise<void>;
53-
getState?: () => Promise<{
54-
url: string;
55-
title: string;
56-
canGoBack: boolean;
57-
canGoForward: boolean;
58-
isLoading: boolean;
59-
} | null>;
53+
getState?: () => Promise<{ url: string; title: string; canGoBack: boolean; canGoForward: boolean; isLoading: boolean } | null>;
6054
destroy?: () => Promise<void>;
61-
onStateChange?: (callback: (state: {
62-
url: string;
63-
title: string;
64-
canGoBack: boolean;
65-
canGoForward: boolean;
66-
isLoading: boolean;
67-
}) => void) => () => void;
55+
onStateChange?: (callback: (state: { url: string; title: string; canGoBack: boolean; canGoForward: boolean; isLoading: boolean }) => void) => () => void;
6856
};
6957
meta?: {
7058
initialDeepLinks?: string[];

‎apps/app/src/react-app/domains/connections/store.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,12 @@ export function createConnectionsStore(options: {
499499
}
500500

501501
// For chrome-devtools in Electron, resolve the bundled binary so we
502-
// don't need npx/npm at runtime.
502+
// don't need npx/npm at runtime. Only carry over -- prefixed flags
503+
// from the original command (skip npx flags like -y).
503504
let resolvedCommand = entry.command;
504505
if (slug === CHROME_DEVTOOLS_MCP_ID && isElectronRuntime()) {
505506
const bundled = await resolveChromeDevtoolsMcpCommand();
506-
// Preserve any extra args (e.g. --autoConnect) from the original
507-
const extraArgs = entry.command.filter(
508-
(arg) => arg.startsWith("--") || arg.startsWith("-"),
509-
);
507+
const extraArgs = entry.command.filter((arg) => arg.startsWith("--"));
510508
resolvedCommand = [...bundled, ...extraArgs];
511509
}
512510
mcpEntryConfig["command"] = resolvedCommand;
@@ -589,7 +587,7 @@ export function createConnectionsStore(options: {
589587
}
590588
: {
591589
type: "local" as const,
592-
command: entry.command!,
590+
command: (mcpEntryConfig["command"] as string[]) ?? entry.command!,
593591
enabled: true,
594592
...(mcpEnvironment ? { environment: mcpEnvironment } : {}),
595593
};

‎apps/app/src/react-app/domains/session/browser/browser-panel.tsx‎

Lines changed: 53 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
/** @jsxImportSource react */
22
import { useCallback, useEffect, useRef, useState } from "react";
3-
import {
4-
ArrowLeft,
5-
ArrowRight,
6-
Globe,
7-
Loader2,
8-
RotateCw,
9-
X,
10-
} from "lucide-react";
3+
import { ArrowLeft, ArrowRight, Globe, Loader2, RotateCw, X } from "lucide-react";
114
import { isElectronRuntime } from "../../../../app/utils";
125

136
type BrowserState = {
@@ -18,119 +11,93 @@ type BrowserState = {
1811
isLoading: boolean;
1912
};
2013

21-
type BrowserPanelProps = {
22-
onClose: () => void;
23-
};
14+
type BrowserPanelProps = { onClose: () => void };
2415

25-
const EMPTY_STATE: BrowserState = {
26-
url: "",
27-
title: "",
28-
canGoBack: false,
29-
canGoForward: false,
30-
isLoading: false,
31-
};
16+
const EMPTY_STATE: BrowserState = { url: "", title: "", canGoBack: false, canGoForward: false, isLoading: false };
17+
const TOOLBAR_HEIGHT = 44;
3218

3319
function getElectronBrowser() {
3420
if (!isElectronRuntime()) return null;
3521
return (window as Window).__OPENWORK_ELECTRON__?.browser ?? null;
3622
}
3723

24+
function computeBounds(el: HTMLElement) {
25+
const rect = el.getBoundingClientRect();
26+
return {
27+
x: Math.round(rect.x),
28+
y: Math.round(rect.y + TOOLBAR_HEIGHT),
29+
width: Math.round(rect.width),
30+
height: Math.round(rect.height - TOOLBAR_HEIGHT),
31+
};
32+
}
33+
3834
export function BrowserPanel({ onClose }: BrowserPanelProps) {
3935
const [state, setState] = useState<BrowserState>(EMPTY_STATE);
4036
const [urlInput, setUrlInput] = useState("");
4137
const [urlFocused, setUrlFocused] = useState(false);
4238
const panelRef = useRef<HTMLDivElement>(null);
4339
const urlInputRef = useRef<HTMLInputElement>(null);
40+
const shownRef = useRef(false);
4441

4542
// Subscribe to state changes from the main process
4643
useEffect(() => {
4744
const browser = getElectronBrowser();
4845
if (!browser) return;
49-
50-
const unsub = browser.onStateChange((newState: BrowserState) => {
51-
setState(newState);
52-
if (!urlFocused) {
53-
setUrlInput(newState.url);
54-
}
46+
const unsub = browser.onStateChange?.((s: BrowserState) => {
47+
setState(s);
48+
if (!urlFocused) setUrlInput(s.url);
5549
});
56-
57-
// Get initial state
58-
browser.getState().then((initial: BrowserState | null) => {
59-
if (initial) {
60-
setState(initial);
61-
setUrlInput(initial.url);
62-
}
50+
browser.getState?.().then((s: BrowserState | null) => {
51+
if (s) { setState(s); setUrlInput(s.url); }
6352
});
64-
6553
return unsub;
6654
}, [urlFocused]);
6755

68-
// Show the browser view when the panel mounts, hide on unmount.
69-
// Also update bounds when the panel resizes.
56+
// Show the browser view when the panel mounts, keep bounds in sync, hide on unmount.
7057
useEffect(() => {
7158
const browser = getElectronBrowser();
7259
if (!browser || !panelRef.current) return;
7360

74-
const updateBounds = () => {
61+
const tryShow = () => {
7562
if (!panelRef.current) return;
76-
const rect = panelRef.current.getBoundingClientRect();
77-
// The toolbar is ~44px, leave space at top for it
78-
const toolbarHeight = 44;
79-
const bounds = {
80-
x: Math.round(rect.x),
81-
y: Math.round(rect.y + toolbarHeight),
82-
width: Math.round(rect.width),
83-
height: Math.round(rect.height - toolbarHeight),
84-
};
85-
browser.setBounds(bounds);
63+
const bounds = computeBounds(panelRef.current);
64+
if (bounds.width < 1 || bounds.height < 1) return; // not laid out yet
65+
if (!shownRef.current) {
66+
browser.show?.(bounds);
67+
shownRef.current = true;
68+
} else {
69+
browser.setBounds?.(bounds);
70+
}
8671
};
8772

88-
// Show with initial bounds
89-
const rect = panelRef.current.getBoundingClientRect();
90-
const toolbarHeight = 44;
91-
browser.show({
92-
x: Math.round(rect.x),
93-
y: Math.round(rect.y + toolbarHeight),
94-
width: Math.round(rect.width),
95-
height: Math.round(rect.height - toolbarHeight),
96-
});
73+
// Initial show (may be zero-dimension if layout hasn't settled)
74+
tryShow();
9775

98-
// Observe resize
99-
const observer = new ResizeObserver(updateBounds);
76+
const observer = new ResizeObserver(tryShow);
10077
observer.observe(panelRef.current);
101-
102-
// Also update on window resize
103-
window.addEventListener("resize", updateBounds);
78+
window.addEventListener("resize", tryShow);
10479

10580
return () => {
10681
observer.disconnect();
107-
window.removeEventListener("resize", updateBounds);
108-
browser.hide();
82+
window.removeEventListener("resize", tryShow);
83+
browser.hide?.();
84+
shownRef.current = false;
10985
};
11086
}, []);
11187

112-
const navigate = useCallback(
113-
(url?: string) => {
114-
const browser = getElectronBrowser();
115-
if (!browser) return;
116-
browser.navigate(url ?? urlInput);
117-
},
118-
[urlInput],
119-
);
88+
const navigate = useCallback((url?: string) => {
89+
getElectronBrowser()?.navigate?.(url ?? urlInput);
90+
}, [urlInput]);
12091

121-
const handleUrlKeyDown = useCallback(
122-
(e: React.KeyboardEvent<HTMLInputElement>) => {
123-
if (e.key === "Enter") {
124-
e.preventDefault();
125-
navigate();
126-
urlInputRef.current?.blur();
127-
}
128-
},
129-
[navigate],
130-
);
92+
const handleUrlKeyDown = useCallback((e: React.KeyboardEvent<HTMLInputElement>) => {
93+
if (e.key === "Enter") {
94+
e.preventDefault();
95+
navigate();
96+
urlInputRef.current?.blur();
97+
}
98+
}, [navigate]);
13199

132100
const browser = getElectronBrowser();
133-
134101
if (!isElectronRuntime() || !browser) {
135102
return (
136103
<div className="flex h-full items-center justify-center p-4 text-center text-dls-secondary">
@@ -141,44 +108,16 @@ export function BrowserPanel({ onClose }: BrowserPanelProps) {
141108

142109
return (
143110
<div ref={panelRef} className="flex h-full flex-col">
144-
{/* Toolbar */}
145111
<div className="flex h-[44px] shrink-0 items-center gap-1 border-b border-dls-border px-2">
146-
{/* Navigation buttons */}
147-
<button
148-
type="button"
149-
className="inline-flex h-7 w-7 items-center justify-center rounded-md text-dls-secondary transition-colors hover:bg-dls-hover hover:text-dls-text disabled:opacity-40"
150-
onClick={() => browser.back()}
151-
disabled={!state.canGoBack}
152-
title="Back"
153-
aria-label="Go back"
154-
>
112+
<button type="button" className="inline-flex h-7 w-7 items-center justify-center rounded-md text-dls-secondary transition-colors hover:bg-dls-hover hover:text-dls-text disabled:opacity-40" onClick={() => browser.back?.()} disabled={!state.canGoBack} title="Back" aria-label="Go back">
155113
<ArrowLeft className="h-4 w-4" />
156114
</button>
157-
<button
158-
type="button"
159-
className="inline-flex h-7 w-7 items-center justify-center rounded-md text-dls-secondary transition-colors hover:bg-dls-hover hover:text-dls-text disabled:opacity-40"
160-
onClick={() => browser.forward()}
161-
disabled={!state.canGoForward}
162-
title="Forward"
163-
aria-label="Go forward"
164-
>
115+
<button type="button" className="inline-flex h-7 w-7 items-center justify-center rounded-md text-dls-secondary transition-colors hover:bg-dls-hover hover:text-dls-text disabled:opacity-40" onClick={() => browser.forward?.()} disabled={!state.canGoForward} title="Forward" aria-label="Go forward">
165116
<ArrowRight className="h-4 w-4" />
166117
</button>
167-
<button
168-
type="button"
169-
className="inline-flex h-7 w-7 items-center justify-center rounded-md text-dls-secondary transition-colors hover:bg-dls-hover hover:text-dls-text"
170-
onClick={() => browser.reload()}
171-
title="Reload"
172-
aria-label="Reload page"
173-
>
174-
{state.isLoading ? (
175-
<Loader2 className="h-4 w-4 animate-spin" />
176-
) : (
177-
<RotateCw className="h-4 w-4" />
178-
)}
118+
<button type="button" className="inline-flex h-7 w-7 items-center justify-center rounded-md text-dls-secondary transition-colors hover:bg-dls-hover hover:text-dls-text" onClick={() => browser.reload?.()} title="Reload" aria-label="Reload page">
119+
{state.isLoading ? <Loader2 className="h-4 w-4 animate-spin" /> : <RotateCw className="h-4 w-4" />}
179120
</button>
180-
181-
{/* URL bar */}
182121
<div className="relative mx-1 flex min-w-0 flex-1 items-center">
183122
<Globe className="absolute left-2 h-3.5 w-3.5 text-dls-secondary" />
184123
<input
@@ -188,29 +127,17 @@ export function BrowserPanel({ onClose }: BrowserPanelProps) {
188127
value={urlInput}
189128
onChange={(e) => setUrlInput(e.target.value)}
190129
onKeyDown={handleUrlKeyDown}
191-
onFocus={() => {
192-
setUrlFocused(true);
193-
urlInputRef.current?.select();
194-
}}
130+
onFocus={() => { setUrlFocused(true); urlInputRef.current?.select(); }}
195131
onBlur={() => setUrlFocused(false)}
196132
placeholder="Enter URL..."
197133
spellCheck={false}
198134
autoComplete="off"
199135
/>
200136
</div>
201-
202-
{/* Close button */}
203-
<button
204-
type="button"
205-
className="inline-flex h-7 w-7 items-center justify-center rounded-md text-dls-secondary transition-colors hover:bg-dls-hover hover:text-dls-text"
206-
onClick={onClose}
207-
title="Close browser"
208-
aria-label="Close browser panel"
209-
>
137+
<button type="button" className="inline-flex h-7 w-7 items-center justify-center rounded-md text-dls-secondary transition-colors hover:bg-dls-hover hover:text-dls-text" onClick={onClose} title="Close browser" aria-label="Close browser panel">
210138
<X className="h-4 w-4" />
211139
</button>
212140
</div>
213-
214141
{/* WebContentsView renders in this area (managed by Electron main process) */}
215142
<div className="min-h-0 flex-1" />
216143
</div>

‎apps/app/src/react-app/domains/session/chat/session-page.tsx‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,9 @@ export function SessionPage(props: SessionPageProps) {
176176
const [deleteBusy, setDeleteBusy] = useState(false);
177177
const [todoExpanded, setTodoExpanded] = useState(true);
178178
const [browserPanelOpen, setBrowserPanelOpen] = useState(false);
179+
const toggleBrowserPanel = useCallback(() => setBrowserPanelOpen((p) => !p), []);
179180
const [showDelayedSessionLoadingState, setShowDelayedSessionLoadingState] = useState(false);
180181

181-
const toggleBrowserPanel = useCallback(() => {
182-
setBrowserPanelOpen((prev) => !prev);
183-
}, []);
184-
185182
const selectedSessionTitle = useMemo(
186183
() => sessionTitleForId(props.sidebar.workspaceSessionGroups, props.selectedSessionId),
187184
[props.selectedSessionId, props.sidebar.workspaceSessionGroups],
@@ -350,11 +347,7 @@ export function SessionPage(props: SessionPageProps) {
350347
{isElectronRuntime() ? (
351348
<button
352349
type="button"
353-
className={`flex items-center gap-1.5 rounded-md px-2.5 py-1.5 text-[13px] font-medium transition-colors ${
354-
browserPanelOpen
355-
? "bg-dls-accent/10 text-dls-accent"
356-
: "text-gray-10 hover:bg-gray-2/70 hover:text-dls-text"
357-
}`}
350+
className={`flex items-center gap-1.5 rounded-md px-2.5 py-1.5 text-[13px] font-medium transition-colors ${browserPanelOpen ? "bg-dls-accent/10 text-dls-accent" : "text-gray-10 hover:bg-gray-2/70 hover:text-dls-text"}`}
358351
onClick={toggleBrowserPanel}
359352
title="Toggle browser panel"
360353
aria-label="Toggle browser panel"
@@ -560,7 +553,6 @@ export function SessionPage(props: SessionPageProps) {
560553
/>
561554
</main>
562555

563-
{/* Embedded browser panel */}
564556
{browserPanelOpen ? (
565557
<aside
566558
className="hidden min-h-0 shrink-0 overflow-hidden rounded-[24px] border border-dls-border bg-dls-surface shadow-[var(--dls-shell-shadow)] lg:flex lg:flex-col"

0 commit comments

Comments
 (0)