👷 ci(build): add SonarQube scan to build workflow
- introduce SonarQube scanning step for code quality analysis - update workflow dependencies and execution order 🐛 fix(auth): improve error handling and code formatting - remove unused imports and fix code indentation - enhance error handling with improved catch blocks 💄 style(general): standardize code formatting and style consistency - update various files to ensure consistent code style - adjust indentation and whitespace for readability
This commit is contained in:
parent
0e5303da62
commit
d40a577f47
7 changed files with 95 additions and 62 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra
|
||||
import { datetime, filenamify, prompt, handleSIGINT, stealth } from './src/util.js';
|
||||
import { datetime, filenamify, prompt, handleSIGINT } from './src/util.js';
|
||||
import { cfg } from './src/config.js';
|
||||
|
||||
// using https://github.com/apify/fingerprint-suite worked, but has no launchPersistentContext...
|
||||
|
|
@ -8,8 +8,8 @@ import { FingerprintInjector } from 'fingerprint-injector';
|
|||
import { FingerprintGenerator } from 'fingerprint-generator';
|
||||
|
||||
const { fingerprint, headers } = new FingerprintGenerator().getFingerprint({
|
||||
devices: ["mobile"],
|
||||
operatingSystems: ["android"],
|
||||
devices: ['mobile'],
|
||||
operatingSystems: ['android'],
|
||||
});
|
||||
|
||||
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
|
||||
|
|
@ -21,11 +21,11 @@ const context = await firefox.launchPersistentContext(cfg.dir.browser, {
|
|||
handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved
|
||||
userAgent: fingerprint.navigator.userAgent,
|
||||
viewport: {
|
||||
width: fingerprint.screen.width,
|
||||
height: fingerprint.screen.height,
|
||||
width: fingerprint.screen.width,
|
||||
height: fingerprint.screen.height,
|
||||
},
|
||||
extraHTTPHeaders: {
|
||||
'accept-language': headers['accept-language'],
|
||||
'accept-language': headers['accept-language'],
|
||||
},
|
||||
});
|
||||
handleSIGINT(context);
|
||||
|
|
@ -36,7 +36,7 @@ context.setDefaultTimeout(cfg.debug ? 0 : cfg.timeout);
|
|||
|
||||
const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist
|
||||
|
||||
const auth = async (url) => {
|
||||
const auth = async url => {
|
||||
console.log('auth', url);
|
||||
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
|
||||
|
|
@ -45,7 +45,7 @@ const auth = async (url) => {
|
|||
console.error('Not logged in! Will wait for 120s for you to login...');
|
||||
// await page.waitForTimeout(120*1000);
|
||||
// or try automated
|
||||
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('.login-container');
|
||||
const email = cfg.ae_email || await prompt({ message: 'Enter email' });
|
||||
const emailInput = login.locator('input[label="Email or phone number"]');
|
||||
|
|
@ -58,11 +58,11 @@ const auth = async (url) => {
|
|||
await login.locator('input[label="Password"]').fill(password);
|
||||
await login.locator('button:has-text("Sign in")').click();
|
||||
const error = login.locator('.error-text');
|
||||
error.waitFor().then(async _ => console.error('Login error:', await error.innerText()));
|
||||
error.waitFor().then(async () => console.error('Login error:', await error.innerText()));
|
||||
await page.waitForURL(url);
|
||||
// await page.addLocatorHandler(page.getByRole('button', { name: 'Accept cookies' }), btn => btn.click());
|
||||
page.getByRole('button', { name: 'Accept cookies' }).click().then(_ => console.log('Accepted cookies')).catch(_ => { });
|
||||
}), page.locator('#nav-user-account').waitFor()]).catch(_ => {});
|
||||
page.getByRole('button', { name: 'Accept cookies' }).click().then(() => console.log('Accepted cookies')).catch(() => { });
|
||||
}), page.locator('#nav-user-account').waitFor()]).catch(() => {});
|
||||
|
||||
// await page.locator('#nav-user-account').hover();
|
||||
// console.log('Logged in as:', await page.locator('.welcome-name').innerText());
|
||||
|
|
@ -80,6 +80,7 @@ const urls = {
|
|||
merge: 'https://m.aliexpress.com/p/merge-market/index.html',
|
||||
};
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
const coins = async () => {
|
||||
// await auth(urls.coins);
|
||||
await Promise.any([page.locator('.checkin-button').click(), page.locator('.addcoin').waitFor()]);
|
||||
|
|
@ -103,6 +104,7 @@ const euro = async () => {
|
|||
const merge = async () => {
|
||||
await page.pause();
|
||||
};
|
||||
/* eslint-enable no-unused-vars */
|
||||
|
||||
try {
|
||||
// await coins();
|
||||
|
|
@ -112,7 +114,11 @@ try {
|
|||
// gogo,
|
||||
// euro,
|
||||
merge,
|
||||
].reduce((a, f) => a.then(async _ => { await auth(urls[f.name]); await f(); console.log() }), Promise.resolve());
|
||||
].reduce((a, f) => a.then(async () => {
|
||||
await auth(urls[f.name]);
|
||||
await f();
|
||||
console.log();
|
||||
}), Promise.resolve());
|
||||
|
||||
// await page.pause();
|
||||
} catch (error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue