add --debug flag

This commit is contained in:
Ralf Vogler 2021-12-28 18:59:43 +01:00
parent a8e8354bf7
commit 6de35e00ef
2 changed files with 11 additions and 3 deletions

View file

@ -3,9 +3,10 @@
Setup: `npm install && npx playwright install` (downloads {chromium, firefox, webkit} (742 MB) to cache in home ([doc](https://playwright.dev/docs/browsers#managing-browser-binaries))). Setup: `npm install && npx playwright install` (downloads {chromium, firefox, webkit} (742 MB) to cache in home ([doc](https://playwright.dev/docs/browsers#managing-browser-binaries))).
Run `npm login` which opens a browser where you can login. When closing the browser, it writes a file `auth.json` containing cookies that should keep you logged in for some time. Run `npm login` which opens a browser where you can login. When closing the browser, it writes a file `auth.json` containing cookies that should keep you logged in for some time (`expires` in a month?).
Then use `npm start` to run Chrome in headless mode to claim the current free game. Then use `npm start` to run Chrome in headless mode to claim the current free game.
If something goes wrong, try `npm start -- --debug` to investigate.
## log ## log
@ -22,3 +23,7 @@ Also, solving via [2captcha](https://2captcha.com?from=13225256) is a paid servi
Added [main.stealth.js](https://github.com/vogler/epicgames-claimer/commit/64d0ba8ce71baec3947d1b64acd567befcb39340#diff-f70d3bd29df4a343f11062a97063953173491ce30fe34f69a0fc52517adbf342) which uses the stealth plugin without `playwright-extra` wrapper but up-to-date `playwright` (from [comment](https://github.com/berstend/puppeteer-extra/issues/454#issuecomment-917437212)). Added [main.stealth.js](https://github.com/vogler/epicgames-claimer/commit/64d0ba8ce71baec3947d1b64acd567befcb39340#diff-f70d3bd29df4a343f11062a97063953173491ce30fe34f69a0fc52517adbf342) which uses the stealth plugin without `playwright-extra` wrapper but up-to-date `playwright` (from [comment](https://github.com/berstend/puppeteer-extra/issues/454#issuecomment-917437212)).
The listed evasions are enough to not show an hcaptcha. Script claimed game successfully in headful mode. The listed evasions are enough to not show an hcaptcha. Script claimed game successfully in headful mode.
Removed `main.captcha.js`.
Using Playwright Test (`main.spec.ts`) instead of Library (`main.stealth.js`) has the advantage of free CLI like `--debug` and `--timeout`.
TODO: check if stealth plugin can be setup with `contextOptions` ([doc](https://playwright.dev/docs/test-configuration#more-browser-and-context-options)).

View file

@ -5,12 +5,15 @@ if (!existsSync('auth.json')) {
process.exit(1); process.exit(1);
} }
const args = process.argv.slice(2);
const debug = args.includes('--debug');
const { chromium } = require('playwright'); // stealth plugin needs no outdated playwright-extra const { chromium } = require('playwright'); // stealth plugin needs no outdated playwright-extra
// stealth with playwright: https://github.com/berstend/puppeteer-extra/issues/454#issuecomment-917437212 // stealth with playwright: https://github.com/berstend/puppeteer-extra/issues/454#issuecomment-917437212
const newStealthContext = async (browser, contextOptions = {}) => { const newStealthContext = async (browser, contextOptions = {}) => {
const originalUserAgent = await (await (await browser.newContext()).newPage()).evaluate(() => navigator.userAgent); const originalUserAgent = await (await (await browser.newContext()).newPage()).evaluate(() => navigator.userAgent);
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 if (debug) 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({
...contextOptions, ...contextOptions,
userAgent: originalUserAgent.replace("Headless", ""), // HeadlessChrome -> Chrome userAgent: originalUserAgent.replace("Headless", ""), // HeadlessChrome -> Chrome
@ -50,7 +53,7 @@ const newStealthContext = async (browser, contextOptions = {}) => {
(async () => { (async () => {
const browser = await chromium.launch({ const browser = await chromium.launch({
channel: 'chrome', channel: 'chrome',
headless: false, headless: !debug,
}); });
/** @type {import('playwright').BrowserContext} */ /** @type {import('playwright').BrowserContext} */
const context = await newStealthContext(browser, { const context = await newStealthContext(browser, {