vscode format dode
This commit is contained in:
parent
1dc3b3db6a
commit
bf647936eb
3 changed files with 13 additions and 13 deletions
|
|
@ -49,7 +49,7 @@ console.debug('userAgent:', await page.evaluate(() => navigator.userAgent));
|
||||||
try {
|
try {
|
||||||
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // 'domcontentloaded' faster than default 'load' https://playwright.dev/docs/api/class-page#page-goto
|
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // 'domcontentloaded' faster than default 'load' https://playwright.dev/docs/api/class-page#page-goto
|
||||||
// Accept cookies to get rid of banner to save space on screen. Will only appear for a fresh context, so we don't await, but let it time out if it does not exist and catch the exception. clickIfExists by checking selector's count > 0 did not work.
|
// Accept cookies to get rid of banner to save space on screen. Will only appear for a fresh context, so we don't await, but let it time out if it does not exist and catch the exception. clickIfExists by checking selector's count > 0 did not work.
|
||||||
page.click('button:has-text("Accept All Cookies")').catch(_ => {}); // _ => console.info('Cookies already accepted')
|
page.click('button:has-text("Accept All Cookies")').catch(_ => { }); // _ => console.info('Cookies already accepted')
|
||||||
while (await page.locator('a[role="button"]:has-text("Sign In")').count() > 0) { // TODO also check alternative for signed-in state
|
while (await page.locator('a[role="button"]:has-text("Sign In")').count() > 0) { // TODO also check alternative for signed-in state
|
||||||
console.error("Not signed in anymore. Please login and then navigate to the 'Free Games' page. If using docker, open http://localhost:6080");
|
console.error("Not signed in anymore. Please login and then navigate to the 'Free Games' page. If using docker, open http://localhost:6080");
|
||||||
context.setDefaultTimeout(0); // give user time to log in without timeout
|
context.setDefaultTimeout(0); // give user time to log in without timeout
|
||||||
|
|
@ -98,7 +98,7 @@ try {
|
||||||
}
|
}
|
||||||
// it then creates an iframe for the rest
|
// it then creates an iframe for the rest
|
||||||
// await page.frame({ url: /.*store\/purchase.*/ }).click('button:has-text("Place Order")'); // not found because it does not wait for iframe
|
// await page.frame({ url: /.*store\/purchase.*/ }).click('button:has-text("Place Order")'); // not found because it does not wait for iframe
|
||||||
const iframe = page.frameLocator('#webPurchaseContainer iframe')
|
const iframe = page.frameLocator('#webPurchaseContainer iframe');
|
||||||
await iframe.locator('button:has-text("Place Order")').click();
|
await iframe.locator('button:has-text("Place Order")').click();
|
||||||
// await page.pause();
|
// await page.pause();
|
||||||
// I Agree button is only shown for EU accounts! https://github.com/vogler/free-games-claimer/pull/7#issuecomment-1038964872
|
// I Agree button is only shown for EU accounts! https://github.com/vogler/free-games-claimer/pull/7#issuecomment-1038964872
|
||||||
|
|
@ -125,12 +125,12 @@ try {
|
||||||
}
|
}
|
||||||
// await page.pause();
|
// await page.pause();
|
||||||
}
|
}
|
||||||
if (i < n-1) { // no need to go back if it's the last game
|
if (i < n - 1) { // no need to go back if it's the last game
|
||||||
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' });
|
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' });
|
||||||
await page.waitForSelector(game_sel);
|
await page.waitForSelector(game_sel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
run.error = error.toString();
|
run.error = error.toString();
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ const clickIfExists = async selector => {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await page.goto(URL_CLAIM, {waitUntil: 'domcontentloaded'}); // default 'load' takes forever
|
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // default 'load' takes forever
|
||||||
// need to wait for some elements to exist before checking if signed in or accepting cookies:
|
// need to wait for some elements to exist before checking if signed in or accepting cookies:
|
||||||
await Promise.any(['button:has-text("Sign in")', '[data-a-target="user-dropdown-first-name-text"]'].map(s => page.waitForSelector(s)));
|
await Promise.any(['button:has-text("Sign in")', '[data-a-target="user-dropdown-first-name-text"]'].map(s => page.waitForSelector(s)));
|
||||||
await clickIfExists('[aria-label="Cookies usage disclaimer banner"] button:has-text("Accept Cookies")'); // to not waste screen space in --debug
|
await clickIfExists('[aria-label="Cookies usage disclaimer banner"] button:has-text("Accept Cookies")'); // to not waste screen space in --debug
|
||||||
|
|
@ -57,7 +57,7 @@ try {
|
||||||
}
|
}
|
||||||
await page.click('button:has-text("Sign in")');
|
await page.click('button:has-text("Sign in")');
|
||||||
if (!debug) context.setDefaultTimeout(0); // give user time to log in without timeout
|
if (!debug) context.setDefaultTimeout(0); // give user time to log in without timeout
|
||||||
await page.waitForNavigation({url: 'https://gaming.amazon.com/home?signedIn=true'});
|
await page.waitForNavigation({ url: 'https://gaming.amazon.com/home?signedIn=true' });
|
||||||
if (!debug) context.setDefaultTimeout(TIMEOUT);
|
if (!debug) context.setDefaultTimeout(TIMEOUT);
|
||||||
}
|
}
|
||||||
console.log('Signed in.');
|
console.log('Signed in.');
|
||||||
|
|
@ -103,7 +103,7 @@ try {
|
||||||
// 3 Full PC Games on Legacy Games
|
// 3 Full PC Games on Legacy Games
|
||||||
const store = store_text.toLowerCase().replace(/.* on /, '');
|
const store = store_text.toLowerCase().replace(/.* on /, '');
|
||||||
console.log('External store:', store);
|
console.log('External store:', store);
|
||||||
if(await page.locator('div:has-text("Link game account")').count()) {
|
if (await page.locator('div:has-text("Link game account")').count()) {
|
||||||
console.error('Account linking is required to claim this offer!');
|
console.error('Account linking is required to claim this offer!');
|
||||||
} else {
|
} else {
|
||||||
// print code if there is one
|
// print code if there is one
|
||||||
|
|
@ -129,13 +129,13 @@ try {
|
||||||
run.c_external++;
|
run.c_external++;
|
||||||
}
|
}
|
||||||
// await page.pause();
|
// await page.pause();
|
||||||
await page.goto(URL_CLAIM, {waitUntil: 'domcontentloaded'});
|
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' });
|
||||||
await page.click('button[data-type="Game"]');
|
await page.click('button[data-type="Game"]');
|
||||||
} while (n);
|
} while (n);
|
||||||
const p = path.resolve(dirs.screenshots, 'prime-gaming', `${filenamify(datetime())}.png`);
|
const p = path.resolve(dirs.screenshots, 'prime-gaming', `${filenamify(datetime())}.png`);
|
||||||
// await page.screenshot({ path: p, fullPage: true });
|
// await page.screenshot({ path: p, fullPage: true });
|
||||||
await page.locator(games_sel).screenshot({ path: p });
|
await page.locator(games_sel).screenshot({ path: p });
|
||||||
} catch(error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
run.error = error.toString();
|
run.error = error.toString();
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
||||||
8
util.js
8
util.js
|
|
@ -17,7 +17,7 @@ export const jsonDb = async file => {
|
||||||
const db = new Low(new JSONFile(dataDir(file)));
|
const db = new Low(new JSONFile(dataDir(file)));
|
||||||
await db.read();
|
await db.read();
|
||||||
return db;
|
return db;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const datetime = (d = new Date()) => d.toISOString().replace('T', ' ').replace('Z', '');
|
export const datetime = (d = new Date()) => d.toISOString().replace('T', ' ').replace('Z', '');
|
||||||
export const filenamify = s => s.replaceAll(':', '.').replace(/[^a-z0-9 _\-.]/gi, '_'); // alternative: https://www.npmjs.com/package/filenamify - On Unix-like systems, / is reserved. On Windows, <>:"/\|?* along with trailing periods are reserved.
|
export const filenamify = s => s.replaceAll(':', '.').replace(/[^a-z0-9 _\-.]/gi, '_'); // alternative: https://www.npmjs.com/package/filenamify - On Unix-like systems, / is reserved. On Windows, <>:"/\|?* along with trailing periods are reserved.
|
||||||
|
|
@ -61,9 +61,9 @@ export const stealth = async (context) => {
|
||||||
const stealth = {
|
const stealth = {
|
||||||
callbacks: [],
|
callbacks: [],
|
||||||
async evaluateOnNewDocument(...args) {
|
async evaluateOnNewDocument(...args) {
|
||||||
this.callbacks.push({ cb: args[0], a: args[1] })
|
this.callbacks.push({ cb: args[0], a: args[1] });
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
for (const e of enabledEvasions) {
|
for (const e of enabledEvasions) {
|
||||||
const evasion = await import(`puppeteer-extra-plugin-stealth/evasions/${e}/index.js`);
|
const evasion = await import(`puppeteer-extra-plugin-stealth/evasions/${e}/index.js`);
|
||||||
evasion.default().onPageCreated(stealth);
|
evasion.default().onPageCreated(stealth);
|
||||||
|
|
@ -71,4 +71,4 @@ export const stealth = async (context) => {
|
||||||
for (let evasion of stealth.callbacks) {
|
for (let evasion of stealth.callbacks) {
|
||||||
await context.addInitScript(evasion.cb, evasion.a);
|
await context.addInitScript(evasion.cb, evasion.a);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue