Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1134,12 +1134,14 @@ export async function search(
const urlBefore = page.url();
const url = buildSearchUrl(query, engine);
await browser.goto(url);
// Some search engines keep long-lived background requests open in CI,
// so treat networkidle as a best-effort signal instead of a hard requirement.
// Use lightweight readiness checks instead of networkidle.
// On Windows CI and some search engines, networkidle can remain pending due to
// long-lived background requests and cause flaky timeouts.
try {
await page.waitForLoadState('networkidle', { timeout: 5000 });
await page.waitForLoadState('domcontentloaded', { timeout: 5000 });
await page.waitForLoadState('load', { timeout: 5000 });
} catch {
// no-op: page is already loaded enough for URL/result assertions
// best-effort only; URL/outcome assertions do not require full idle
}

const durationMs = Date.now() - startTime;
Expand Down
29 changes: 29 additions & 0 deletions tests/actions-search-timeout.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { search } from '../src/actions';

describe('search timeout hardening', () => {
it('returns success when post-goto load-state wait times out', async () => {
const page = {
url: jest
.fn()
.mockReturnValueOnce('https://example.com')
.mockReturnValue('https://duckduckgo.com/?q=sentience+sdk'),
waitForLoadState: jest.fn().mockRejectedValue(new Error('Timeout 30000ms exceeded.')),
};

const browser = {
goto: jest.fn().mockResolvedValue(undefined),
snapshot: jest.fn(),
getPage: jest.fn().mockReturnValue(page),
getContext: jest.fn().mockReturnValue(null),
getApiKey: jest.fn().mockReturnValue(undefined),
getApiUrl: jest.fn().mockReturnValue(undefined),
} as any;

const result = await search(browser, 'sentience sdk', 'duckduckgo');

expect(result.success).toBe(true);
expect(result.outcome).toBe('navigated');
expect(browser.goto).toHaveBeenCalledWith('https://duckduckgo.com/?q=sentience+sdk');
expect(page.waitForLoadState).toHaveBeenCalled();
});
});
Loading