Open a web browser with EXEC node

Hello, I'm attempting to use Node-Red to open a web browser UI on the Windows 10 PC which hosts Node-Red.
I've tried using the EXEC node in spawn mode for this purpose with the command powershell start chrome, however chrome launches as 7 background processes rather than a chrome application with a desktop UI (i.e. no browser UI is visible in Windows).
Node-Red is running under the admin user account, on a single user PC.
My goal is to use Node-Red to open / close Chrome UI, and to control the displayed content.
Any assistance is most appreciated - thanks in advance.

This may be the issue. Are you saying that you are running it from an elevated command or from a different user to the one normally logged in?

As far as I can tell, you should be able to do this fine. I'll check if I have time.

However, don't get your hopes up too far. You do realise that you cannot automate Chrome from powershell, let along Node-RED don't you?

There are however tools that will let you do that such as Selenium. I think some of the headless browser tools also let you create a window as well.

Node-Red is running under the logged in user account, which is also an administrator account.

I was able to successfully use Selenium to launch Chrome using node-red-contrib-selenium-webdriver.
For comparison purposes, I tried using Node.js Puppeteer via a Function node to launch Chromium. This worked with limited success, as Puppeteer employs asynchronous callbacks which Node-Red doesn't appear to support.
Sadly, while Selenium works, the web site I was using it with relies on user authentication and this appears to be lost, resulting in a manual login each time.

I still don't understand why the EXEC node won't launch chrome under Win 10. I tried launching VLC (start vlc) and observed the same behaviour with the EXEC node, i.e. VLC spawned as a background process without a UI. The same command works successfully when entered to Powershell running under the user account.

I tried using Node-Red running under Raspbian to launch Chromium with no luck. Entering pi@raspberrypi:~ $ chromium-browser & disown into a terminal window works , however the same command used in the EXEC node doesn't.
The following debug messages were received :
[11312:11312:1126/164144.443246:ERROR:browser_main_loop.cc(670)] Failed to put Xlib into threaded mode. and (chromium-browser:11312): Gtk-WARNING **: cannot open display:

There's probably an obvious reason related to the use of a child process in the EXEC node, but my software skills are rather limited.

Thanks for your help.

OK, that is different. Such a user only gets limited access by default, many tasks will generate the protection dialog. Not the same as running Node-RED itself with admin privileges.

Well, NR is written using JavaScript/NodeJS so in theory, it does support them. However, integration can be a challenge. It might need you to require the library in settings.js as a global variable - you can then make use of it from within a function node. A proper custom node would be better of course but a lot more work.

It would be interesting to try the equivalent call direct from a simple, test, Node.JS app. That would probably show whether it is a Node-RED issue or a Node.JS one.

Also, have you tried starting chrome.exe directly from the EXEC node?

So, some quick tests.

Under Windows 10, even with PowerShell set as the default shell, the exec node starts a cmd window not a powershell. It is that that is causing the issue.

Change the exec to be the following command (adjusting for the location of your ps1 file):

powershell -NonInteractive -NoLogo ./data/chrome.ps1

That works just fine.

I tried your suggested fix however the problem remained. So I checked in task manager and Node.js was running as a background process owned by SYSTEM. As it turns out, I am launching node-red via the Windows Task Scheduler and I had selected the 'run whether user is logged on or not' button. After changing the node-red task to run only when the user is logged on, and running the task, Node.js appeared as an application owned by the user. Magically I was now able to launch chrome via the EXEC node using the command path\script.cmd where script.cmd is start chrome "https://www.google.com.au".
The lesson here seems to be don't expect Node.js running as a system service to launch applications with a UI.
Thanks so much for your help.

1 Like

Which is the same for Linux / Pi - as per your "can't open display" messages above.

1 Like

sorry for my poor english.

do you can´t use eletron-node red?
see: https://github.com/natcl/electron-node-red, https://www.npmjs.com/package/micro-app-electron-launcher, https://poshtools.com/2018/02/05/creating-desktop-app-universal-dashboard-installer-powershell-pro-tools/

There are lots of ways to run Node-RED, it depends on your requirements. Personally I don't use the Electron version as I don't need it. But I tend to run NR manually on my Windows PC as I use it mainly for development and occasional bits-and-pieces so I don't need it running all the time. I have defined some handy scripts in my npm package.json file. So I have standard ways of updating and running NR and its nodes.