From 548a4bcf8da224c60a78dbc8a586aaa0ecb577d3 Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Tue, 25 Jun 2024 14:58:40 +0200 Subject: [PATCH] try to force process exit --- nzz.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/nzz.js b/nzz.js index 37d9ea1..5f793a2 100755 --- a/nzz.js +++ b/nzz.js @@ -219,6 +219,7 @@ async function findIssues(driver, from, to, tmpDir, outDir) { SEARCH_WAIT_TIMEOUT, SEARCH_TIMEOUT_MSG, ); + await articles[0].click(); await sleep(500); @@ -233,7 +234,7 @@ async function findIssues(driver, from, to, tmpDir, outDir) { } catch { // this means there is no issue on the searched date // move along with the next date - continue; + console.log(`\tno issues`); } } } @@ -256,14 +257,15 @@ async function run(from, to, user, password, outDir) { console.log(`downloading to ${outDir} (tmp dir: ${tmpDir.name})...`); const fxOptions = new fx.Options() - // .addArguments("-headless") + .addArguments("-headless") .setPreference("pdfjs.disabled", true) .setPreference("general.useragent.override", USER_AGENT) .setPreference("browser.helperApps.neverAsk.openFile", "application/pdf") .setPreference("browser.download.folderList", 2) .setPreference("browser.download.manager.showWhenStartingout", false) .setPreference("browser.download.dir", tmpDir.name) - .setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf"); + .setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf") + .setPreference("browser.tabs.warnOnClose", true); const caps = new Capabilities(); caps.setPageLoadStrategy("normal"); @@ -277,10 +279,15 @@ async function run(from, to, user, password, outDir) { try { await login(driver, user, password); await findIssues(driver, from, to, tmpDir.name, outDir); - await sleep(1000); + // await sleep(1000); } finally { - driver.quit(); - fs.rmSync(tmpDir.name, { recursive: true }); + await fs.rm(tmpDir.name, { recursive: true }, (e) => { + if (e) { + console.error(`failed to remove tmp directory: ${e}`); + } + }); + await driver.quit(); + process.exit(); } }