Skip to content

Commit 9fb6baa

Browse files
authored
fix: wait for login form to render before auto-fill (#201)
The Bloomreach login page is an Angular SPA that takes several seconds to render after DOM content loads. The auto-fill was running immediately after navigation with only 500ms per selector, causing it to silently fail every time. Changes: - Use waitUntil: 'networkidle' instead of 'domcontentloaded' for login page navigation - Add explicit waitForSelector for email input (10s timeout) before attempting auto-fill - Increase default selector candidate timeout from 500ms to 3s to accommodate SPA rendering
1 parent 608860c commit 9fb6baa

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

packages/core/src/__tests__/bloomreachAuth.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ describe('BloomreachAuthService', () => {
211211
expect.any(Function),
212212
);
213213
expect(mockPage.goto).toHaveBeenCalledWith('https://eu.login.bloomreach.com/login', {
214-
waitUntil: 'domcontentloaded',
214+
waitUntil: 'networkidle',
215215
timeout: 30_000,
216216
});
217217
expect(saveSession).toHaveBeenCalledWith(

packages/core/src/auth/loginSelectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface AutoFillConfig {
2121
password?: string;
2222
}
2323

24-
const DEFAULT_CANDIDATE_TIMEOUT_MS = 500;
24+
const DEFAULT_CANDIDATE_TIMEOUT_MS = 3_000;
2525

2626
/** Get multi-strategy selectors for the Bloomreach login page. */
2727
export function getLoginSelectors(): LoginPageSelectors {

packages/core/src/bloomreachAuth.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,18 @@ export class BloomreachAuthService {
144144
async (context: BrowserContext) => {
145145
const page: Page = context.pages()[0] ?? (await context.newPage());
146146

147-
await page.goto(loginUrl, { waitUntil: 'domcontentloaded', timeout: 30_000 });
147+
await page.goto(loginUrl, { waitUntil: 'networkidle', timeout: 30_000 });
148148

149149
const autoFill = options?.autoFill ?? true;
150150
if (autoFill) {
151151
const autoFillConfig = resolveAutoFillConfig();
152152
if (autoFillConfig.email || autoFillConfig.password) {
153+
// Wait for the login form to render (Angular SPA needs time after navigation)
154+
try {
155+
await page.waitForSelector('input[name="username"], input[type="email"]', { timeout: 10_000 });
156+
} catch {
157+
// Form may not appear (already authenticated, different page layout) — continue
158+
}
153159
await tryAutoFill(page, autoFillConfig);
154160
}
155161
}

0 commit comments

Comments
 (0)