I'm trying to run a Node.js script that uses Nick.js with a headless chrome whose path must be declared in an environmental variable. When running this through the task scheduler and a batch file it crashes.
According to the Answer from What must be taken into account on executing a batch file as scheduled task? it is advisable not to use environmental variables in combination with scheduled tasks but I'm lacking alternatives at this moment.
This CHROME_PATH variable is defined locally as well as globally. I am the admin but when I set the task to 'run whether user is logged on or not', Node.js starts but doesn't find chrome anymore. I say 'anymore' intentionally because it used to work on two different machines and now it doesn't on either of them without any obvious reason.
In .bat:
cd C:\NodeJS\
node myScript.js
In myScript.js:
const Nick = require("nickjs");
const nick = new Nick();
(async () => {
const tab = await nick.newTab();
await tab.open("https://www.somePage.com");
...
});
return;
})()
...
The script freezes at tab.open()
without throwing an error and Node.js must be forced to stop. Any ideas how to solve this?