0

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Woodly0
  • 187
  • 2
  • 13
  • I'm reposting my question because it was marked as duplicate without having a satisfying answer. After editing it stayed marked as duplicate. – Woodly0 Apr 30 '19 at 07:32
  • So HOW DO YOU KNOW it doesn't work. It will be invisible. – Noodles Apr 30 '19 at 07:39
  • @Noodles: What is invisible? – Woodly0 May 01 '19 at 08:09
  • The program, Your settings says run it invisible. – Noodles May 01 '19 at 08:27
  • @Noodles: Well, if you mean 'hidden' then yes. I can assure you that this setting has no influence on the problem. The output of the script is a file which should contain some data from the web page. This file is not created which is a 'visible' proof that it doesn't run through. – Woodly0 May 01 '19 at 14:41
  • Guys, if anyone is interested: Puppeteer-Sharp provides a nice workaround for this problem. It allows js execution within the .NET framework, i.e. there is no more need for Node.js. Even though that solves my problem it is not really an answer to my question so I'm posting it here. – Woodly0 Jul 26 '19 at 10:55

0 Answers0