mirror of
https://github.com/stablyai/orca.git
synced 2026-10-19 08:03:13 +00:00
fix: preserve screenshot fallback encoding errors
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -190,6 +190,28 @@ describe('captureScreenshot', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('reports the original timeout when fallback encoding fails', async () => {
|
||||
vi.useFakeTimers()
|
||||
|
||||
const webContents = createMockWebContents()
|
||||
webContents.debugger.sendCommand.mockImplementation(() => new Promise(() => {}))
|
||||
webContents.capturePage.mockResolvedValueOnce({
|
||||
isEmpty: () => {
|
||||
throw new Error('native image unavailable')
|
||||
}
|
||||
})
|
||||
const onResult = vi.fn()
|
||||
const onError = vi.fn()
|
||||
|
||||
captureScreenshot(webContents as never, { format: 'png' }, onResult, onError)
|
||||
await vi.advanceTimersByTimeAsync(8000)
|
||||
|
||||
expect(onResult).not.toHaveBeenCalled()
|
||||
expect(onError).toHaveBeenCalledWith(
|
||||
'Screenshot timed out — the browser tab may not be visible or the window may not have focus.'
|
||||
)
|
||||
})
|
||||
|
||||
it('reports the timeout when both CDP and fallback capture stall', async () => {
|
||||
vi.useFakeTimers()
|
||||
|
||||
|
||||
@@ -268,7 +268,13 @@ export function captureScreenshot(
|
||||
clearTimeout(fallbackTimer)
|
||||
fallbackTimer = null
|
||||
}
|
||||
const fallback = encodeNativeImageScreenshot(image, params)
|
||||
let fallback: { data: string } | null = null
|
||||
try {
|
||||
fallback = encodeNativeImageScreenshot(image, params)
|
||||
} catch {
|
||||
settleError(SCREENSHOT_TIMEOUT_MESSAGE)
|
||||
return
|
||||
}
|
||||
if (fallback) {
|
||||
settleResult(fallback)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user