Skip to content

Commit 99069c0

Browse files
committed
fix(browser): address review feedback — avoid panel auto-open race; include size on launch; send scaled coordinates in say; guard ResizeObserver cleanup
1 parent 46578e0 commit 99069c0

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/core/task/Task.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,17 +380,29 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
380380
// Broadcast to browser panel
381381
this.broadcastBrowserSessionUpdate()
382382

383-
// When a browser session becomes active, automatically open/reveal the Browser Session tab
383+
// When a browser session becomes active, automatically open/reveal the Browser Session tab.
384+
// Defer to the microtask queue and re-check active state to avoid race conditions
385+
// where the session could be closed before the panel opens.
384386
if (isActive) {
385387
try {
386-
// Lazy-load to avoid circular imports at module load time
387-
const { BrowserSessionPanelManager } = require("../webview/BrowserSessionPanelManager")
388388
const providerRef = this.providerRef.deref()
389-
if (providerRef) {
390-
BrowserSessionPanelManager.getInstance(providerRef)
391-
.show()
392-
.catch(() => {})
393-
}
389+
if (!providerRef) return
390+
391+
Promise.resolve().then(async () => {
392+
try {
393+
// Ensure the session is still active before opening the panel
394+
if (!(this.browserSession?.isSessionActive() ?? false)) return
395+
396+
// Lazy-load to avoid circular imports at module load time
397+
const { BrowserSessionPanelManager } = require("../webview/BrowserSessionPanelManager")
398+
const mgr = BrowserSessionPanelManager.getInstance(providerRef)
399+
// New session: allow auto-open again
400+
mgr.resetManualCloseFlag()
401+
await mgr.show()
402+
} catch {
403+
// swallow
404+
}
405+
})
394406
} catch (err) {
395407
console.error("[Task] Failed to auto-open Browser Session panel:", err)
396408
}

src/core/tools/browserActionTool.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,15 @@ export async function browserActionTool(
115115
await cline.browserSession.launchBrowser()
116116

117117
// Create browser_action say message AFTER launching so status appears first
118+
// Include size to keep message shape consistent with other actions
119+
const vs = cline.browserSession.getViewportSize()
120+
const launchSize = `${vs.width ?? 900}x${vs.height ?? 600}`
118121
await cline.say(
119122
"browser_action",
120123
JSON.stringify({
121124
action: "launch" as BrowserAction,
122125
text: url,
126+
size: launchSize,
123127
} satisfies ClineSayBrowserAction),
124128
undefined,
125129
false,
@@ -187,7 +191,7 @@ export async function browserActionTool(
187191
"browser_action",
188192
JSON.stringify({
189193
action: action as BrowserAction,
190-
coordinate,
194+
coordinate: processedCoordinate,
191195
text,
192196
size,
193197
} satisfies ClineSayBrowserAction),

webview-ui/src/components/chat/BrowserSessionRow.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ const BrowserSessionRow = memo((props: BrowserSessionRowProps) => {
196196
useEffect(() => {
197197
const el = screenshotRef.current
198198
if (!el) return
199+
let mounted = true
199200
const update = () => {
201+
if (!mounted) return
200202
const r = el.getBoundingClientRect()
201203
setSW(r.width)
202204
setSH(r.height)
@@ -206,6 +208,7 @@ const BrowserSessionRow = memo((props: BrowserSessionRowProps) => {
206208
typeof window !== "undefined" && "ResizeObserver" in window ? new ResizeObserver(() => update()) : null
207209
if (ro) ro.observe(el)
208210
return () => {
211+
mounted = false
209212
if (ro) ro.disconnect()
210213
}
211214
}, [])

0 commit comments

Comments
 (0)