add new playwright implementation to gog and amazon
This commit is contained in:
parent
d7e7cb3c58
commit
5a0ec268af
2 changed files with 13 additions and 19 deletions
13
gog.js
13
gog.js
|
|
@ -1,4 +1,4 @@
|
||||||
import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra
|
import { chromium } from 'patchright';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import { resolve, jsonDb, datetime, filenamify, prompt, notify, html_game_list, handleSIGINT } from './src/util.js';
|
import { resolve, jsonDb, datetime, filenamify, prompt, notify, html_game_list, handleSIGINT } from './src/util.js';
|
||||||
import { cfg } from './src/config.js';
|
import { cfg } from './src/config.js';
|
||||||
|
|
@ -17,13 +17,10 @@ if (cfg.width < 1280) { // otherwise 'Sign in' and #menuUsername are hidden (but
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://playwright.dev/docs/auth#multi-factor-authentication
|
// https://playwright.dev/docs/auth#multi-factor-authentication
|
||||||
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
|
const context = await chromium.launchPersistentContext(cfg.dir.browser, {
|
||||||
headless: cfg.headless,
|
channel: 'chrome',
|
||||||
viewport: { width: cfg.width, height: cfg.height },
|
headless: false,
|
||||||
locale: 'en-US', // ignore OS locale to be sure to have english text for locators -> done via /en in URL
|
viewport: null,
|
||||||
recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800
|
|
||||||
recordHar: cfg.record ? { path: `data/record/gog-${filenamify(datetime())}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools
|
|
||||||
handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved
|
|
||||||
});
|
});
|
||||||
|
|
||||||
handleSIGINT(context);
|
handleSIGINT(context);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra
|
import { chromium } from 'patchright';
|
||||||
import { authenticator } from 'otplib';
|
import { authenticator } from 'otplib';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import { resolve, jsonDb, datetime, stealth, filenamify, prompt, confirm, notify, html_game_list, handleSIGINT } from './src/util.js';
|
import { resolve, jsonDb, datetime, stealth, filenamify, prompt, confirm, notify, html_game_list, handleSIGINT } from './src/util.js';
|
||||||
|
|
@ -14,13 +14,10 @@ console.log(datetime(), 'started checking prime-gaming');
|
||||||
const db = await jsonDb('prime-gaming.json', {});
|
const db = await jsonDb('prime-gaming.json', {});
|
||||||
|
|
||||||
// https://playwright.dev/docs/auth#multi-factor-authentication
|
// https://playwright.dev/docs/auth#multi-factor-authentication
|
||||||
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
|
const context = await chromium.launchPersistentContext(cfg.dir.browser, {
|
||||||
headless: cfg.headless,
|
channel: 'chrome',
|
||||||
viewport: { width: cfg.width, height: cfg.height },
|
headless: false,
|
||||||
locale: 'en-US', // ignore OS locale to be sure to have english text for locators
|
viewport: null,
|
||||||
recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800
|
|
||||||
recordHar: cfg.record ? { path: `data/record/pg-${filenamify(datetime())}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools
|
|
||||||
handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved
|
|
||||||
});
|
});
|
||||||
|
|
||||||
handleSIGINT(context);
|
handleSIGINT(context);
|
||||||
|
|
@ -149,7 +146,7 @@ try {
|
||||||
console.log(' ', await p.locator('.availability-date').innerText(), '->', daysLeft.toFixed(2));
|
console.log(' ', await p.locator('.availability-date').innerText(), '->', daysLeft.toFixed(2));
|
||||||
if (isNew) await p.close();
|
if (isNew) await p.close();
|
||||||
return daysLeft > cfg.pg_timeLeft;
|
return daysLeft > cfg.pg_timeLeft;
|
||||||
}
|
};
|
||||||
console.log('\nNumber of free unclaimed games (Prime Gaming):', internal.length);
|
console.log('\nNumber of free unclaimed games (Prime Gaming):', internal.length);
|
||||||
// claim games in internal store
|
// claim games in internal store
|
||||||
for (const card of internal) {
|
for (const card of internal) {
|
||||||
|
|
@ -366,7 +363,7 @@ try {
|
||||||
await loot.waitFor();
|
await loot.waitFor();
|
||||||
|
|
||||||
process.stdout.write('Loading all DLCs on page...');
|
process.stdout.write('Loading all DLCs on page...');
|
||||||
await scrollUntilStable(() => loot.locator('[data-a-target="item-card"]').count())
|
await scrollUntilStable(() => loot.locator('[data-a-target="item-card"]').count());
|
||||||
|
|
||||||
console.log('\nNumber of already claimed DLC:', await loot.locator('p:has-text("Collected")').count());
|
console.log('\nNumber of already claimed DLC:', await loot.locator('p:has-text("Collected")').count());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue