fix(browser): silence popup notices for links opened in Orca tabs

Links that open in new Orca tabs are immediately visible to the user and
don't warrant a toast notification. Only external popup opens now show
notifications, reducing unnecessary clutter while still alerting the user
to unexpected external window opens.
This commit is contained in:
Jinjing
2026-09-05 21:18:53 -07:00
parent f888071352
commit fe81ca49db
5 changed files with 16 additions and 21 deletions
@@ -99,21 +99,13 @@ describe('ClientHostedBrowserPagePane popup notices', () => {
expect(new Set(ids).size).toBe(1)
})
// Why: the local pane reports all three outcomes; only "blocked" reaching this pane left a page
// that silently opened somewhere else looking like it did nothing.
it('reports where a popup Orca did open actually went', () => {
it('silences in-Orca opens but reports external opens', () => {
renderPane()
emitPopup({ action: 'opened-in-orca' })
expect(toastMocks.message).not.toHaveBeenCalled()
emitPopup({ action: 'opened-external' })
expect(toastMocks.message).toHaveBeenNthCalledWith(
1,
'https://accounts.example.com opened a new page in Orca.',
{ id: 'browser-popup:page-a:opened-in-orca:https://accounts.example.com' }
)
expect(toastMocks.message).toHaveBeenNthCalledWith(
2,
expect(toastMocks.message).toHaveBeenCalledExactlyOnceWith(
'https://accounts.example.com opened a new window in your default browser.',
{ id: 'browser-popup:page-a:opened-external:https://accounts.example.com' }
)
@@ -2,18 +2,18 @@ import { useEffect } from 'react'
import { toast } from 'sonner'
import { formatPopupNotice } from './navigate/browser-notices'
/**
* A client-hosted page's popups are gesture-gated and capped, and every outcome — blocked, opened
* in an Orca tab, or handed to the default browser — leaves no other trace on this pane. One quiet
* toast per page and origin says what happened, without spamming a site that retries.
*/
// Deduplicate blocked and external-popup notices per page and origin.
export function useBrowserClientHostedPopupNotices(browserPageId: string): void {
useEffect(() => {
return window.api.browser.onPopup((event) => {
if (event.browserPageId !== browserPageId) {
return
}
toast.message(formatPopupNotice(event), {
const notice = formatPopupNotice(event)
if (!notice) {
return
}
toast.message(notice, {
id: `browser-popup:${browserPageId}:${event.action}:${event.origin}`
})
})
@@ -83,7 +83,7 @@ describe('browser notice formatting', () => {
origin: 'https://example.com',
action: 'opened-in-orca'
})
).toBe('https://example.com opened a new page in Orca.')
).toBeNull()
expect(
formatPopupNotice({
@@ -64,10 +64,10 @@ export function formatPermissionNotice(event: BrowserPermissionDeniedEvent): str
return `${target} asked for ${humanizePermission(event.permission)}, and Orca denied it.`
}
export function formatPopupNotice(event: BrowserPopupEvent): string {
export function formatPopupNotice(event: BrowserPopupEvent): string | null {
const target = event.origin === 'unknown' ? 'A site' : event.origin
if (event.action === 'opened-in-orca') {
return `${target} opened a new page in Orca.`
return null
}
if (event.action === 'opened-external') {
return `${target} opened a new window in your default browser.`
@@ -50,7 +50,10 @@ export function useBrowserPageResourceNotices(browserTabId: string): {
if (event.browserPageId !== browserTabId) {
return
}
setResourceNotice(formatPopupNotice(event))
const notice = formatPopupNotice(event)
if (notice) {
setResourceNotice(notice)
}
})
}, [browserTabId])