disable Playwright's handleSIGINT and close context ourselves to save recordings also on SIGINT

This commit is contained in:
Ralf Vogler 2023-09-18 12:58:20 +02:00
parent 1fbabbc0f2
commit b748460b73
5 changed files with 24 additions and 15 deletions

View file

@ -12,8 +12,6 @@ console.log(datetime(), 'started checking prime-gaming');
const db = await jsonDb('prime-gaming.json', {});
handleSIGINT();
// https://playwright.dev/docs/auth#multi-factor-authentication
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
headless: cfg.headless,
@ -21,8 +19,11 @@ const context = await firefox.launchPersistentContext(cfg.dir.browser, {
locale: "en-US", // ignore OS locale to be sure to have english text for locators
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-${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);
// TODO test if needed
await stealth(context);
@ -377,8 +378,9 @@ try {
console.log('DLC: Unlinked accounts:', dlc_unlinked);
}
} catch (error) {
console.error(error); // .toString()?
process.exitCode ||= 1;
console.error('--- Exception:');
console.error(error); // .toString()?
if (error.message && process.exitCode != 130)
notify(`prime-gaming failed: ${error.message.split('\n')[0]}`);
} finally {