Skip to content

Commit a067e41

Browse files
committed
fix(desktop-browser): recover issue-page focus only when nothing holds focus, and keep cache bypass except for hung pages
1 parent 9d22526 commit a067e41

3 files changed

Lines changed: 14 additions & 22 deletions

File tree

‎apps/desktop/src/main/browser-agent/session.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,12 +2013,12 @@ export function reloadPage(contents: WebContents): void {
20132013
}
20142014

20152015
/**
2016-
* Reloads past the HTTP cache, the browser's Shift-reload. A page showing an
2017-
* issue takes the same recovery as a plain reload instead: a hung renderer
2018-
* must be restarted, since reloading it in place waits on the hung page.
2016+
* Reloads past the HTTP cache, the browser's Shift-reload. A hung page takes
2017+
* the plain reload's recovery instead: its renderer must be restarted, since
2018+
* reloading it in place waits on the hung page.
20192019
*/
20202020
function hardReloadPage(contents: WebContents): void {
2021-
if (tabForContents(contents)?.pageIssue) {
2021+
if (tabForContents(contents)?.pageIssue?.kind === 'unresponsive') {
20222022
reloadPage(contents)
20232023
return
20242024
}

‎apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/browser-session/browser-page-issue.tsx‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type RefObject, useEffect, useRef } from 'react'
1+
import { useEffect, useRef } from 'react'
22
import type { BrowserPageIssue } from '@sim/browser-protocol'
33
import { Chip } from '@sim/emcn'
44
import { CircleAlert, Globe, RefreshCw } from '@sim/emcn/icons'
@@ -7,8 +7,6 @@ interface BrowserPageIssueProps {
77
issue: BrowserPageIssue
88
onReload: () => void
99
focusRecovery: boolean
10-
/** The browser panel; focus anywhere else in Sim is never taken for recovery. */
11-
panelRef: RefObject<HTMLElement | null>
1210
}
1311

1412
interface BrowserPageIssueCopy {
@@ -128,30 +126,25 @@ export function browserPageIssueCopy(issue: BrowserPageIssue): BrowserPageIssueC
128126
}
129127

130128
/**
131-
* Whether the user's focus is somewhere in Sim other than the browser.
132-
* `document.activeElement` survives a window blur, so a caret left in chat
133-
* still counts as elsewhere.
129+
* Whether nothing in Sim holds focus, as when it was in the native page that
130+
* just failed. Any focused element, from the chat composer to the omnibox,
131+
* keeps it. `document.activeElement` survives a window blur, so a caret left
132+
* in chat still counts.
134133
*/
135-
function isFocusElsewhere(panel: HTMLElement | null): boolean {
134+
function isFocusFree(): boolean {
136135
const active = document.activeElement
137-
if (!(active instanceof HTMLElement) || active === document.body) return false
138-
return !panel?.contains(active)
136+
return !active || active === document.body
139137
}
140138

141139
/** Replaces a hidden native page and optionally claims renderer focus for keyboard recovery. */
142-
export function BrowserPageIssueView({
143-
issue,
144-
onReload,
145-
focusRecovery,
146-
panelRef,
147-
}: BrowserPageIssueProps) {
140+
export function BrowserPageIssueView({ issue, onReload, focusRecovery }: BrowserPageIssueProps) {
148141
const headingRef = useRef<HTMLHeadingElement>(null)
149142
const copy = browserPageIssueCopy(issue)
150143

151144
useEffect(() => {
152145
// Keyboard recovery for someone who was in the browser.
153-
if (focusRecovery && !isFocusElsewhere(panelRef.current)) headingRef.current?.focus()
154-
}, [focusRecovery, issue, panelRef])
146+
if (focusRecovery && isFocusFree()) headingRef.current?.focus()
147+
}, [focusRecovery, issue])
155148

156149
const Icon = issue.kind === 'load-error' ? Globe : CircleAlert
157150

‎apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/browser-session/browser-session.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,6 @@ export function BrowserSession({
13591359
<BrowserPageIssueView
13601360
issue={pageState.issue}
13611361
focusRecovery={visible}
1362-
panelRef={panelRef}
13631362
onReload={() => sendBrowserPanelAction('reload', {}, scopeId)}
13641363
/>
13651364
)}

0 commit comments

Comments
 (0)