diff --git a/README.md b/README.md index 7f61ba5..cb3aa01 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Setup: `npm install && npx playwright install` (downloads {chromium, firefox, we 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. -If something goes wrong, try `npm start -- --debug` to investigate. +If something goes wrong, use `PWDEBUG=1 npm start` to [inspect](https://playwright.dev/docs/inspector). ## log diff --git a/main.stealth.js b/main.stealth.js index 6144f77..2d503e4 100644 --- a/main.stealth.js +++ b/main.stealth.js @@ -5,8 +5,7 @@ if (!existsSync('auth.json')) { process.exit(1); } -const args = process.argv.slice(2); -const debug = args.includes('--debug'); +const debug = process.env.PWDEBUG == '1'; // runs headful and opens https://playwright.dev/docs/inspector const { chromium } = require('playwright'); // stealth plugin needs no outdated playwright-extra @@ -52,15 +51,14 @@ const newStealthContext = async (browser, contextOptions = {}) => { // could change to .mjs to get top-level-await, but would then also need to change require to import and dynamic import for stealth below would just add more async/await (async () => { const browser = await chromium.launch({ - channel: 'chrome', - headless: !debug, + channel: 'chrome', // https://playwright.dev/docs/browsers#google-chrome--microsoft-edge }); /** @type {import('playwright').BrowserContext} */ const context = await newStealthContext(browser, { storageState: 'auth.json', viewport: { width: 1280, height: 1280 }, }); - context.setDefaultTimeout(10000); + if (!debug) context.setDefaultTimeout(10000); const page = await context.newPage(); await page.goto('https://www.epicgames.com/store/en-US/free-games'); await page.click('button:has-text("Accept All Cookies")'); // to not waste screen space in --debug