MCPcopy
hub / github.com/vogler/free-games-claimer / auth

Function auth

aliexpress.js:39–69  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

37const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist
38
39const auth = async (url) => {
40 console.log('auth', url);
41 await page.goto(url, { waitUntil: 'domcontentloaded' });
42 // redirects to https://login.aliexpress.com/?return_url=https%3A%2F%2Fwww.aliexpress.com%2Fp%2Fcoin-pc-index%2Findex.html
43 await Promise.any([page.waitForURL(/.*login.aliexpress.com.*/).then(async () => {
44 // manual login
45 console.error('Not logged in! Will wait for 120s for you to login...');
46 // await page.waitForTimeout(120*1000);
47 // or try automated
48 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
49 const login = page.locator('.login-container');
50 const email = cfg.ae_email || await prompt({ message: 'Enter email' });
51 const emailInput = login.locator('input[label="Email or phone number"]');
52 await emailInput.fill(email);
53 await emailInput.blur(); // otherwise Continue button stays disabled
54 const continueButton = login.locator('button:has-text("Continue")');
55 await continueButton.click({ force: true }); // normal click waits for button to no longer be covered by their suggestion menu, so we have to force click somewhere for the menu to close and then click
56 await continueButton.click();
57 const password = email && (cfg.ae_password || await prompt({ type: 'password', message: 'Enter password' }));
58 await login.locator('input[label="Password"]').fill(password);
59 await login.locator('button:has-text("Sign in")').click();
60 const error = login.locator('.error-text');
61 error.waitFor().then(async _ => console.error('Login error:', await error.innerText()));
62 await page.waitForURL(url);
63 // await page.addLocatorHandler(page.getByRole('button', { name: 'Accept cookies' }), btn => btn.click());
64 page.getByRole('button', { name: 'Accept cookies' }).click().then(_ => console.log('Accepted cookies')).catch(_ => { });
65 }), page.locator('#nav-user-account').waitFor()]).catch(_ => {});
66
67 // await page.locator('#nav-user-account').hover();
68 // console.log('Logged in as:', await page.locator('.welcome-name').innerText());
69};
70
71// copied URLs from AliExpress app on tablet which has menu for the used webview
72const urls = {

Callers 1

aliexpress.jsFile · 0.85

Calls 1

promptFunction · 0.90

Tested by

no test coverage detected