aliexpress: fix login

This commit is contained in:
Ralf Vogler 2025-07-23 01:42:16 +02:00
parent 9ad61a18f2
commit 37a0635cb8

View file

@ -44,12 +44,16 @@ const page = context.pages().length ? context.pages()[0] : await context.newPage
const auth = async url => { const auth = async url => {
console.log('auth', url); console.log('auth', url);
await page.goto(url, { waitUntil: 'domcontentloaded' }); await page.goto(url, { waitUntil: 'domcontentloaded' });
// redirects to https://login.aliexpress.com/?return_url=https%3A%2F%2Fwww.aliexpress.com%2Fp%2Fcoin-pc-index%2Findex.html // no longer redirects if not authed, but replaces content -> click button "Log in" which then redirects
await Promise.any([page.waitForURL(/.*login\.aliexpress.com.*/).then(async () => { const loginBtn = page.locator('button:has-text("Log in")');
// manual login const loggedIn = page.locator('h3:text-is("day streak")');
await Promise.race([loginBtn.waitFor().then(async () => {
// offer manual login
console.error('Not logged in! Will wait for 120s for you to login in the browser or terminal...'); console.error('Not logged in! Will wait for 120s for you to login in the browser or terminal...');
context.setDefaultTimeout(120 * 1000); context.setDefaultTimeout(120 * 1000);
// or try automated // and try automated
await loginBtn.click();
page.getByRole('button', { name: 'Accept cookies' }).click().then(_ => console.log('Accepted cookies')).catch(_ => { });
page.locator('span:has-text("Switch account")').click().catch(_ => {}); // sometimes no longer logged in, but previous user/email is pre-selected -> in this case we want to go back to the classic login page.locator('span:has-text("Switch account")').click().catch(_ => {}); // sometimes no longer logged in, but previous user/email is pre-selected -> in this case we want to go back to the classic login
const login = page.locator('#root'); // not universal: .content, .nfm-login const login = page.locator('#root'); // not universal: .content, .nfm-login
const email = cfg.ae_email || await prompt({ message: 'Enter email' }); const email = cfg.ae_email || await prompt({ message: 'Enter email' });
@ -61,21 +65,19 @@ const auth = async url => {
const password = email && (cfg.ae_password || await prompt({ type: 'password', message: 'Enter password' })); const password = email && (cfg.ae_password || await prompt({ type: 'password', message: 'Enter password' }));
await login.locator('input[label="Password"]').fill(password); await login.locator('input[label="Password"]').fill(password);
await login.locator('button:has-text("Sign in")').click(); await login.locator('button:has-text("Sign in")').click();
// TODO handle failed login
const error = login.locator('.nfm-login-input-error-text'); const error = login.locator('.nfm-login-input-error-text');
error.waitFor().then(async _ => console.error('Login error (please restart):', await error.innerText())).catch(_ => console.log('No login error.')); error.waitFor().then(async _ => console.error('Login error (please restart):', await error.innerText())).catch(_ => console.log('No login error.'));
await page.waitForURL(u => u.toString().startsWith(url)); // e.g. https://m.aliexpress.com/p/coin-index/index.html?_immersiveMode=true&from=pc302 await page.waitForURL(u => u.toString().startsWith('https://www.aliexpress.com/'));
// TODO the following won't be executed anymore due to the navigation - patchright issue?
context.setDefaultTimeout(cfg.debug ? 0 : cfg.timeout); context.setDefaultTimeout(cfg.debug ? 0 : cfg.timeout);
console.log('Logged in!'); // this should still be printed, but isn't... console.log('Logged in!'); // this should still be printed, but isn't...
// await page.addLocatorHandler(page.getByRole('button', { name: 'Accept cookies' }), btn => btn.click()); }), loggedIn.waitFor()]); // some alternative element which is only there once logged in
// page.getByRole('button', { name: 'Accept cookies' }).click().then(_ => console.log('Accepted cookies')).catch(_ => { });
}), page.locator('.app-game').waitFor()]);
}; };
// copied URLs from AliExpress app on tablet which has menu for the used webview // copied URLs from AliExpress app on tablet which has menu for the used webview
const urls = { const urls = {
// only work with mobile view: // only work with mobile view:
coins: 'https://www.aliexpress.com/p/coin-pc-index/index.html', coins: 'https://m.aliexpress.com/p/coin-index/index.html',
grow: 'https://m.aliexpress.com/p/ae_fruit/index.html', // firefox: stuck at 60% loading, chrome: loads, but canvas grow: 'https://m.aliexpress.com/p/ae_fruit/index.html', // firefox: stuck at 60% loading, chrome: loads, but canvas
gogo: 'https://m.aliexpress.com/p/gogo-match-cc/index.html', // closes firefox?! gogo: 'https://m.aliexpress.com/p/gogo-match-cc/index.html', // closes firefox?!
// only show notification to install the app // only show notification to install the app