Verbessere Login-Handling: Füge Unterstützung für das automatische Hinzufügen des Intent-Feldes im Login-Formular hinzu und verbessere die Cookie-Verwaltung bei der Anmeldung.
This commit is contained in:
@@ -108,16 +108,42 @@ async function loginWithBrowser(email, password) {
|
|||||||
await page.waitForTimeout(2_500)
|
await page.waitForTimeout(2_500)
|
||||||
}
|
}
|
||||||
|
|
||||||
const submit = page.locator('button[type="submit"][name="intent"][value="login"], button[type="submit"], input[type="submit"]').first()
|
await page.evaluate(() => {
|
||||||
|
const form = document.querySelector('form[action*="/login"]')
|
||||||
|
if (!form) return
|
||||||
|
let intent = form.querySelector('input[name="intent"]')
|
||||||
|
if (!intent) {
|
||||||
|
intent = document.createElement('input')
|
||||||
|
intent.setAttribute('type', 'hidden')
|
||||||
|
intent.setAttribute('name', 'intent')
|
||||||
|
form.appendChild(intent)
|
||||||
|
}
|
||||||
|
intent.setAttribute('value', 'login')
|
||||||
|
})
|
||||||
|
const submit = page.locator('button[type="submit"][name="intent"][value="login"]').first()
|
||||||
|
const genericSubmit = page.locator('button[type="submit"], input[type="submit"]').first()
|
||||||
if (await submit.count()) await submit.click({ noWaitAfter: true })
|
if (await submit.count()) await submit.click({ noWaitAfter: true })
|
||||||
|
else if (await genericSubmit.count()) await genericSubmit.click({ noWaitAfter: true })
|
||||||
else await page.locator('form').evaluate(form => form.requestSubmit())
|
else await page.locator('form').evaluate(form => form.requestSubmit())
|
||||||
let cookie = null
|
let cookie = null
|
||||||
|
let cookieNames = []
|
||||||
|
let loginPageText = ''
|
||||||
for (let attempt = 0; attempt < 40; attempt += 1) {
|
for (let attempt = 0; attempt < 40; attempt += 1) {
|
||||||
cookie = (await page.context().cookies(BASE_URL)).find(item => /^sb-\d+-auth-token$/.test(item.name))
|
const cookies = await page.context().cookies()
|
||||||
|
cookieNames = cookies.map(item => item.name)
|
||||||
|
cookie = cookies.find(item => item.name === 'sb-10-auth-token' || /^sb-\d+-auth-token$/.test(item.name) || item.name.includes('auth-token'))
|
||||||
if (cookie) break
|
if (cookie) break
|
||||||
|
if (attempt % 4 === 0) {
|
||||||
|
loginPageText = await page.locator('body').innerText().catch(() => '')
|
||||||
|
}
|
||||||
await page.waitForTimeout(500)
|
await page.waitForTimeout(500)
|
||||||
}
|
}
|
||||||
if (!cookie) throw new Error('CAPTCHA konnte nicht automatisch gelöst werden.')
|
if (!cookie) {
|
||||||
|
console.warn('[mytischtennis] Login after solved CAPTCHA did not create a session', {
|
||||||
|
url: page.url(), cookieNames, pageText: loginPageText.slice(0, 1_000)
|
||||||
|
})
|
||||||
|
throw new Error('myTischtennis-Login nach gelöstem CAPTCHA fehlgeschlagen.')
|
||||||
|
}
|
||||||
return `${cookie.name}=${cookie.value}`
|
return `${cookie.name}=${cookie.value}`
|
||||||
} finally { await browser.close() }
|
} finally { await browser.close() }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user