1

I want to open my chromium web browser in fullscreen-mode and open an URL that I get from a different config file. All this should happen automatically after booting. For testing, I tried to execute a terminal command in python first of all with

import os
import webbrowser
os.system(chromium-browser --start-fullscreen www.google.de)

But it throws an invalid syntax error.

Is there a possibility to start the browser with something different than with a systemd service file?

I am running this on an RPI 4 with the newest version of Raspbian.
Thank you for your advice

M. Rostami
  • 4,323
  • 1
  • 17
  • 36
Soam.P
  • 57
  • 2
  • 6

2 Answers2

2

Create a service file:

sudo nano /etc/systemd/system/startupbrowser.service  

Put all lines below there:

[Unit]
Description=startupbrowser
After=graphical.target

[Service]
User=pi
WorkingDirectory=/home/pi
Environment=DISPLAY=:0
ExecStart=/usr/bin/chromium-browser --start-fullscreen www.google.de

[Install]
WantedBy=graphical.target

Enable the new service and reboot the raspberry pi:

sudo systemctl enable startupbrowser.service 
sudo systemctl reboot  

Source

M. Rostami
  • 4,323
  • 1
  • 17
  • 36
  • Better not to fiddle direct with systemd system files in /etc/systemd/system/. It is less error prone using systemctl edit with its options, in particular if you have drop in files. – Ingo Apr 03 '20 at 21:20
2

I would use the service as per the other answer as os.system() is no longer the preferred way of calling external programs.

If you do wish to put the command into a python program using os.system() then you could use:

import os
cmd = "/usr/bin/chromium-browser --start-fullscreen www.google.de"
os.system(cmd)

The advantage of Python is that it is much simpler to handle error checks / reporting (code snippet - will not work fully):

try:
    retcode = call(cmd, shell=True)
    if retcode < 0:
        print("Browser was terminated", -retcode, file=sys.stderr)
    else:
        print("Browser returned", retcode, file=sys.stderr)
except OSError as e:
    print("Execution of the browser failed:", e, file=sys.stderr)

Note the use of sys.stderr to get the completion status back from the browser.