fix(browser): keep snapshot refs on server browsers that use an external Chromium (#36276)

Every command re-selected its tab first, and agent-browser drops the last
snapshot's refs on any tab select, so each @ref failed as Unknown ref.
Select the tab only when it is not already active.
This commit is contained in:
Kelvin Amoaba
2026-10-30 07:24:24 +00:00
committed by GitHub
parent f78b5979ca
commit bafbf406c9
2 changed files with 30 additions and 0 deletions
@@ -167,6 +167,32 @@ describe('orcad external-chromium agent-browser environment', () => {
expect(issued).not.toContain('open')
})
it('selects a tab only when it is not already active, keeping the snapshot refs', async () => {
runProcessMock.mockImplementation(() => {
const tabs = [
{ active: true, tabId: 't1', title: 'a', url: 'about:blank' },
{ active: false, tabId: 't2', title: 'b', url: 'about:blank' }
]
return Promise.resolve({
code: 0,
signal: null,
stdout: JSON.stringify({ success: true, data: { tabs } }),
stderr: '',
timedOut: false
})
})
const session = new ExternalChromiumBrowserSession(
'/opt/orca/agent-browser',
{ executablePath: BASE.executablePath, provider: 'chromium' },
'/state'
)
await session.selectPage('t1')
expect(commands()).toEqual([['tab']])
await session.selectPage('t2')
expect(commands()).toEqual([['tab'], ['tab'], ['tab', 't2']])
})
it('reclaims a session that answers nothing, then opens', async () => {
let listed = 0
runProcessMock.mockImplementation((spec: Spec) => {
@@ -138,6 +138,10 @@ export class ExternalChromiumBrowserSession {
}
async selectPage(agentPageId: string): Promise<void> {
// Selecting any tab, even the active one, discards the refs of the last snapshot.
if ((await this.readTabs()).some((tab) => tab.tabId === agentPageId && tab.active)) {
return
}
await this.run(['tab', agentPageId])
}