use PWDEBUG=1 to debug instead which also opens Playwright Inspector

This commit is contained in:
Ralf Vogler 2021-12-28 19:07:56 +01:00
parent 6de35e00ef
commit 1fc4ee761d
2 changed files with 4 additions and 6 deletions

View file

@ -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?). 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. If something goes wrong, use `PWDEBUG=1 npm start` to [inspect](https://playwright.dev/docs/inspector).
## log ## log

View file

@ -5,8 +5,7 @@ if (!existsSync('auth.json')) {
process.exit(1); process.exit(1);
} }
const args = process.argv.slice(2); const debug = process.env.PWDEBUG == '1'; // runs headful and opens https://playwright.dev/docs/inspector
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
@ -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 // 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 () => { (async () => {
const browser = await chromium.launch({ const browser = await chromium.launch({
channel: 'chrome', channel: 'chrome', // https://playwright.dev/docs/browsers#google-chrome--microsoft-edge
headless: !debug,
}); });
/** @type {import('playwright').BrowserContext} */ /** @type {import('playwright').BrowserContext} */
const context = await newStealthContext(browser, { const context = await newStealthContext(browser, {
storageState: 'auth.json', storageState: 'auth.json',
viewport: { width: 1280, height: 1280 }, viewport: { width: 1280, height: 1280 },
}); });
context.setDefaultTimeout(10000); if (!debug) context.setDefaultTimeout(10000);
const page = await context.newPage(); const page = await context.newPage();
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 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