Autostart Chromium After Node-Red Starts

I really don't know why this hasn't been posted yet or maybe it has before, or maybe because it is so simple to do it gets overlooked.

If you search the web, you will find a load of information for automatically starting an application on boot.
I have recently done this for my Node-Red installation and because my application runs in a sort of kiosk mode, I needed Chromium to be auto-started too.
I did the natural thing and added an entry to the /lxsession/LXDE-pi/autostart directory.

What I found was that node-red takes much longer to start than chromium does. Ultimately, you are left with a "localhost not responding" page displayed in chromium. Then once node-red is up and running, chromium will eventually navigate to the node-red ui.

I searched all over the internet to see how I could make chromium wait for node-red to start to no avail. Actually, you will be hard pressed to find any information on "wait for app x to be running before running app y".

Then I remembered that node-red has an execute node. Why not let node-red start chromium and navigate to the ui?

Easy enough, although there are some gotchas with starting chromium from the terminal.
I am using X11vnc on my raspberry pi, and in order to start chromium from the command line, you must tell it which display to start from. Like this:

DISPLAY=:0 chromium-browser http://localhost:1880/ui -start-fullscreen;

That works fine, but everytime I would Deploy a change to my flows, it would start another chromium browser.

So, I did some more digging and found a bit of bash to help.
In order to use this, go to terminal and type:

cd ~
sudo nano startChromium.sh

Then type the following into the text editor.

#!/bin/bash

if pidof chromium-browser > /dev/null
then
        echo Running
else
DISPLAY=:0 chromium-browser http://localhost:1880/ui -start-fullscreen;
fi

Then press Ctrl-O to write the file, Enter to confirm the filename, then Ctrl-X to exit.
Now you must make this file an executable by doing the following:

cd ~
chmod u+x startChromium.sh

Now you can test your script from terminal like so:

cd ~
bash startChromium.sh

This shell script will check if the chromium browser is running, if it is running "Running" will display in the terminal window. If chromium is not running, the script will start it.

Now all that is left to do is add your flow to make it work.

[{"id":"b209822d.9e674","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"40ee18a5.154a38","type":"inject","z":"b209822d.9e674","name":"Trigger Once At Startup","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"2","x":450,"y":270,"wires":[["2f984eaf.bf7712"]]},{"id":"2f984eaf.bf7712","type":"exec","z":"b209822d.9e674","command":"bash startChromium.sh","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Start Chromium If It Is Not Running","x":700,"y":340,"wires":[["dcd88b38.3637e8"],[],[]]},{"id":"dcd88b38.3637e8","type":"debug","z":"b209822d.9e674","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":940,"y":270,"wires":[]}]

6 Likes

UPDATE:

Found some more neat commands for chromium. Running the script above does work, but you will, at times, be prompted with messages from chromium.
Example: "Chromium is not your default browser" & "Chromium did not shut down properly, restore pages?"

To hide these alerts you can use this command instead. Note that some of these commands may be redundant, I havn't played with it since I got this working.

The --start-fullscreen command can probably be omitted because it is using the --app= command instead.

DISPLAY=:0 chromium-browser --disable-infobars --noerrdialogs --app=http://localhost:1880/ui -start-fullscreen;

4 Likes

Thanks. I was looking for this and gone test it!

1 Like

Hello, I liked this publication. I am working with a raspberry and start chromium automatically and an application that with nodejs. But I start running well and then it stops me because it use all RAM memory, can you give me an idea to avoid this memory devouring by the browser?

That is a common problem with chromium. There are many posts on Stack and other places with people asking for help.

The one thing that is most often suggested is to make sure you have the latest version of chromium installed. You can google "how to update chromium on raspberrypi" to get some answers.