Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
This commit is contained in:
@@ -63,6 +63,7 @@ import { getRuntimeEnvironmentIdForWorktree } from '@/lib/worktree-runtime-owner
|
||||
import { ORCA_BROWSER_BLANK_URL, ORCA_BROWSER_PARTITION } from '../../../../shared/constants'
|
||||
import { getOrcaProfileBrowserDefaultPartition } from '../../../../shared/orca-profiles'
|
||||
import type {
|
||||
BrowserCertificateProceedResult,
|
||||
BrowserLoadError,
|
||||
BrowserPage as BrowserPageState,
|
||||
BrowserWorkspace as BrowserWorkspaceState
|
||||
@@ -70,7 +71,9 @@ import type {
|
||||
import {
|
||||
normalizeBrowserNavigationUrl,
|
||||
normalizeExternalBrowserUrl,
|
||||
redactKagiSessionToken
|
||||
redactKagiSessionToken,
|
||||
resolveRemoteFailureExternalUrl,
|
||||
toHttpsRecoveryUrl
|
||||
} from '../../../../shared/browser-url'
|
||||
import { keybindingMatchesAction } from '../../../../shared/keybindings'
|
||||
import { getScreenSubmitModifierLabel, isScreenSubmitShortcut } from '@/lib/screen-submit-shortcut'
|
||||
@@ -165,13 +168,7 @@ import {
|
||||
type BrowserScreencastFrameMetadata
|
||||
} from '../../../../shared/browser-screencast-protocol'
|
||||
import { withBrowserPaneUiRuntimeRpcSource } from '../../../../shared/runtime-rpc-feature-interaction-source'
|
||||
import {
|
||||
formatByteCount,
|
||||
formatLoadFailureDescription,
|
||||
formatLoadFailureRecoveryHint,
|
||||
formatPermissionNotice,
|
||||
formatPopupNotice
|
||||
} from './browser-notices'
|
||||
import { formatByteCount, formatPermissionNotice, formatPopupNotice } from './browser-notices'
|
||||
import {
|
||||
getDriverForBrowserPage,
|
||||
onBrowserDriverChange,
|
||||
@@ -186,6 +183,7 @@ import { useMarkupMode, type MarkupCaptureContext } from './markup/useMarkupMode
|
||||
import { MarkupOverlay } from './markup/MarkupOverlay'
|
||||
import { MarkupDrawButton } from './markup/MarkupDrawButton'
|
||||
import { deliverMarkupToClipboard } from './markup/markup-clipboard-delivery'
|
||||
import { BrowserLoadFailureOverlay } from './browser-load-failure-overlay'
|
||||
|
||||
type BrowserTabPageState = Partial<
|
||||
Pick<
|
||||
@@ -700,28 +698,6 @@ function getRemoteBrowserDeviceScaleFactor(): number {
|
||||
return Math.min(2, Math.max(1, Number(scale.toFixed(2))))
|
||||
}
|
||||
|
||||
function getLoadErrorMetadata(loadError: BrowserLoadError | null): {
|
||||
displayUrl: string
|
||||
host: string | null
|
||||
isLocalhostLike: boolean
|
||||
} {
|
||||
const rawUrl = loadError?.validatedUrl ?? 'about:blank'
|
||||
const displayUrl = toDisplayUrl(rawUrl)
|
||||
try {
|
||||
const parsed = new URL(rawUrl)
|
||||
const host = parsed.host || null
|
||||
const hostname = parsed.hostname
|
||||
const isLocalhostLike =
|
||||
hostname === 'localhost' ||
|
||||
hostname === '127.0.0.1' ||
|
||||
hostname === '0.0.0.0' ||
|
||||
hostname === '::1'
|
||||
return { displayUrl, host, isLocalhostLike }
|
||||
} catch {
|
||||
return { displayUrl, host: null, isLocalhostLike: false }
|
||||
}
|
||||
}
|
||||
|
||||
function getOpenableExternalUrl(
|
||||
webview: Electron.WebviewTag | null,
|
||||
fallbackUrl: string
|
||||
@@ -960,6 +936,12 @@ function RemoteBrowserPagePane({
|
||||
(token: RemoteBrowserOperationToken) => Promise<BrowserTabInfo | null>
|
||||
>(async () => null)
|
||||
const setRemoteBrowserPageHandle = useAppStore((s) => s.setRemoteBrowserPageHandle)
|
||||
const certificateFailure = useAppStore(
|
||||
(s) => s.browserCertificateFailuresByPageId[browserTab.id] ?? null
|
||||
)
|
||||
const remotePageHandle = useAppStore(
|
||||
(s) => s.remoteBrowserPageHandlesByPageId[browserTab.id] ?? null
|
||||
)
|
||||
const createBrowserTab = useAppStore((s) => s.createBrowserTab)
|
||||
const closeBrowserPage = useAppStore((s) => s.closeBrowserPage)
|
||||
const closeBrowserTab = useAppStore((s) => s.closeBrowserTab)
|
||||
@@ -1985,7 +1967,13 @@ function RemoteBrowserPagePane({
|
||||
setRemoteError(message)
|
||||
onUpdatePageState(browserTab.id, {
|
||||
loading: false,
|
||||
loadError: { code: 0, description: message, validatedUrl: url ?? browserTab.url }
|
||||
// Why: validatedUrl crosses process/persistence boundaries, so redact a
|
||||
// Kagi session token the same way the main-process failure path does.
|
||||
loadError: {
|
||||
code: 0,
|
||||
description: message,
|
||||
validatedUrl: redactKagiSessionToken(url ?? browserTab.url)
|
||||
}
|
||||
})
|
||||
} finally {
|
||||
if (isCurrentRemoteOperationToken(pageToken)) {
|
||||
@@ -2398,6 +2386,12 @@ function RemoteBrowserPagePane({
|
||||
}, [frameUrl, handleRemoteScreenshotWheel])
|
||||
|
||||
const remoteFrameStyle = useMemo(() => getRemoteBrowserFrameStyle(frameMetadata), [frameMetadata])
|
||||
const remoteFailureUrl = browserTab.loadError?.validatedUrl ?? browserTab.url
|
||||
const remoteFailureExternalUrl = resolveRemoteFailureExternalUrl(remoteFailureUrl)
|
||||
const showRemoteFailureOverlay =
|
||||
Boolean(browserTab.loadError) &&
|
||||
remoteFailureUrl !== 'about:blank' &&
|
||||
remoteFailureUrl !== ORCA_BROWSER_BLANK_URL
|
||||
|
||||
// Why: markup works on remote panes by snapshotting the already-displayed
|
||||
// screencast <img> — no in-page injection needed, so it is enabled here even
|
||||
@@ -2692,6 +2686,44 @@ function RemoteBrowserPagePane({
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{showRemoteFailureOverlay && browserTab.loadError ? (
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={browserTab.loadError}
|
||||
externalUrl={remoteFailureExternalUrl}
|
||||
currentUrl={toDisplayUrl(remoteFailureUrl)}
|
||||
httpsRecoveryUrl={toHttpsRecoveryUrl(remoteFailureUrl)}
|
||||
onRetry={() => void runRemoteNavigation('browser.reload')}
|
||||
onTryHttps={(url) => void runRemoteNavigation('browser.goto', url)}
|
||||
onCopy={(url) => void window.api.ui.writeClipboardText(url)}
|
||||
onOpenExternal={(url) => void window.api.shell.openUrl(url)}
|
||||
certificateFailure={certificateFailure}
|
||||
expectedBrowserPageId={
|
||||
remotePageHandle?.environmentId === activeRuntimeEnvironmentId
|
||||
? remotePageHandle.remotePageId
|
||||
: null
|
||||
}
|
||||
onProceedCertificate={async (challengeId) => {
|
||||
const target = runtimeTarget()
|
||||
if (
|
||||
!target ||
|
||||
remotePageHandle?.environmentId !== target.environmentId ||
|
||||
remotePageHandle.remotePageId !== certificateFailure?.browserPageId
|
||||
) {
|
||||
return { ok: false, reason: 'missing' }
|
||||
}
|
||||
return callRuntimeRpc<BrowserCertificateProceedResult>(
|
||||
target,
|
||||
'browser.certificate.proceed',
|
||||
{
|
||||
worktree: runtimeWorktree,
|
||||
page: remotePageHandle.remotePageId,
|
||||
challengeId
|
||||
},
|
||||
{ timeoutMs: 15_000, suppressFeatureInteraction: true }
|
||||
)
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
{remoteError ? (
|
||||
<div className="absolute bottom-4 left-1/2 max-w-md -translate-x-1/2 rounded-md border border-border bg-popover px-3 py-2 text-xs text-popover-foreground shadow-md">
|
||||
{remoteError}
|
||||
@@ -2879,6 +2911,9 @@ function BrowserPagePane({
|
||||
const browserAnnotations = useAppStore(
|
||||
(s) => s.browserAnnotationsByPageId[browserTab.id] ?? EMPTY_BROWSER_ANNOTATIONS
|
||||
)
|
||||
const certificateFailure = useAppStore(
|
||||
(s) => s.browserCertificateFailuresByPageId[browserTab.id] ?? null
|
||||
)
|
||||
const activeGroupId = useAppStore((s) => s.activeGroupIdByWorktree[worktreeId])
|
||||
const browserAnnotationsRef = useRef(browserAnnotations)
|
||||
browserAnnotationsRef.current = browserAnnotations
|
||||
@@ -3731,21 +3766,53 @@ function BrowserPagePane({
|
||||
dismissAddressBarSuggestionsRef.current?.()
|
||||
}
|
||||
|
||||
const handleDomReady = (): void => {
|
||||
let registrationInFlight: { webContentsId: number; promise: Promise<boolean> } | null = null
|
||||
const registerGuest = (): Promise<boolean> => {
|
||||
const webContentsId = webview.getWebContentsId()
|
||||
let queuedAnnotationViewportBridgeSync = false
|
||||
if (registeredWebContentsIds.get(browserTab.id) !== webContentsId) {
|
||||
registeredWebContentsIds.set(browserTab.id, webContentsId)
|
||||
queuedAnnotationViewportBridgeSync = true
|
||||
void window.api.browser
|
||||
.registerGuest({
|
||||
browserPageId: browserTab.id,
|
||||
workspaceId,
|
||||
worktreeId,
|
||||
sessionProfileId,
|
||||
webContentsId
|
||||
})
|
||||
.finally(() => syncBrowserAnnotationViewportBridge())
|
||||
if (registeredWebContentsIds.get(browserTab.id) === webContentsId) {
|
||||
return Promise.resolve(true)
|
||||
}
|
||||
if (registrationInFlight?.webContentsId === webContentsId) {
|
||||
return registrationInFlight.promise
|
||||
}
|
||||
const promise = window.api.browser
|
||||
.registerGuest({
|
||||
browserPageId: browserTab.id,
|
||||
workspaceId,
|
||||
worktreeId,
|
||||
sessionProfileId,
|
||||
webContentsId
|
||||
})
|
||||
.then((registered) => {
|
||||
if (registered) {
|
||||
registeredWebContentsIds.set(browserTab.id, webContentsId)
|
||||
}
|
||||
return registered
|
||||
})
|
||||
// Why: normalize IPC rejection to false so the dom-ready fallback can
|
||||
// retry attach-policy races without an unhandled promise rejection.
|
||||
.catch(() => false)
|
||||
.finally(() => {
|
||||
if (registrationInFlight?.promise === promise) {
|
||||
registrationInFlight = null
|
||||
}
|
||||
})
|
||||
registrationInFlight = { webContentsId, promise }
|
||||
return promise
|
||||
}
|
||||
|
||||
const handleDidAttach = (): void => {
|
||||
// Why: certificate failures can happen before dom-ready. Register at
|
||||
// attach so main can map the initial failure to this page; dom-ready below
|
||||
// remains an idempotent fallback for attach-policy races.
|
||||
void registerGuest().finally(() => syncBrowserAnnotationViewportBridge())
|
||||
}
|
||||
|
||||
const handleDomReady = (): void => {
|
||||
const queuedAnnotationViewportBridgeSync =
|
||||
registeredWebContentsIds.get(browserTab.id) !== webview.getWebContentsId()
|
||||
if (queuedAnnotationViewportBridgeSync) {
|
||||
void registerGuest().finally(() => syncBrowserAnnotationViewportBridge())
|
||||
}
|
||||
syncNavigationState(webview)
|
||||
if (keepAddressBarFocusRef.current) {
|
||||
@@ -3964,6 +4031,7 @@ function BrowserPagePane({
|
||||
}
|
||||
}
|
||||
|
||||
webview.addEventListener('did-attach', handleDidAttach)
|
||||
webview.addEventListener('dom-ready', handleDomReady)
|
||||
webview.addEventListener('focus', dismissAddressBarSuggestions)
|
||||
webview.addEventListener('did-start-loading', handleDidStartLoading)
|
||||
@@ -3997,6 +4065,7 @@ function BrowserPagePane({
|
||||
}
|
||||
|
||||
return () => {
|
||||
webview.removeEventListener('did-attach', handleDidAttach)
|
||||
webview.removeEventListener('dom-ready', handleDomReady)
|
||||
webview.removeEventListener('focus', dismissAddressBarSuggestions)
|
||||
webview.removeEventListener('did-start-loading', handleDidStartLoading)
|
||||
@@ -4672,8 +4741,8 @@ function BrowserPagePane({
|
||||
const isBlankTab = browserTab.url === 'about:blank' || browserTab.url === ORCA_BROWSER_BLANK_URL
|
||||
const externalUrl = getOpenableExternalUrl(webviewRef.current, browserTab.url)
|
||||
const currentBrowserUrl = getCurrentBrowserUrl(webviewRef.current, browserTab.url)
|
||||
const loadErrorMeta = getLoadErrorMetadata(browserTab.loadError)
|
||||
const loadErrorHint = formatLoadFailureRecoveryHint(loadErrorMeta)
|
||||
const failedNavigationUrl = browserTab.loadError?.validatedUrl ?? currentBrowserUrl
|
||||
const failureExternalUrl = normalizeExternalBrowserUrl(failedNavigationUrl)
|
||||
const showFailureOverlay = Boolean(browserTab.loadError) && !isBlankTab
|
||||
const visibleDownloads = (() => {
|
||||
const active = downloadStates.filter((download) => download.status === 'downloading')
|
||||
@@ -5476,114 +5545,40 @@ function BrowserPagePane({
|
||||
onClose={() => setFindOpen(false)}
|
||||
webviewRef={webviewRef}
|
||||
/>
|
||||
{showFailureOverlay ? (
|
||||
<div className="absolute inset-0 z-10 flex items-center justify-center bg-[radial-gradient(circle_at_center,rgba(255,255,255,0.02),transparent_58%)] px-6">
|
||||
<div className="flex max-w-sm flex-col items-center px-8 py-8 text-center opacity-70">
|
||||
<div className="mb-4 rounded-full border border-border/70 bg-muted/30 p-3">
|
||||
<Globe className="size-5 text-muted-foreground" />
|
||||
</div>
|
||||
<h2 className="text-base font-semibold text-foreground/85">
|
||||
{loadErrorMeta.host
|
||||
? translate(
|
||||
'auto.components.browser.pane.BrowserPane.db325a7eeb',
|
||||
"Can't reach {{value0}}",
|
||||
{ value0: loadErrorMeta.host }
|
||||
)
|
||||
: translate(
|
||||
'auto.components.browser.pane.BrowserPane.b2856516e2',
|
||||
"Can't load this page"
|
||||
)}
|
||||
</h2>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
{formatLoadFailureDescription(browserTab.loadError, loadErrorMeta)}
|
||||
</p>
|
||||
{loadErrorHint ? (
|
||||
<p className="mt-2 text-xs text-muted-foreground/80">{loadErrorHint}</p>
|
||||
) : null}
|
||||
<div className="mt-5 flex items-center gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="h-9 gap-2 px-3"
|
||||
title={translate(
|
||||
'auto.components.browser.pane.BrowserPane.781d6459ad',
|
||||
'Retry'
|
||||
)}
|
||||
onClick={() => {
|
||||
const webview = webviewRef.current
|
||||
if (!webview) {
|
||||
return
|
||||
}
|
||||
onUpdatePageStateRef.current(browserTab.id, {
|
||||
loading: true
|
||||
})
|
||||
retryBrowserTabLoad(webview, browserTab, onUpdatePageStateRef.current)
|
||||
}}
|
||||
>
|
||||
<RefreshCw className="size-4" />
|
||||
<span>
|
||||
{translate(
|
||||
'auto.components.browser.pane.BrowserPane.c6be71329e',
|
||||
'Refresh'
|
||||
)}
|
||||
</span>
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-9 gap-2 px-3"
|
||||
title={translate(
|
||||
'auto.components.browser.pane.BrowserPane.3c085f638d',
|
||||
'Copy failed page URL'
|
||||
)}
|
||||
onClick={() => {
|
||||
// Why: failed guests often leave users stranded on a blank
|
||||
// error surface. Put the current URL on the clipboard from
|
||||
// the recovery UI itself so they can retry elsewhere
|
||||
// without having to discover the toolbar overflow first.
|
||||
void window.api.ui.writeClipboardText(currentBrowserUrl)
|
||||
setResourceNotice('Copied the current page URL.')
|
||||
}}
|
||||
>
|
||||
<Copy className="size-4" />
|
||||
<span>
|
||||
{translate(
|
||||
'auto.components.browser.pane.BrowserPane.93be92f8d1',
|
||||
'Copy Address'
|
||||
)}
|
||||
</span>
|
||||
</Button>
|
||||
{externalUrl ? (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-9 gap-2 px-3"
|
||||
title={translate(
|
||||
'auto.components.browser.pane.BrowserPane.da68d35f7b',
|
||||
'Open failed page in default browser'
|
||||
)}
|
||||
onClick={() => {
|
||||
// Why: page failures inside Orca can still be recoverable
|
||||
// in the system browser, especially for OAuth, captive
|
||||
// portals, or enterprise auth flows that rely on a full
|
||||
// browser profile. Keep this action in the failed-state
|
||||
// overlay so recovery does not depend on toolbar affordance
|
||||
// discovery while the guest itself is unusable.
|
||||
void window.api.shell.openUrl(externalUrl)
|
||||
}}
|
||||
>
|
||||
<ExternalLink className="size-4" />
|
||||
<span>
|
||||
{translate(
|
||||
'auto.components.browser.pane.BrowserPane.1c78adc73d',
|
||||
'Open Externally'
|
||||
)}
|
||||
</span>
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{showFailureOverlay && browserTab.loadError ? (
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={browserTab.loadError}
|
||||
externalUrl={failureExternalUrl}
|
||||
currentUrl={toDisplayUrl(failedNavigationUrl)}
|
||||
httpsRecoveryUrl={toHttpsRecoveryUrl(failedNavigationUrl)}
|
||||
onRetry={() => {
|
||||
const webview = webviewRef.current
|
||||
if (!webview) {
|
||||
return
|
||||
}
|
||||
onUpdatePageStateRef.current(browserTab.id, { loading: true })
|
||||
retryBrowserTabLoad(webview, browserTab, onUpdatePageStateRef.current)
|
||||
}}
|
||||
onTryHttps={navigateToUrl}
|
||||
onCopy={(url) => {
|
||||
void window.api.ui.writeClipboardText(url)
|
||||
setResourceNotice(
|
||||
translate(
|
||||
'browser.loadFailure.addressCopied',
|
||||
'Copied the current page address.'
|
||||
)
|
||||
)
|
||||
}}
|
||||
onOpenExternal={(url) => void window.api.shell.openUrl(url)}
|
||||
certificateFailure={certificateFailure}
|
||||
expectedBrowserPageId={browserTab.id}
|
||||
onProceedCertificate={(challengeId) =>
|
||||
window.api.browser.proceedCertificate({
|
||||
browserPageId: browserTab.id,
|
||||
challengeId
|
||||
})
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{isBlankTab ? (
|
||||
<div className="pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-[radial-gradient(circle_at_center,rgba(255,255,255,0.02),transparent_58%)] px-6">
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
// @vitest-environment happy-dom
|
||||
import '@testing-library/jest-dom/vitest'
|
||||
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { BrowserLoadFailureOverlay } from './browser-load-failure-overlay'
|
||||
|
||||
const callbacks = {
|
||||
onRetry: vi.fn(),
|
||||
onTryHttps: vi.fn(),
|
||||
onCopy: vi.fn(),
|
||||
onOpenExternal: vi.fn(),
|
||||
onProceedCertificate: vi.fn()
|
||||
}
|
||||
|
||||
const certificateFailure = {
|
||||
challengeId: 'challenge-1',
|
||||
browserPageId: 'page-1',
|
||||
errorCode: -202,
|
||||
error: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
origin: 'https://localhost:3443',
|
||||
displayHost: 'localhost:3443',
|
||||
canProceed: true,
|
||||
observedAt: 123
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.useRealTimers()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('BrowserLoadFailureOverlay', () => {
|
||||
it('uses certificate-specific copy while keeping strict verification', () => {
|
||||
render(
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={{
|
||||
code: -202,
|
||||
description: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
validatedUrl: 'https://localhost:3443/app'
|
||||
}}
|
||||
externalUrl="https://localhost:3443/app"
|
||||
currentUrl="https://localhost:3443/app"
|
||||
httpsRecoveryUrl={null}
|
||||
{...callbacks}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText("Connection isn't secure")).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getByText(
|
||||
"Orca doesn't trust the authority that issued the certificate for localhost:3443."
|
||||
)
|
||||
).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Proceed Anyway (Unsafe)' })).toBeNull()
|
||||
expect(screen.queryByText(/make sure the server is running/i)).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('keeps restored certificate errors accurate without allowing approval', () => {
|
||||
render(
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={{
|
||||
code: -200,
|
||||
description: 'ERR_CERT_COMMON_NAME_INVALID',
|
||||
validatedUrl: 'https://localhost:3443/'
|
||||
}}
|
||||
externalUrl={null}
|
||||
currentUrl="https://localhost:3443/"
|
||||
httpsRecoveryUrl={null}
|
||||
{...callbacks}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText("The certificate doesn't match localhost:3443.")).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Proceed Anyway (Unsafe)' })).toBeNull()
|
||||
expect(screen.getByRole('button', { name: 'Retry' })).toBeEnabled()
|
||||
expect(screen.getByRole('button', { name: 'Copy Address' })).toBeEnabled()
|
||||
})
|
||||
|
||||
it('offers HTTPS recovery only for an eligible failed HTTP address', () => {
|
||||
const { rerender } = render(
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={{
|
||||
code: -102,
|
||||
description: 'ERR_CONNECTION_REFUSED',
|
||||
validatedUrl: 'http://localhost:3000/app'
|
||||
}}
|
||||
externalUrl="http://localhost:3000/app"
|
||||
currentUrl="http://localhost:3000/app"
|
||||
httpsRecoveryUrl="https://localhost:3000/app"
|
||||
{...callbacks}
|
||||
/>
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Try HTTPS' }))
|
||||
expect(callbacks.onTryHttps).toHaveBeenCalledWith('https://localhost:3000/app')
|
||||
|
||||
rerender(
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={{
|
||||
code: -102,
|
||||
description: 'ERR_CONNECTION_REFUSED',
|
||||
validatedUrl: 'https://localhost:3000/app'
|
||||
}}
|
||||
externalUrl="https://localhost:3000/app"
|
||||
currentUrl="https://localhost:3000/app"
|
||||
httpsRecoveryUrl={null}
|
||||
{...callbacks}
|
||||
/>
|
||||
)
|
||||
expect(screen.queryByRole('button', { name: 'Try HTTPS' })).toBeNull()
|
||||
})
|
||||
|
||||
it('hides Open Externally and works without an external handler', () => {
|
||||
render(
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={{
|
||||
code: -202,
|
||||
description: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
validatedUrl: 'https://localhost:3443/'
|
||||
}}
|
||||
currentUrl="https://localhost:3443/"
|
||||
httpsRecoveryUrl={null}
|
||||
onRetry={callbacks.onRetry}
|
||||
onTryHttps={callbacks.onTryHttps}
|
||||
onCopy={callbacks.onCopy}
|
||||
/>
|
||||
)
|
||||
|
||||
// externalUrl / onOpenExternal omitted (e.g. a remote loopback failure):
|
||||
// the action is absent and the overlay still renders its other recovery UI.
|
||||
expect(screen.queryByRole('button', { name: 'Open Externally' })).toBeNull()
|
||||
expect(screen.getByRole('button', { name: 'Retry' })).toBeEnabled()
|
||||
expect(screen.getByRole('button', { name: 'Copy Address' })).toBeEnabled()
|
||||
})
|
||||
|
||||
it('does not show local-certificate guidance for a public-host failure', () => {
|
||||
render(
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={{
|
||||
code: -202,
|
||||
description: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
validatedUrl: 'https://example.com/'
|
||||
}}
|
||||
externalUrl="https://example.com/"
|
||||
currentUrl="https://example.com/"
|
||||
httpsRecoveryUrl={null}
|
||||
{...callbacks}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.queryByText(/use a trusted local certificate/i)).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('offers approval only for a matching live challenge', () => {
|
||||
const { rerender } = render(
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={{
|
||||
code: -202,
|
||||
description: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
validatedUrl: 'https://localhost:3443/app'
|
||||
}}
|
||||
externalUrl={null}
|
||||
currentUrl="https://localhost:3443/app"
|
||||
httpsRecoveryUrl={null}
|
||||
certificateFailure={certificateFailure}
|
||||
expectedBrowserPageId="page-1"
|
||||
{...callbacks}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Proceed Anyway (Unsafe)' })).toBeEnabled()
|
||||
|
||||
rerender(
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={{
|
||||
code: -1,
|
||||
description: 'ERR_FAILED',
|
||||
validatedUrl: 'https://localhost:3443/app'
|
||||
}}
|
||||
externalUrl={null}
|
||||
currentUrl="https://localhost:3443/app"
|
||||
httpsRecoveryUrl={null}
|
||||
certificateFailure={certificateFailure}
|
||||
expectedBrowserPageId="page-1"
|
||||
{...callbacks}
|
||||
/>
|
||||
)
|
||||
expect(screen.getByText("Connection isn't secure")).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Proceed Anyway (Unsafe)' })).toBeEnabled()
|
||||
|
||||
rerender(
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={{
|
||||
code: -202,
|
||||
description: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
validatedUrl: 'https://localhost:3444/app'
|
||||
}}
|
||||
externalUrl={null}
|
||||
currentUrl="https://localhost:3444/app"
|
||||
httpsRecoveryUrl={null}
|
||||
certificateFailure={certificateFailure}
|
||||
expectedBrowserPageId="page-1"
|
||||
{...callbacks}
|
||||
/>
|
||||
)
|
||||
expect(screen.queryByRole('button', { name: 'Proceed Anyway (Unsafe)' })).toBeNull()
|
||||
|
||||
rerender(
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={{
|
||||
code: -202,
|
||||
description: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
validatedUrl: 'https://localhost:3443/app'
|
||||
}}
|
||||
externalUrl={null}
|
||||
currentUrl="https://localhost:3443/app"
|
||||
httpsRecoveryUrl={null}
|
||||
certificateFailure={certificateFailure}
|
||||
expectedBrowserPageId="other-page"
|
||||
{...callbacks}
|
||||
/>
|
||||
)
|
||||
expect(screen.queryByRole('button', { name: 'Proceed Anyway (Unsafe)' })).toBeNull()
|
||||
})
|
||||
|
||||
it('disables every action immediately and delays connecting feedback', async () => {
|
||||
vi.useFakeTimers()
|
||||
let resolveProceed: ((result: { ok: true }) => void) | null = null
|
||||
callbacks.onProceedCertificate.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
resolveProceed = resolve
|
||||
})
|
||||
)
|
||||
const { rerender } = render(
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={{
|
||||
code: -202,
|
||||
description: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
validatedUrl: 'https://localhost:3443/app'
|
||||
}}
|
||||
externalUrl="https://localhost:3443/app"
|
||||
currentUrl="https://localhost:3443/app"
|
||||
httpsRecoveryUrl={null}
|
||||
certificateFailure={certificateFailure}
|
||||
expectedBrowserPageId="page-1"
|
||||
{...callbacks}
|
||||
/>
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Proceed Anyway (Unsafe)' }))
|
||||
expect(callbacks.onProceedCertificate).toHaveBeenCalledWith('challenge-1')
|
||||
for (const name of ['Proceed Anyway (Unsafe)', 'Open Externally', 'Retry', 'Copy Address']) {
|
||||
expect(screen.getByRole('button', { name })).toBeDisabled()
|
||||
}
|
||||
expect(screen.queryByText('Connecting…')).toBeNull()
|
||||
|
||||
act(() => vi.advanceTimersByTime(199))
|
||||
expect(screen.queryByText('Connecting…')).toBeNull()
|
||||
act(() => vi.advanceTimersByTime(1))
|
||||
expect(screen.getByRole('button', { name: 'Connecting…' })).toBeDisabled()
|
||||
|
||||
await act(async () => resolveProceed?.({ ok: true }))
|
||||
rerender(
|
||||
<BrowserLoadFailureOverlay
|
||||
loadError={{
|
||||
code: -202,
|
||||
description: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
validatedUrl: 'https://localhost:3443/app'
|
||||
}}
|
||||
externalUrl="https://localhost:3443/app"
|
||||
currentUrl="https://localhost:3443/app"
|
||||
httpsRecoveryUrl={null}
|
||||
certificateFailure={null}
|
||||
expectedBrowserPageId="page-1"
|
||||
{...callbacks}
|
||||
/>
|
||||
)
|
||||
expect(screen.queryByRole('button', { name: 'Proceed Anyway (Unsafe)' })).toBeNull()
|
||||
expect(screen.getByRole('button', { name: 'Retry' })).toBeEnabled()
|
||||
})
|
||||
|
||||
it('recovers from typed approval failures and resets for a new challenge', async () => {
|
||||
callbacks.onProceedCertificate.mockResolvedValue({ ok: false, reason: 'expired' })
|
||||
const props = {
|
||||
loadError: {
|
||||
code: -202,
|
||||
description: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
validatedUrl: 'https://localhost:3443/app'
|
||||
},
|
||||
externalUrl: null,
|
||||
currentUrl: 'https://localhost:3443/app',
|
||||
httpsRecoveryUrl: null,
|
||||
expectedBrowserPageId: 'page-1',
|
||||
...callbacks
|
||||
}
|
||||
const { rerender } = render(
|
||||
<BrowserLoadFailureOverlay {...props} certificateFailure={certificateFailure} />
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Proceed Anyway (Unsafe)' }))
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('alert')).toHaveTextContent(/certificate approval expired/i)
|
||||
)
|
||||
expect(screen.getByRole('button', { name: 'Retry' })).toBeEnabled()
|
||||
|
||||
callbacks.onProceedCertificate.mockReturnValue(new Promise(() => {}))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Proceed Anyway (Unsafe)' }))
|
||||
expect(screen.getByRole('button', { name: 'Retry' })).toBeDisabled()
|
||||
rerender(
|
||||
<BrowserLoadFailureOverlay
|
||||
{...props}
|
||||
certificateFailure={{ ...certificateFailure, challengeId: 'challenge-2' }}
|
||||
/>
|
||||
)
|
||||
expect(screen.getByRole('button', { name: 'Proceed Anyway (Unsafe)' })).toBeEnabled()
|
||||
expect(screen.queryByRole('alert')).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,340 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { Copy, ExternalLink, Globe, Loader2, RefreshCw, ShieldAlert } from 'lucide-react'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import type {
|
||||
BrowserCertificateFailure,
|
||||
BrowserCertificateProceedFailureReason,
|
||||
BrowserCertificateProceedResult,
|
||||
BrowserLoadError
|
||||
} from '../../../../shared/types'
|
||||
import { isEligibleLocalCertificateHost } from '../../../../shared/browser-url'
|
||||
import {
|
||||
formatLoadFailureDescription,
|
||||
formatLoadFailureRecoveryHint,
|
||||
isCertificateLoadError,
|
||||
type LoadFailureMeta
|
||||
} from './browser-notices'
|
||||
|
||||
type BrowserLoadFailureOverlayProps = {
|
||||
loadError: BrowserLoadError
|
||||
externalUrl?: string | null
|
||||
currentUrl: string
|
||||
httpsRecoveryUrl: string | null
|
||||
onRetry: () => void
|
||||
onTryHttps: (url: string) => void
|
||||
onCopy: (url: string) => void
|
||||
onOpenExternal?: (url: string) => void
|
||||
certificateFailure?: BrowserCertificateFailure | null
|
||||
expectedBrowserPageId?: string | null
|
||||
onProceedCertificate?: (challengeId: string) => Promise<BrowserCertificateProceedResult>
|
||||
}
|
||||
|
||||
type CertificateProceedAttempt = {
|
||||
challengeId: string
|
||||
state: 'submitting' | 'failed'
|
||||
showConnecting: boolean
|
||||
reason?: BrowserCertificateProceedFailureReason | 'request-failed'
|
||||
}
|
||||
|
||||
function getLoadErrorMetadata(loadError: BrowserLoadError): LoadFailureMeta {
|
||||
try {
|
||||
const parsed = new URL(loadError.validatedUrl)
|
||||
return {
|
||||
host: parsed.host || null,
|
||||
isLocalhostLike:
|
||||
parsed.hostname === '0.0.0.0' || isEligibleLocalCertificateHost(parsed.hostname)
|
||||
}
|
||||
} catch {
|
||||
return { host: null, isLocalhostLike: false }
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeCertificateError(error: string): string {
|
||||
return error
|
||||
.trim()
|
||||
.replace(/^net::/i, '')
|
||||
.toUpperCase()
|
||||
}
|
||||
|
||||
function getMatchingCertificateFailure(args: {
|
||||
loadError: BrowserLoadError
|
||||
certificateFailure?: BrowserCertificateFailure | null
|
||||
expectedBrowserPageId?: string | null
|
||||
canProceed: boolean
|
||||
}): BrowserCertificateFailure | null {
|
||||
const { loadError, certificateFailure, expectedBrowserPageId, canProceed } = args
|
||||
const errorMatchesChallenge = Boolean(
|
||||
certificateFailure &&
|
||||
(loadError.code === -1 ||
|
||||
(loadError.code === certificateFailure.errorCode &&
|
||||
normalizeCertificateError(certificateFailure.error) ===
|
||||
normalizeCertificateError(loadError.description)))
|
||||
)
|
||||
if (
|
||||
!canProceed ||
|
||||
!certificateFailure?.canProceed ||
|
||||
!expectedBrowserPageId ||
|
||||
certificateFailure.browserPageId !== expectedBrowserPageId ||
|
||||
certificateFailure.errorCode !== -202 ||
|
||||
!errorMatchesChallenge
|
||||
) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
return new URL(loadError.validatedUrl).origin === certificateFailure.origin
|
||||
? certificateFailure
|
||||
: null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function formatCertificateProceedFailure(
|
||||
reason: BrowserCertificateProceedFailureReason | 'request-failed'
|
||||
): string {
|
||||
if (reason === 'expired') {
|
||||
return translate(
|
||||
'browser.loadFailure.certificateChallengeExpired',
|
||||
'This certificate approval expired. Retry the page to request a new one.'
|
||||
)
|
||||
}
|
||||
if (reason === 'changed' || reason === 'navigated') {
|
||||
return translate(
|
||||
'browser.loadFailure.certificateChallengeChanged',
|
||||
'The certificate request changed. Retry the page and review the new warning.'
|
||||
)
|
||||
}
|
||||
if (reason === 'request-failed') {
|
||||
return translate(
|
||||
'browser.loadFailure.certificateProceedFailed',
|
||||
'Orca could not approve this certificate request. Retry the page and try again.'
|
||||
)
|
||||
}
|
||||
return translate(
|
||||
'browser.loadFailure.certificateChallengeUnavailable',
|
||||
'This certificate request is no longer available. Retry the page to request a new one.'
|
||||
)
|
||||
}
|
||||
|
||||
export function BrowserLoadFailureOverlay({
|
||||
loadError,
|
||||
externalUrl,
|
||||
currentUrl,
|
||||
httpsRecoveryUrl,
|
||||
onRetry,
|
||||
onTryHttps,
|
||||
onCopy,
|
||||
onOpenExternal,
|
||||
certificateFailure,
|
||||
expectedBrowserPageId,
|
||||
onProceedCertificate
|
||||
}: BrowserLoadFailureOverlayProps): React.JSX.Element {
|
||||
const connectingTimerRef = useRef<{
|
||||
challengeId: string
|
||||
timer: ReturnType<typeof setTimeout>
|
||||
} | null>(null)
|
||||
const [proceedAttempt, setProceedAttempt] = useState<CertificateProceedAttempt | null>(null)
|
||||
const matchingCertificateFailure = getMatchingCertificateFailure({
|
||||
loadError,
|
||||
certificateFailure,
|
||||
expectedBrowserPageId,
|
||||
canProceed: Boolean(onProceedCertificate)
|
||||
})
|
||||
// Why: Chromium's error-page fallback can replace the diagnostic code with
|
||||
// -1 after main has already captured an exact live certificate challenge.
|
||||
const presentationLoadError =
|
||||
matchingCertificateFailure && loadError.code === -1
|
||||
? {
|
||||
...loadError,
|
||||
code: matchingCertificateFailure.errorCode ?? loadError.code,
|
||||
description: matchingCertificateFailure.error
|
||||
}
|
||||
: loadError
|
||||
const meta = getLoadErrorMetadata(presentationLoadError)
|
||||
const certificateError = isCertificateLoadError(presentationLoadError)
|
||||
const recoveryHint = formatLoadFailureRecoveryHint(meta, presentationLoadError)
|
||||
const activeProceedAttempt =
|
||||
proceedAttempt?.challengeId === matchingCertificateFailure?.challengeId ? proceedAttempt : null
|
||||
const actionsDisabled = activeProceedAttempt?.state === 'submitting'
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (connectingTimerRef.current) {
|
||||
clearTimeout(connectingTimerRef.current.timer)
|
||||
connectingTimerRef.current = null
|
||||
}
|
||||
}
|
||||
}, [matchingCertificateFailure?.challengeId])
|
||||
|
||||
const proceedCertificate = (): void => {
|
||||
if (!matchingCertificateFailure || !onProceedCertificate || actionsDisabled) {
|
||||
return
|
||||
}
|
||||
const challengeId = matchingCertificateFailure.challengeId
|
||||
setProceedAttempt({ challengeId, state: 'submitting', showConnecting: false })
|
||||
connectingTimerRef.current = {
|
||||
challengeId,
|
||||
timer: setTimeout(() => {
|
||||
setProceedAttempt((current) =>
|
||||
current?.challengeId === challengeId && current.state === 'submitting'
|
||||
? { ...current, showConnecting: true }
|
||||
: current
|
||||
)
|
||||
}, 200)
|
||||
}
|
||||
void onProceedCertificate(challengeId)
|
||||
.then((result) => {
|
||||
if (connectingTimerRef.current?.challengeId === challengeId) {
|
||||
clearTimeout(connectingTimerRef.current.timer)
|
||||
connectingTimerRef.current = null
|
||||
}
|
||||
if (!result.ok) {
|
||||
setProceedAttempt((current) =>
|
||||
current?.challengeId === challengeId
|
||||
? {
|
||||
challengeId,
|
||||
state: 'failed',
|
||||
showConnecting: false,
|
||||
reason: result.reason
|
||||
}
|
||||
: current
|
||||
)
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
if (connectingTimerRef.current?.challengeId === challengeId) {
|
||||
clearTimeout(connectingTimerRef.current.timer)
|
||||
connectingTimerRef.current = null
|
||||
}
|
||||
setProceedAttempt((current) =>
|
||||
current?.challengeId === challengeId
|
||||
? {
|
||||
challengeId,
|
||||
state: 'failed',
|
||||
showConnecting: false,
|
||||
reason: 'request-failed'
|
||||
}
|
||||
: current
|
||||
)
|
||||
})
|
||||
}
|
||||
const retryButton = (
|
||||
<Button
|
||||
size="sm"
|
||||
variant={certificateError && !externalUrl ? 'default' : 'outline'}
|
||||
className="h-9 gap-2 px-3"
|
||||
disabled={actionsDisabled}
|
||||
onClick={onRetry}
|
||||
>
|
||||
<RefreshCw className="size-4" />
|
||||
{translate('browser.loadFailure.retry', 'Retry')}
|
||||
</Button>
|
||||
)
|
||||
const copyButton = (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-9 gap-2 px-3"
|
||||
disabled={actionsDisabled}
|
||||
onClick={() => onCopy(currentUrl)}
|
||||
>
|
||||
<Copy className="size-4" />
|
||||
{translate('browser.loadFailure.copyAddress', 'Copy Address')}
|
||||
</Button>
|
||||
)
|
||||
const externalButton =
|
||||
externalUrl && onOpenExternal ? (
|
||||
<Button
|
||||
size="sm"
|
||||
variant={certificateError ? 'default' : 'ghost'}
|
||||
className="h-9 gap-2 px-3"
|
||||
disabled={actionsDisabled}
|
||||
onClick={() => onOpenExternal(externalUrl)}
|
||||
>
|
||||
<ExternalLink className="size-4" />
|
||||
{translate('browser.loadFailure.openExternally', 'Open Externally')}
|
||||
</Button>
|
||||
) : null
|
||||
|
||||
return (
|
||||
<div className="absolute inset-0 z-20 flex items-center justify-center bg-background px-6">
|
||||
<div aria-live="polite" className="flex max-w-lg flex-col items-center px-8 py-8 text-center">
|
||||
<div className="mb-4 rounded-full border border-border bg-muted p-3 text-muted-foreground">
|
||||
{certificateError ? <ShieldAlert className="size-5" /> : <Globe className="size-5" />}
|
||||
</div>
|
||||
<h2 className="text-base font-semibold text-foreground">
|
||||
{certificateError
|
||||
? translate('browser.loadFailure.connectionNotSecure', "Connection isn't secure")
|
||||
: meta.host
|
||||
? translate('browser.loadFailure.cantReachHost', "Can't reach {{value0}}", {
|
||||
value0: meta.host
|
||||
})
|
||||
: translate('browser.loadFailure.cantLoadPage', "Can't load this page")}
|
||||
</h2>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
{formatLoadFailureDescription(presentationLoadError, meta)}
|
||||
</p>
|
||||
{certificateError && meta.isLocalhostLike ? (
|
||||
<p className="mt-2 text-xs text-muted-foreground">
|
||||
{translate(
|
||||
'browser.loadFailure.trustedCertificateGuidance',
|
||||
'For local development, use a trusted local certificate when possible.'
|
||||
)}
|
||||
</p>
|
||||
) : null}
|
||||
{recoveryHint ? <p className="mt-2 text-xs text-muted-foreground">{recoveryHint}</p> : null}
|
||||
{activeProceedAttempt?.state === 'failed' && activeProceedAttempt.reason ? (
|
||||
<p role="alert" className="mt-3 text-xs text-destructive">
|
||||
{formatCertificateProceedFailure(activeProceedAttempt.reason)}
|
||||
</p>
|
||||
) : null}
|
||||
<div className="mt-5 flex flex-wrap items-center justify-center gap-2">
|
||||
{certificateError ? (
|
||||
<>
|
||||
{externalButton}
|
||||
{retryButton}
|
||||
{copyButton}
|
||||
{matchingCertificateFailure ? (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="h-9 w-48 gap-2 px-3"
|
||||
disabled={actionsDisabled}
|
||||
onClick={proceedCertificate}
|
||||
>
|
||||
{activeProceedAttempt?.state === 'submitting' &&
|
||||
activeProceedAttempt.showConnecting ? (
|
||||
<>
|
||||
<Loader2 className="size-4 animate-spin" />
|
||||
{translate('browser.loadFailure.connecting', 'Connecting…')}
|
||||
</>
|
||||
) : (
|
||||
translate('browser.loadFailure.proceedUnsafe', 'Proceed Anyway (Unsafe)')
|
||||
)}
|
||||
</Button>
|
||||
) : null}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{httpsRecoveryUrl ? (
|
||||
<Button
|
||||
size="sm"
|
||||
className="h-9 gap-2 px-3"
|
||||
disabled={actionsDisabled}
|
||||
onClick={() => onTryHttps(httpsRecoveryUrl)}
|
||||
>
|
||||
{translate('browser.loadFailure.tryHttps', 'Try HTTPS')}
|
||||
</Button>
|
||||
) : null}
|
||||
{retryButton}
|
||||
{copyButton}
|
||||
{externalButton}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -5,7 +5,8 @@ import {
|
||||
formatLoadFailureDescription,
|
||||
formatLoadFailureRecoveryHint,
|
||||
formatPermissionNotice,
|
||||
formatPopupNotice
|
||||
formatPopupNotice,
|
||||
isCertificateLoadError
|
||||
} from './browser-notices'
|
||||
|
||||
describe('browser notice formatting', () => {
|
||||
@@ -114,4 +115,29 @@ describe('browser notice formatting', () => {
|
||||
})
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('formats certificate failures without local-server recovery advice', () => {
|
||||
const meta = { host: 'localhost:3443', isLocalhostLike: true }
|
||||
const loadError = (code: number) => ({
|
||||
code,
|
||||
description: 'certificate error',
|
||||
validatedUrl: 'https://localhost:3443/'
|
||||
})
|
||||
|
||||
expect(formatLoadFailureDescription(loadError(-200), meta)).toBe(
|
||||
"The certificate doesn't match localhost:3443."
|
||||
)
|
||||
expect(formatLoadFailureDescription(loadError(-201), meta)).toBe(
|
||||
"The certificate for localhost:3443 isn't valid at the current date and time."
|
||||
)
|
||||
expect(formatLoadFailureDescription(loadError(-202), meta)).toBe(
|
||||
"Orca doesn't trust the authority that issued the certificate for localhost:3443."
|
||||
)
|
||||
expect(formatLoadFailureDescription(loadError(-208), meta)).toBe(
|
||||
"Orca couldn't verify the certificate for localhost:3443."
|
||||
)
|
||||
expect(isCertificateLoadError(loadError(-219))).toBe(true)
|
||||
expect(isCertificateLoadError(loadError(-215))).toBe(false)
|
||||
expect(formatLoadFailureRecoveryHint(meta, loadError(-202))).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,8 +4,10 @@ import type {
|
||||
BrowserPopupEvent
|
||||
} from '../../../../shared/browser-guest-events'
|
||||
import type { BrowserLoadError } from '../../../../shared/types'
|
||||
import { isChromiumCertificateErrorCode } from '../../../../shared/browser-certificate-errors'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
|
||||
type LoadFailureMeta = {
|
||||
export type LoadFailureMeta = {
|
||||
host: string | null
|
||||
isLocalhostLike: boolean
|
||||
}
|
||||
@@ -73,6 +75,35 @@ export function formatLoadFailureDescription(
|
||||
if (!loadError) {
|
||||
return 'The page did not respond.'
|
||||
}
|
||||
if (isChromiumCertificateErrorCode(loadError.code)) {
|
||||
const host = meta.host ?? 'this address'
|
||||
if (loadError.code === -200) {
|
||||
return translate(
|
||||
'browser.loadFailure.certificateNameMismatch',
|
||||
"The certificate doesn't match {{value0}}.",
|
||||
{ value0: host }
|
||||
)
|
||||
}
|
||||
if (loadError.code === -201) {
|
||||
return translate(
|
||||
'browser.loadFailure.certificateDateInvalid',
|
||||
"The certificate for {{value0}} isn't valid at the current date and time.",
|
||||
{ value0: host }
|
||||
)
|
||||
}
|
||||
if (loadError.code === -202) {
|
||||
return translate(
|
||||
'browser.loadFailure.certificateAuthorityInvalid',
|
||||
"Orca doesn't trust the authority that issued the certificate for {{value0}}.",
|
||||
{ value0: host }
|
||||
)
|
||||
}
|
||||
return translate(
|
||||
'browser.loadFailure.certificateVerificationFailed',
|
||||
"Orca couldn't verify the certificate for {{value0}}.",
|
||||
{ value0: host }
|
||||
)
|
||||
}
|
||||
if (meta.isLocalhostLike) {
|
||||
return "We couldn't connect to your local server."
|
||||
}
|
||||
@@ -82,9 +113,16 @@ export function formatLoadFailureDescription(
|
||||
return "We couldn't connect to this page."
|
||||
}
|
||||
|
||||
export function formatLoadFailureRecoveryHint(meta: LoadFailureMeta): string | null {
|
||||
if (!meta.isLocalhostLike) {
|
||||
export function formatLoadFailureRecoveryHint(
|
||||
meta: LoadFailureMeta,
|
||||
loadError?: BrowserLoadErrorLike
|
||||
): string | null {
|
||||
if (!meta.isLocalhostLike || (loadError && isChromiumCertificateErrorCode(loadError.code))) {
|
||||
return null
|
||||
}
|
||||
return 'If this should be a local app, make sure the server is running and listening on the expected port.'
|
||||
}
|
||||
|
||||
export function isCertificateLoadError(loadError: BrowserLoadErrorLike): boolean {
|
||||
return Boolean(loadError && isChromiumCertificateErrorCode(loadError.code))
|
||||
}
|
||||
|
||||
@@ -50,6 +50,15 @@ describe('tab create entry classification', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps the shared legacy local-dev forms in parity with address-bar normalization', () => {
|
||||
for (const input of ['0.0.0.0:3000', '[::1]:3000', '[2001:db8::1]:3000/path']) {
|
||||
expect(classifyTabEntryQuery(input, readyFiles([]))).toMatchObject({
|
||||
kind: 'host-url',
|
||||
url: expect.stringMatching(/^http:/)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('does not classify invalid numeric hosts as URLs', () => {
|
||||
expect(classifyTabEntryQuery('999.999.999.999', readyFiles([]))).toEqual({
|
||||
kind: 'new-file',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import { classifySchemeLessLocalDevAddress } from '../../../../shared/browser-url'
|
||||
|
||||
const HOST_FILE_EXTENSIONS = new Set([
|
||||
'css',
|
||||
@@ -15,9 +16,6 @@ const HOST_FILE_EXTENSIONS = new Set([
|
||||
'yml'
|
||||
])
|
||||
|
||||
const LOCAL_ADDRESS_PATTERN =
|
||||
/^(?:localhost|127(?:\.\d{1,3}){3}|0\.0\.0\.0|\[[0-9a-f:]+\])(?::\d+)?(?:[/?#].*)?$/i
|
||||
|
||||
const LOCALHOST_WITH_PORT_PATTERN = /^localhost(?::\d{1,5})?$/i
|
||||
const IPV4_WITH_PORT_PATTERN =
|
||||
/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?::\d{1,5})?$/
|
||||
@@ -33,7 +31,7 @@ export type HostUrlClassification = { kind: 'host-url'; url: string }
|
||||
export function classifyExplicitUrl(query: string): ExplicitUrlClassification | null {
|
||||
// Local dev inputs are handled by host-url classification so users can
|
||||
// enter localhost/IP addresses without an explicit scheme.
|
||||
if (LOCAL_ADDRESS_PATTERN.test(query)) {
|
||||
if (classifySchemeLessLocalDevAddress(query)) {
|
||||
return null
|
||||
}
|
||||
let url: URL
|
||||
@@ -55,15 +53,8 @@ export function classifyExplicitUrl(query: string): ExplicitUrlClassification |
|
||||
}
|
||||
|
||||
function classifyLocalDevUrl(query: string): HostUrlClassification | null {
|
||||
if (!LOCAL_ADDRESS_PATTERN.test(query)) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
const url = new URL(`http://${query}`)
|
||||
return url.hostname ? { kind: 'host-url', url: url.href } : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
const url = classifySchemeLessLocalDevAddress(query)
|
||||
return url?.hostname ? { kind: 'host-url', url: url.href } : null
|
||||
}
|
||||
|
||||
function classifyHostLikeUrl(query: string): HostUrlClassification | null {
|
||||
|
||||
@@ -2108,6 +2108,18 @@ export function useIpcEvents(): void {
|
||||
})
|
||||
)
|
||||
|
||||
const unsubscribeCertificateFailure = window.api.browser.onCertificateFailureChanged?.(
|
||||
({ browserPageId, failure }) => {
|
||||
if (isRuntimeEnvironmentActive()) {
|
||||
return
|
||||
}
|
||||
useAppStore.getState().setBrowserPageCertificateFailure(browserPageId, failure)
|
||||
}
|
||||
)
|
||||
if (unsubscribeCertificateFailure) {
|
||||
unsubs.push(unsubscribeCertificateFailure)
|
||||
}
|
||||
|
||||
// Why: agent-browser drives navigation via CDP, bypassing Electron's webview
|
||||
// event system. The renderer's did-navigate listener never fires for those
|
||||
// navigations, so the Zustand store (address bar, tab title) stays stale.
|
||||
|
||||
@@ -7,6 +7,29 @@
|
||||
"webDescription": "Retry the web client or reconnect to the paired runtime."
|
||||
}
|
||||
},
|
||||
"browser": {
|
||||
"loadFailure": {
|
||||
"connectionNotSecure": "Connection isn't secure",
|
||||
"cantReachHost": "Can't reach {{value0}}",
|
||||
"cantLoadPage": "Can't load this page",
|
||||
"certificateNameMismatch": "The certificate doesn't match {{value0}}.",
|
||||
"certificateDateInvalid": "The certificate for {{value0}} isn't valid at the current date and time.",
|
||||
"certificateAuthorityInvalid": "Orca doesn't trust the authority that issued the certificate for {{value0}}.",
|
||||
"certificateVerificationFailed": "Orca couldn't verify the certificate for {{value0}}.",
|
||||
"trustedCertificateGuidance": "For local development, use a trusted local certificate when possible.",
|
||||
"retry": "Retry",
|
||||
"copyAddress": "Copy Address",
|
||||
"addressCopied": "Copied the current page address.",
|
||||
"openExternally": "Open Externally",
|
||||
"tryHttps": "Try HTTPS",
|
||||
"proceedUnsafe": "Proceed Anyway (Unsafe)",
|
||||
"connecting": "Connecting…",
|
||||
"certificateChallengeExpired": "This certificate approval expired. Retry the page to request a new one.",
|
||||
"certificateChallengeChanged": "The certificate request changed. Retry the page and review the new warning.",
|
||||
"certificateChallengeUnavailable": "This certificate request is no longer available. Retry the page to request a new one.",
|
||||
"certificateProceedFailed": "Orca could not approve this certificate request. Retry the page and try again."
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"appearance": {
|
||||
"language": {
|
||||
|
||||
@@ -13284,5 +13284,28 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"browser": {
|
||||
"loadFailure": {
|
||||
"connectionNotSecure": "Connection isn't secure",
|
||||
"cantReachHost": "Can't reach {{value0}}",
|
||||
"cantLoadPage": "Can't load this page",
|
||||
"certificateNameMismatch": "The certificate doesn't match {{value0}}.",
|
||||
"certificateDateInvalid": "The certificate for {{value0}} isn't valid at the current date and time.",
|
||||
"certificateAuthorityInvalid": "Orca doesn't trust the authority that issued the certificate for {{value0}}.",
|
||||
"certificateVerificationFailed": "Orca couldn't verify the certificate for {{value0}}.",
|
||||
"trustedCertificateGuidance": "For local development, use a trusted local certificate when possible.",
|
||||
"retry": "Retry",
|
||||
"copyAddress": "Copy Address",
|
||||
"addressCopied": "Copied the current page address.",
|
||||
"openExternally": "Open Externally",
|
||||
"tryHttps": "Try HTTPS",
|
||||
"proceedUnsafe": "Proceed Anyway (Unsafe)",
|
||||
"connecting": "Connecting…",
|
||||
"certificateChallengeExpired": "This certificate approval expired. Retry the page to request a new one.",
|
||||
"certificateChallengeChanged": "The certificate request changed. Retry the page and review the new warning.",
|
||||
"certificateChallengeUnavailable": "This certificate request is no longer available. Retry the page to request a new one.",
|
||||
"certificateProceedFailed": "Orca could not approve this certificate request. Retry the page and try again."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13284,5 +13284,28 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"browser": {
|
||||
"loadFailure": {
|
||||
"connectionNotSecure": "Connection isn't secure",
|
||||
"cantReachHost": "Can't reach {{value0}}",
|
||||
"cantLoadPage": "Can't load this page",
|
||||
"certificateNameMismatch": "The certificate doesn't match {{value0}}.",
|
||||
"certificateDateInvalid": "The certificate for {{value0}} isn't valid at the current date and time.",
|
||||
"certificateAuthorityInvalid": "Orca doesn't trust the authority that issued the certificate for {{value0}}.",
|
||||
"certificateVerificationFailed": "Orca couldn't verify the certificate for {{value0}}.",
|
||||
"trustedCertificateGuidance": "For local development, use a trusted local certificate when possible.",
|
||||
"retry": "Retry",
|
||||
"copyAddress": "Copy Address",
|
||||
"addressCopied": "Copied the current page address.",
|
||||
"openExternally": "Open Externally",
|
||||
"tryHttps": "Try HTTPS",
|
||||
"proceedUnsafe": "Proceed Anyway (Unsafe)",
|
||||
"connecting": "Connecting…",
|
||||
"certificateChallengeExpired": "This certificate approval expired. Retry the page to request a new one.",
|
||||
"certificateChallengeChanged": "The certificate request changed. Retry the page and review the new warning.",
|
||||
"certificateChallengeUnavailable": "This certificate request is no longer available. Retry the page to request a new one.",
|
||||
"certificateProceedFailed": "Orca could not approve this certificate request. Retry the page and try again."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13284,5 +13284,28 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"browser": {
|
||||
"loadFailure": {
|
||||
"connectionNotSecure": "Connection isn't secure",
|
||||
"cantReachHost": "Can't reach {{value0}}",
|
||||
"cantLoadPage": "Can't load this page",
|
||||
"certificateNameMismatch": "The certificate doesn't match {{value0}}.",
|
||||
"certificateDateInvalid": "The certificate for {{value0}} isn't valid at the current date and time.",
|
||||
"certificateAuthorityInvalid": "Orca doesn't trust the authority that issued the certificate for {{value0}}.",
|
||||
"certificateVerificationFailed": "Orca couldn't verify the certificate for {{value0}}.",
|
||||
"trustedCertificateGuidance": "For local development, use a trusted local certificate when possible.",
|
||||
"retry": "Retry",
|
||||
"copyAddress": "Copy Address",
|
||||
"addressCopied": "Copied the current page address.",
|
||||
"openExternally": "Open Externally",
|
||||
"tryHttps": "Try HTTPS",
|
||||
"proceedUnsafe": "Proceed Anyway (Unsafe)",
|
||||
"connecting": "Connecting…",
|
||||
"certificateChallengeExpired": "This certificate approval expired. Retry the page to request a new one.",
|
||||
"certificateChallengeChanged": "The certificate request changed. Retry the page and review the new warning.",
|
||||
"certificateChallengeUnavailable": "This certificate request is no longer available. Retry the page to request a new one.",
|
||||
"certificateProceedFailed": "Orca could not approve this certificate request. Retry the page and try again."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13284,5 +13284,28 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"browser": {
|
||||
"loadFailure": {
|
||||
"connectionNotSecure": "Connection isn't secure",
|
||||
"cantReachHost": "Can't reach {{value0}}",
|
||||
"cantLoadPage": "Can't load this page",
|
||||
"certificateNameMismatch": "The certificate doesn't match {{value0}}.",
|
||||
"certificateDateInvalid": "The certificate for {{value0}} isn't valid at the current date and time.",
|
||||
"certificateAuthorityInvalid": "Orca doesn't trust the authority that issued the certificate for {{value0}}.",
|
||||
"certificateVerificationFailed": "Orca couldn't verify the certificate for {{value0}}.",
|
||||
"trustedCertificateGuidance": "For local development, use a trusted local certificate when possible.",
|
||||
"retry": "Retry",
|
||||
"copyAddress": "Copy Address",
|
||||
"addressCopied": "Copied the current page address.",
|
||||
"openExternally": "Open Externally",
|
||||
"tryHttps": "Try HTTPS",
|
||||
"proceedUnsafe": "Proceed Anyway (Unsafe)",
|
||||
"connecting": "Connecting…",
|
||||
"certificateChallengeExpired": "This certificate approval expired. Retry the page to request a new one.",
|
||||
"certificateChallengeChanged": "The certificate request changed. Retry the page and review the new warning.",
|
||||
"certificateChallengeUnavailable": "This certificate request is no longer available. Retry the page to request a new one.",
|
||||
"certificateProceedFailed": "Orca could not approve this certificate request. Retry the page and try again."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ function makeState(overrides: Partial<WebSessionTabsSyncState> = {}): WebSession
|
||||
activeWorktreeId: WT,
|
||||
agentStatusByPaneKey: {},
|
||||
agentStatusEpoch: 0,
|
||||
browserCertificateFailuresByPageId: {},
|
||||
browserPagesByWorkspace: {},
|
||||
browserTabsByWorktree: {},
|
||||
groupsByWorktree: {},
|
||||
|
||||
@@ -20,6 +20,7 @@ function makeState(overrides: Partial<AppState> = {}): AppState {
|
||||
activeBrowserTabIdByWorktree: {},
|
||||
browserTabsByWorktree: {},
|
||||
browserPagesByWorkspace: {},
|
||||
browserCertificateFailuresByPageId: {},
|
||||
openFiles: [],
|
||||
editorDrafts: {},
|
||||
activeTabId: null,
|
||||
@@ -103,7 +104,19 @@ describe('browser mobile session sync', () => {
|
||||
createdAt: 1
|
||||
}
|
||||
]
|
||||
} as unknown as AppState['browserPagesByWorkspace']
|
||||
} as unknown as AppState['browserPagesByWorkspace'],
|
||||
browserCertificateFailuresByPageId: {
|
||||
'page-1': {
|
||||
challengeId: 'challenge-1',
|
||||
browserPageId: 'page-1',
|
||||
errorCode: -202,
|
||||
error: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
origin: 'https://localhost:3443',
|
||||
displayHost: 'localhost:3443',
|
||||
canProceed: true,
|
||||
observedAt: 123
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
expect(buildMobileSessionTabSnapshots(state)[0]?.tabs).toMatchObject([
|
||||
@@ -115,11 +128,40 @@ describe('browser mobile session sync', () => {
|
||||
title: 'Example Page',
|
||||
url: 'https://example.com/path',
|
||||
canGoBack: true,
|
||||
certificateFailure: {
|
||||
challengeId: 'challenge-1',
|
||||
browserPageId: 'page-1'
|
||||
},
|
||||
isActive: true
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('does not resurrect a stale workspace failure after the active page clears it', () => {
|
||||
const staleError = {
|
||||
code: -202,
|
||||
description: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
validatedUrl: 'https://localhost:3443/'
|
||||
}
|
||||
const workspace = { ...makeBrowserWorkspace(), loadError: staleError }
|
||||
const activePage = {
|
||||
...workspace,
|
||||
id: 'page-1',
|
||||
workspaceId: workspace.id,
|
||||
loadError: null
|
||||
}
|
||||
const state = makeState({
|
||||
activeBrowserTabIdByWorktree: { 'wt-1': workspace.id },
|
||||
browserTabsByWorktree: { 'wt-1': [workspace] },
|
||||
browserPagesByWorkspace: { [workspace.id]: [activePage] }
|
||||
})
|
||||
|
||||
expect(buildMobileSessionTabSnapshots(state)[0]?.tabs[0]).toMatchObject({
|
||||
type: 'browser',
|
||||
loadError: null
|
||||
})
|
||||
})
|
||||
|
||||
it('publishes fallback browser tabs by workspace id when no unified tab exists', () => {
|
||||
const state = makeState({
|
||||
activeBrowserTabIdByWorktree: { 'wt-1': 'browser-1' },
|
||||
|
||||
@@ -1492,6 +1492,12 @@ function buildMobileBrowserTab(
|
||||
loading: activePage?.loading ?? workspace.loading,
|
||||
canGoBack: activePage?.canGoBack ?? workspace.canGoBack,
|
||||
canGoForward: activePage?.canGoForward ?? workspace.canGoForward,
|
||||
// Why: null means the active page successfully cleared its failure. Falling
|
||||
// back through ?? would resurrect a stale workspace-level error.
|
||||
loadError: activePage ? activePage.loadError : workspace.loadError,
|
||||
certificateFailure: activePage
|
||||
? (state.browserCertificateFailuresByPageId[activePage.id] ?? null)
|
||||
: null,
|
||||
color: unifiedTab?.color ?? null,
|
||||
isPinned: unifiedTab?.isPinned === true,
|
||||
isActive: unifiedTabId
|
||||
|
||||
@@ -64,6 +64,7 @@ function makeState(overrides: Partial<WebSessionTabsSyncState> = {}): WebSession
|
||||
activeWorktreeId: WT,
|
||||
agentStatusByPaneKey: {},
|
||||
agentStatusEpoch: 0,
|
||||
browserCertificateFailuresByPageId: {},
|
||||
browserPagesByWorkspace: {},
|
||||
browserTabsByWorktree: {},
|
||||
groupsByWorktree: {},
|
||||
@@ -2359,6 +2360,21 @@ describe('applyWebSessionTabsSnapshot', () => {
|
||||
loading: false,
|
||||
canGoBack: true,
|
||||
canGoForward: false,
|
||||
loadError: {
|
||||
code: -202,
|
||||
description: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
validatedUrl: 'https://localhost:3443/'
|
||||
},
|
||||
certificateFailure: {
|
||||
challengeId: 'challenge-1',
|
||||
browserPageId: 'host-browser-page',
|
||||
errorCode: -202,
|
||||
error: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
origin: 'https://localhost:3443',
|
||||
displayHost: 'localhost:3443',
|
||||
canProceed: true,
|
||||
observedAt: 123
|
||||
},
|
||||
color: '#3b82f6',
|
||||
isPinned: true,
|
||||
isActive: true
|
||||
@@ -2390,13 +2406,28 @@ describe('applyWebSessionTabsSnapshot', () => {
|
||||
worktreeId: WT,
|
||||
url: 'https://example.com/',
|
||||
title: 'Example Domain',
|
||||
loading: false
|
||||
loading: false,
|
||||
loadError: {
|
||||
code: -202,
|
||||
description: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
validatedUrl: 'https://localhost:3443/'
|
||||
}
|
||||
}
|
||||
])
|
||||
expect(patch.remoteBrowserPageHandlesByPageId?.['host-browser-page']).toEqual({
|
||||
environmentId: ENV,
|
||||
remotePageId: 'host-browser-page'
|
||||
})
|
||||
expect(patch.browserCertificateFailuresByPageId?.['host-browser-page']).toEqual({
|
||||
challengeId: 'challenge-1',
|
||||
browserPageId: 'host-browser-page',
|
||||
errorCode: -202,
|
||||
error: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
origin: 'https://localhost:3443',
|
||||
displayHost: 'localhost:3443',
|
||||
canProceed: true,
|
||||
observedAt: 123
|
||||
})
|
||||
expect(patch.unifiedTabsByWorktree?.[WT]).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
@@ -2888,6 +2919,18 @@ describe('applyWebSessionTabsSnapshot', () => {
|
||||
remoteBrowserPageHandlesByPageId: {
|
||||
[page.id]: { environmentId: ENV, remotePageId: 'host-browser-page' }
|
||||
},
|
||||
browserCertificateFailuresByPageId: {
|
||||
[page.id]: {
|
||||
challengeId: 'stale-challenge',
|
||||
browserPageId: 'host-browser-page',
|
||||
errorCode: -202,
|
||||
error: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
origin: 'https://localhost:3443',
|
||||
displayHost: 'localhost:3443',
|
||||
canProceed: true,
|
||||
observedAt: 100
|
||||
}
|
||||
},
|
||||
openFiles: [file],
|
||||
unifiedTabsByWorktree: { [WT]: existingTabs }
|
||||
}),
|
||||
@@ -2945,6 +2988,9 @@ describe('applyWebSessionTabsSnapshot', () => {
|
||||
})
|
||||
])
|
||||
)
|
||||
// Why: older runtimes omit this transient field. Omission must clear an
|
||||
// earlier challenge instead of leaving an unsafe action wired to stale RPC input.
|
||||
expect(patch.browserCertificateFailuresByPageId).toEqual({})
|
||||
})
|
||||
|
||||
it('uses local markdown preview file ids while preserving the host unified tab id', () => {
|
||||
|
||||
@@ -19,6 +19,7 @@ import type {
|
||||
RuntimeMobileSessionTerminalClientTab
|
||||
} from '../../../shared/runtime-types'
|
||||
import type {
|
||||
BrowserCertificateFailure,
|
||||
BrowserPage,
|
||||
BrowserWorkspace,
|
||||
Tab,
|
||||
@@ -104,6 +105,7 @@ type MirroredTerminalTab = {
|
||||
type MirroredBrowserTab = {
|
||||
workspace: BrowserWorkspace
|
||||
page: BrowserPage
|
||||
certificateFailure: BrowserCertificateFailure | null
|
||||
remotePageId: string
|
||||
unifiedTab: Tab
|
||||
hostTabId: string
|
||||
@@ -130,6 +132,7 @@ export type WebSessionTabsSyncState = Pick<
|
||||
| 'agentStatusByPaneKey'
|
||||
| 'agentStatusEpoch'
|
||||
| 'browserPagesByWorkspace'
|
||||
| 'browserCertificateFailuresByPageId'
|
||||
| 'browserTabsByWorktree'
|
||||
| 'groupsByWorktree'
|
||||
| 'layoutByWorktree'
|
||||
@@ -951,7 +954,7 @@ function buildMirroredBrowserTabs(
|
||||
faviconUrl: existing?.page.faviconUrl ?? null,
|
||||
canGoBack: tab.canGoBack,
|
||||
canGoForward: tab.canGoForward,
|
||||
loadError: null,
|
||||
loadError: tab.loadError ?? null,
|
||||
createdAt,
|
||||
browserRuntimeEnvironmentId: environmentId,
|
||||
viewportPresetId: existing?.page.viewportPresetId ?? null
|
||||
@@ -975,6 +978,7 @@ function buildMirroredBrowserTabs(
|
||||
return {
|
||||
workspace,
|
||||
page,
|
||||
certificateFailure: tab.certificateFailure ?? null,
|
||||
remotePageId: tab.browserPageId,
|
||||
unifiedTab: buildBrowserUnifiedTab(workspace, tab, existing?.unifiedTab ?? null, groupId),
|
||||
hostTabId: tab.id
|
||||
@@ -1478,6 +1482,29 @@ function browserPageEqual(a: BrowserPage, b: BrowserPage): boolean {
|
||||
)
|
||||
}
|
||||
|
||||
function browserCertificateFailureEqual(
|
||||
a: BrowserCertificateFailure | null | undefined,
|
||||
b: BrowserCertificateFailure | null | undefined
|
||||
): boolean {
|
||||
const left = a ?? null
|
||||
const right = b ?? null
|
||||
if (left === right) {
|
||||
return true
|
||||
}
|
||||
return Boolean(
|
||||
left &&
|
||||
right &&
|
||||
left.challengeId === right.challengeId &&
|
||||
left.browserPageId === right.browserPageId &&
|
||||
left.errorCode === right.errorCode &&
|
||||
left.error === right.error &&
|
||||
left.origin === right.origin &&
|
||||
left.displayHost === right.displayHost &&
|
||||
left.canProceed === right.canProceed &&
|
||||
left.observedAt === right.observedAt
|
||||
)
|
||||
}
|
||||
|
||||
function sameBrowserPages(
|
||||
a: readonly BrowserPage[] | undefined,
|
||||
b: readonly BrowserPage[] | null
|
||||
@@ -2135,6 +2162,7 @@ export function applyWebSessionTabsSnapshot(
|
||||
|
||||
let nextBrowserPagesByWorkspace = state.browserPagesByWorkspace
|
||||
let nextRemoteBrowserPageHandlesByPageId = state.remoteBrowserPageHandlesByPageId
|
||||
let nextBrowserCertificateFailuresByPageId = state.browserCertificateFailuresByPageId
|
||||
for (const removedWorkspaceId of removedBrowserWorkspaceIds) {
|
||||
const pages = nextBrowserPagesByWorkspace[removedWorkspaceId] ?? []
|
||||
if (nextBrowserPagesByWorkspace[removedWorkspaceId]) {
|
||||
@@ -2145,6 +2173,13 @@ export function applyWebSessionTabsSnapshot(
|
||||
delete nextBrowserPagesByWorkspace[removedWorkspaceId]
|
||||
}
|
||||
for (const page of pages) {
|
||||
if (nextBrowserCertificateFailuresByPageId[page.id]) {
|
||||
nextBrowserCertificateFailuresByPageId =
|
||||
nextBrowserCertificateFailuresByPageId === state.browserCertificateFailuresByPageId
|
||||
? { ...state.browserCertificateFailuresByPageId }
|
||||
: nextBrowserCertificateFailuresByPageId
|
||||
delete nextBrowserCertificateFailuresByPageId[page.id]
|
||||
}
|
||||
if (nextRemoteBrowserPageHandlesByPageId[page.id]) {
|
||||
nextRemoteBrowserPageHandlesByPageId =
|
||||
nextRemoteBrowserPageHandlesByPageId === state.remoteBrowserPageHandlesByPageId
|
||||
@@ -2154,7 +2189,7 @@ export function applyWebSessionTabsSnapshot(
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const { page, remotePageId } of mirroredBrowserTabs) {
|
||||
for (const { page, certificateFailure, remotePageId } of mirroredBrowserTabs) {
|
||||
const current = nextBrowserPagesByWorkspace[page.workspaceId] ?? []
|
||||
if (!sameBrowserPages(current, [page])) {
|
||||
nextBrowserPagesByWorkspace =
|
||||
@@ -2177,6 +2212,22 @@ export function applyWebSessionTabsSnapshot(
|
||||
remotePageId
|
||||
}
|
||||
}
|
||||
if (
|
||||
!browserCertificateFailureEqual(
|
||||
nextBrowserCertificateFailuresByPageId[page.id],
|
||||
certificateFailure
|
||||
)
|
||||
) {
|
||||
nextBrowserCertificateFailuresByPageId =
|
||||
nextBrowserCertificateFailuresByPageId === state.browserCertificateFailuresByPageId
|
||||
? { ...state.browserCertificateFailuresByPageId }
|
||||
: nextBrowserCertificateFailuresByPageId
|
||||
if (certificateFailure) {
|
||||
nextBrowserCertificateFailuresByPageId[page.id] = certificateFailure
|
||||
} else {
|
||||
delete nextBrowserCertificateFailuresByPageId[page.id]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const nextTabsByWorktree = withWorktreeEntry(
|
||||
@@ -2383,6 +2434,9 @@ export function applyWebSessionTabsSnapshot(
|
||||
...(nextRemoteBrowserPageHandlesByPageId !== state.remoteBrowserPageHandlesByPageId
|
||||
? { remoteBrowserPageHandlesByPageId: nextRemoteBrowserPageHandlesByPageId }
|
||||
: {}),
|
||||
...(nextBrowserCertificateFailuresByPageId !== state.browserCertificateFailuresByPageId
|
||||
? { browserCertificateFailuresByPageId: nextBrowserCertificateFailuresByPageId }
|
||||
: {}),
|
||||
...(nextActiveTabIdByWorktree !== state.activeTabIdByWorktree
|
||||
? { activeTabIdByWorktree: nextActiveTabIdByWorktree }
|
||||
: {}),
|
||||
|
||||
@@ -180,6 +180,39 @@ describe('createBrowserSlice annotations', () => {
|
||||
expect(store.getState().browserAnnotationsByPageId[pageId]).toBeUndefined()
|
||||
})
|
||||
|
||||
it('keeps certificate challenges transient across navigation, success, and close', () => {
|
||||
const store = createTestStore()
|
||||
const tab = store.getState().createBrowserTab('wt-1', 'https://localhost:3443/')
|
||||
const pageId = tab.activePageId
|
||||
if (!pageId) {
|
||||
throw new Error('Expected a new browser page')
|
||||
}
|
||||
const failure = {
|
||||
challengeId: 'challenge-1',
|
||||
browserPageId: pageId,
|
||||
errorCode: -202,
|
||||
error: 'ERR_CERT_AUTHORITY_INVALID',
|
||||
origin: 'https://localhost:3443',
|
||||
displayHost: 'localhost:3443',
|
||||
canProceed: true,
|
||||
observedAt: 123
|
||||
}
|
||||
|
||||
store.getState().setBrowserPageCertificateFailure(pageId, failure)
|
||||
expect(store.getState().browserCertificateFailuresByPageId[pageId]).toEqual(failure)
|
||||
|
||||
store.getState().setBrowserPageUrl(pageId, 'https://localhost:3443/next')
|
||||
expect(store.getState().browserCertificateFailuresByPageId[pageId]).toBeUndefined()
|
||||
|
||||
store.getState().setBrowserPageCertificateFailure(pageId, failure)
|
||||
store.getState().updateBrowserPageState(pageId, { loadError: null })
|
||||
expect(store.getState().browserCertificateFailuresByPageId[pageId]).toBeUndefined()
|
||||
|
||||
store.getState().setBrowserPageCertificateFailure(pageId, failure)
|
||||
store.getState().closeBrowserTab(tab.id)
|
||||
expect(store.getState().browserCertificateFailuresByPageId[pageId]).toBeUndefined()
|
||||
})
|
||||
|
||||
it('creates inactive browser unified tabs without stealing the visible tab', () => {
|
||||
const store = createTestStore()
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { AppState } from '../types'
|
||||
import type {
|
||||
BrowserCookieImportResult,
|
||||
BrowserCookieImportSummary,
|
||||
BrowserCertificateFailure,
|
||||
BrowserHistoryEntry,
|
||||
BrowserLoadError,
|
||||
BrowserPage,
|
||||
@@ -117,6 +118,7 @@ export type RemoteBrowserPageHandle = {
|
||||
export type BrowserSlice = {
|
||||
browserTabsByWorktree: Record<string, BrowserWorkspace[]>
|
||||
browserPagesByWorkspace: Record<string, BrowserPage[]>
|
||||
browserCertificateFailuresByPageId: Record<string, BrowserCertificateFailure>
|
||||
browserAnnotationsByPageId: Record<string, BrowserPageAnnotation[]>
|
||||
remoteBrowserPageHandlesByPageId: Record<string, RemoteBrowserPageHandle>
|
||||
activeBrowserTabId: string | null
|
||||
@@ -159,6 +161,10 @@ export type BrowserSlice = {
|
||||
consumeAddressBarFocusRequest: (pageId: string) => boolean
|
||||
updateBrowserTabPageState: (pageId: string, updates: BrowserTabPageState) => void
|
||||
updateBrowserPageState: (pageId: string, updates: BrowserTabPageState) => void
|
||||
setBrowserPageCertificateFailure: (
|
||||
pageId: string,
|
||||
failure: BrowserCertificateFailure | null
|
||||
) => void
|
||||
setBrowserTabUrl: (pageId: string, url: string) => void
|
||||
setBrowserPageUrl: (pageId: string, url: string) => void
|
||||
setRemoteBrowserPageHandle: (pageId: string, handle: RemoteBrowserPageHandle) => void
|
||||
@@ -473,6 +479,7 @@ function findPage(
|
||||
export const createBrowserSlice: StateCreator<AppState, [], [], BrowserSlice> = (set, get) => ({
|
||||
browserTabsByWorktree: {},
|
||||
browserPagesByWorkspace: {},
|
||||
browserCertificateFailuresByPageId: {},
|
||||
browserAnnotationsByPageId: {},
|
||||
remoteBrowserPageHandlesByPageId: {},
|
||||
activeBrowserTabId: null,
|
||||
@@ -675,8 +682,12 @@ export const createBrowserSlice: StateCreator<AppState, [], [], BrowserSlice> =
|
||||
const nextBrowserPagesByWorkspace = { ...s.browserPagesByWorkspace }
|
||||
delete nextBrowserPagesByWorkspace[tabId]
|
||||
const nextBrowserAnnotationsByPageId = { ...s.browserAnnotationsByPageId }
|
||||
const nextBrowserCertificateFailuresByPageId = {
|
||||
...s.browserCertificateFailuresByPageId
|
||||
}
|
||||
for (const page of closedPages) {
|
||||
delete nextBrowserAnnotationsByPageId[page.id]
|
||||
delete nextBrowserCertificateFailuresByPageId[page.id]
|
||||
}
|
||||
remotePagesToClose = closedPages.flatMap((page) => {
|
||||
const handle = s.remoteBrowserPageHandlesByPageId[page.id]
|
||||
@@ -766,6 +777,7 @@ export const createBrowserSlice: StateCreator<AppState, [], [], BrowserSlice> =
|
||||
recentlyClosedTabKindsByWorktree: nextRecentlyClosedTabKindsByWorktree,
|
||||
recentlyClosedBrowserPagesByWorkspace: nextRecentlyClosedBrowserPagesByWorkspace,
|
||||
remoteBrowserPageHandlesByPageId: nextRemoteBrowserPageHandlesByPageId,
|
||||
browserCertificateFailuresByPageId: nextBrowserCertificateFailuresByPageId,
|
||||
browserAnnotationsByPageId: nextBrowserAnnotationsByPageId
|
||||
}
|
||||
})
|
||||
@@ -1040,6 +1052,10 @@ export const createBrowserSlice: StateCreator<AppState, [], [], BrowserSlice> =
|
||||
delete nextRemoteBrowserPageHandlesByPageId[pageId]
|
||||
const nextBrowserAnnotationsByPageId = { ...s.browserAnnotationsByPageId }
|
||||
delete nextBrowserAnnotationsByPageId[pageId]
|
||||
const nextBrowserCertificateFailuresByPageId = {
|
||||
...s.browserCertificateFailuresByPageId
|
||||
}
|
||||
delete nextBrowserCertificateFailuresByPageId[pageId]
|
||||
|
||||
return {
|
||||
browserPagesByWorkspace: {
|
||||
@@ -1072,6 +1088,7 @@ export const createBrowserSlice: StateCreator<AppState, [], [], BrowserSlice> =
|
||||
)
|
||||
),
|
||||
remoteBrowserPageHandlesByPageId: nextRemoteBrowserPageHandlesByPageId,
|
||||
browserCertificateFailuresByPageId: nextBrowserCertificateFailuresByPageId,
|
||||
browserAnnotationsByPageId: nextBrowserAnnotationsByPageId
|
||||
}
|
||||
})
|
||||
@@ -1367,6 +1384,32 @@ export const createBrowserSlice: StateCreator<AppState, [], [], BrowserSlice> =
|
||||
}
|
||||
return nextState
|
||||
})
|
||||
if (updates.loadError === null) {
|
||||
get().setBrowserPageCertificateFailure(pageId, null)
|
||||
}
|
||||
},
|
||||
|
||||
setBrowserPageCertificateFailure: (pageId, failure) => {
|
||||
set((s) => {
|
||||
const current = s.browserCertificateFailuresByPageId[pageId]
|
||||
if (failure === null) {
|
||||
if (!current) {
|
||||
return s
|
||||
}
|
||||
const nextFailures = { ...s.browserCertificateFailuresByPageId }
|
||||
delete nextFailures[pageId]
|
||||
return { browserCertificateFailuresByPageId: nextFailures }
|
||||
}
|
||||
if (!findPage(s.browserPagesByWorkspace, pageId) || current === failure) {
|
||||
return s
|
||||
}
|
||||
return {
|
||||
browserCertificateFailuresByPageId: {
|
||||
...s.browserCertificateFailuresByPageId,
|
||||
[pageId]: failure
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
setBrowserTabUrl: (pageId, url) => get().setBrowserPageUrl(pageId, url),
|
||||
@@ -1425,6 +1468,7 @@ export const createBrowserSlice: StateCreator<AppState, [], [], BrowserSlice> =
|
||||
: {})
|
||||
}
|
||||
})
|
||||
get().setBrowserPageCertificateFailure(pageId, null)
|
||||
},
|
||||
|
||||
setRemoteBrowserPageHandle: (pageId, handle) => {
|
||||
@@ -1688,6 +1732,7 @@ export const createBrowserSlice: StateCreator<AppState, [], [], BrowserSlice> =
|
||||
activeTabTypeByWorktree: nextActiveTabTypeByWorktree,
|
||||
activeTabType,
|
||||
remoteBrowserPageHandlesByPageId: {},
|
||||
browserCertificateFailuresByPageId: {},
|
||||
browserAnnotationsByPageId: {},
|
||||
browserUrlHistory: normalizeBrowserHistoryEntries(session.browserUrlHistory ?? [])
|
||||
}
|
||||
|
||||
@@ -1993,12 +1993,14 @@ function createGitApi(): NonNullable<Partial<PreloadApi>['git']> {
|
||||
|
||||
function createBrowserApi(): NonNullable<Partial<PreloadApi>['browser']> {
|
||||
return {
|
||||
registerGuest: () => Promise.resolve(),
|
||||
registerGuest: () => Promise.resolve(false),
|
||||
unregisterGuest: () => Promise.resolve(),
|
||||
openDevTools: () => Promise.resolve(false),
|
||||
setViewportOverride: () => Promise.resolve(false),
|
||||
setAnnotationViewportBridge: () => Promise.resolve(false),
|
||||
onGuestLoadFailed: () => noopUnsubscribe,
|
||||
onCertificateFailureChanged: () => noopUnsubscribe,
|
||||
proceedCertificate: () => Promise.resolve({ ok: false, reason: 'missing' }),
|
||||
onPermissionDenied: () => noopUnsubscribe,
|
||||
onPopup: () => noopUnsubscribe,
|
||||
onDownloadRequested: () => noopUnsubscribe,
|
||||
|
||||
Reference in New Issue
Block a user