Autostarting a browser on the Raspberry Pi

In this tutorial, I’ll show you how to start a browser after booting on the raspberry pi.

  1. Disable login
    In case you want the browser to start without having to log in, apply the following steps:

    sudo vi /etc/inittab

    Comment this line …

    1:2345:respawn:/sbin/getty 115200 tty

    … like this.

    #1:2345:respawn:/sbin/getty 115200 tty1

    Add the following line:

    1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1

    Save and exit vi with :wq.

  2. Start X server after boot
    Edit this file:

    sudo vi /etc/rc.local

    And add the following line before the line ‘exit 0’.

    su -l pi -c startx

    Save and quit vi.

  3. Autostarting bash script
    Let’s create a bash script that should be executed after startup. Here we shall place the command to execute the browser. Of course, you can extend this script as you like.

    vi /home/pi/start.sh

    Now add the following code to start the browser midori in fullscreen mode pointing at the adress www.bbc.co.uk.

    #!/usr/bin/sh
    midori -e Fullscreen -a www.bbc.co.uk &

    Make your bash script executable.

    sudo chmod +x /home/pi/start.sh

    Add the script execution to your LXDE autostart file.

    sudo vi /etc/xdg/lxsession/LXDE/autostart

    Add the line

    @sh /home/pi/start.sh

    That’s it! You’re good to go. Try rebooting.

  4. Optional steps
    You may notice your screen going black or a screensaver starting which might not be what you want for your application. Luckily, you can change this in a few easy steps.
    Install the package x11-xserver-utils.

    sudo apt-get install x11-xserver-utils

    Now edit the autostart file again. Uncomment the screensaver and add a few lines. Your file should look something like this.

    @lxpanel --profile LXDE
    @pcmanfm --desktop --profile LXDE
    #@xscreensaver -no-splash
    @xset s off
    @xset -dpms
    @xset s noblank
    @sh /home/pi/start.sh
    

    Your screen should stay on permanently.
    If you would like to hide the mouse, install the tool unclutter and add the following line to the top of the start.sh:

    unclutter -idle 5 &