check if game already claimed
This commit is contained in:
parent
64d0ba8ce7
commit
b7b93f4c46
1 changed files with 29 additions and 20 deletions
|
|
@ -3,20 +3,20 @@ if (!existsSync('auth.json')) {
|
||||||
console.error('Missing auth.json! Run `npm login` to login and create this file by closing the opened browser.');
|
console.error('Missing auth.json! Run `npm login` to login and create this file by closing the opened browser.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { chromium } = require('playwright');
|
const { chromium } = require('playwright'); // stealth plugin needs no outdated playwright-extra
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await chromium.launch({
|
const browser = await chromium.launch({
|
||||||
channel: 'chrome',
|
channel: 'chrome',
|
||||||
headless: false,
|
headless: true,
|
||||||
});
|
});
|
||||||
// https://github.com/berstend/puppeteer-extra/issues/454#issuecomment-917437212
|
// stealth with playwright: https://github.com/berstend/puppeteer-extra/issues/454#issuecomment-917437212
|
||||||
const originalUserAgent = await (await (await browser.newContext()).newPage()).evaluate(() => { return navigator.userAgent });
|
const originalUserAgent = await (await (await browser.newContext()).newPage()).evaluate(() => navigator.userAgent);
|
||||||
console.log(originalUserAgent);
|
console.log('userAgent:', originalUserAgent); // Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/96.0.4664.110 Safari/537.36
|
||||||
const context = await browser.newContext({
|
const context = await browser.newContext({
|
||||||
storageState: 'auth.json',
|
storageState: 'auth.json',
|
||||||
viewport: { width: 1280, height: 1280 },
|
viewport: { width: 1280, height: 1280 },
|
||||||
userAgent: originalUserAgent.replace("Headless", ""),
|
userAgent: originalUserAgent.replace("Headless", ""), // HeadlessChrome -> Chrome
|
||||||
});
|
});
|
||||||
const enabledEvasions = [
|
const enabledEvasions = [
|
||||||
'chrome.app',
|
'chrome.app',
|
||||||
|
|
@ -51,8 +51,14 @@ const { chromium } = require('playwright');
|
||||||
await page.goto('https://www.epicgames.com/store/en-US/free-games');
|
await page.goto('https://www.epicgames.com/store/en-US/free-games');
|
||||||
// await expect(page.locator('a[role="button"]:has-text("Sign In")')).toHaveCount(0);
|
// await expect(page.locator('a[role="button"]:has-text("Sign In")')).toHaveCount(0);
|
||||||
await page.click('button:has-text("Accept All Cookies")'); // to not waste screen space in --debug
|
await page.click('button:has-text("Accept All Cookies")'); // to not waste screen space in --debug
|
||||||
|
// click on banner to go to current free game. TODO what if there are multiple games?
|
||||||
await page.click('[data-testid="offer-card-image-landscape"]');
|
await page.click('[data-testid="offer-card-image-landscape"]');
|
||||||
// TODO check if already claimed
|
const game = await page.locator('h1 div').first().innerText();
|
||||||
|
console.log('Current free game:', game);
|
||||||
|
const btnText = await page.locator('[data-testid="purchase-cta-button"]').innerText();
|
||||||
|
if (btnText.toLowerCase() == 'in library') {
|
||||||
|
console.log('Already in library! Nothing to claim.');
|
||||||
|
} else {
|
||||||
await page.click('[data-testid="purchase-cta-button"]');
|
await page.click('[data-testid="purchase-cta-button"]');
|
||||||
await page.click('button:has-text("Continue")');
|
await page.click('button:has-text("Continue")');
|
||||||
// it then creates an iframe for the rest
|
// it then creates an iframe for the rest
|
||||||
|
|
@ -60,7 +66,10 @@ const { chromium } = require('playwright');
|
||||||
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 iframe.locator('button:has-text("I Agree")').click();
|
await iframe.locator('button:has-text("I Agree")').click();
|
||||||
|
console.log(await page.locator('[data-testid="purchase-cta-button"]').innerText());
|
||||||
await page.pause();
|
await page.pause();
|
||||||
|
// await context.waitForEvent("close");
|
||||||
|
}
|
||||||
await context.close();
|
await context.close();
|
||||||
await browser.close();
|
await browser.close();
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue