try to force process exit

This commit is contained in:
Sebastian Hugentobler 2024-06-25 14:58:40 +02:00
parent 05ae5be02f
commit 548a4bcf8d
Signed by: shu
GPG Key ID: BB32CF3CA052C2F0

19
nzz.js
View File

@ -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();
}
}