update sync
This commit is contained in:
@@ -67,26 +67,41 @@ export async function scrapeAll(username: string, password: string): Promise<{
|
||||
|
||||
async function login(page: Page, username: string, password: string): Promise<void> {
|
||||
log(`Navigating to ${LOGIN_URL}`);
|
||||
await page.goto(LOGIN_URL, { waitUntil: 'networkidle' });
|
||||
await page.goto(LOGIN_URL, { waitUntil: 'domcontentloaded' });
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Check if already logged in
|
||||
const currentUrlBefore = page.url();
|
||||
if (!currentUrlBefore.toLowerCase().includes('login')) {
|
||||
log(`Already logged in, on: ${currentUrlBefore}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// ASP.NET WebForms login — try common selector patterns
|
||||
// Adjust these selectors if login fails
|
||||
const usernameField = page.locator('input[type="text"], input[name*="user"], input[name*="User"], input[id*="user"], input[id*="User"]').first();
|
||||
const passwordField = page.locator('input[type="password"]').first();
|
||||
|
||||
await usernameField.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await usernameField.fill(username);
|
||||
await passwordField.fill(password);
|
||||
|
||||
// Submit — look for a login/submit button
|
||||
// Submit — ASP.NET WebForms may use __doPostBack; click submit and wait for URL change
|
||||
const submitButton = page.locator('input[type="submit"], button[type="submit"]').first();
|
||||
await Promise.all([
|
||||
page.waitForNavigation({ waitUntil: 'networkidle' }),
|
||||
submitButton.click(),
|
||||
]);
|
||||
await submitButton.click();
|
||||
|
||||
// Verify we're logged in by checking we're not still on the login page
|
||||
// Wait for navigation away from the login page (up to 15s)
|
||||
try {
|
||||
await page.waitForURL(
|
||||
(url) => !url.toString().toLowerCase().includes('login'),
|
||||
{ waitUntil: 'networkidle', timeout: 15000 },
|
||||
);
|
||||
} catch {
|
||||
// waitForURL timed out — fall through to the URL check below
|
||||
}
|
||||
|
||||
// Verify we're logged in
|
||||
const currentUrl = page.url();
|
||||
if (currentUrl.includes('login') || currentUrl.includes('Login') || currentUrl === LOGIN_URL) {
|
||||
if (currentUrl.toLowerCase().includes('login')) {
|
||||
throw new Error(`Login failed — still on login page: ${currentUrl}`);
|
||||
}
|
||||
log(`Logged in successfully, redirected to: ${currentUrl}`);
|
||||
|
||||
Reference in New Issue
Block a user