How to start uzbl browser on startup on a Raspberry PI

I wanted to use my Raspberry Pi to view build status, graphite charts and some other stuff on a TV.
I have my Raspberry, I needed to configure it to start uzbl (which is a very lightweight and easy to script browser).

Once you have a working raspberry (or any Debian environment), follow the steps written below:

Install software

We will need an xserver to have a graphical interface, a window manager and the web browser.
I choose Fluxbox as WM
Use apt-get install command to install xorg, fluxbox and uzbl:

$ sudo apt-get install xserver-xorg xinit fluxbox uzbl

Start the X server on startup

I would not introduce a display manager, like XDM or GDM to start the X server, so do it by edit the /etc/rc.local.

$ sudo $EDITOR /etc/rc.local

Add to the end of the file

su -l pi -c startx

Allow to start X outside of console

By default it's disabled to start the X from the rc.local file, we need to change the X11 configuration.

$ sudo dpkg-reconfigure x11-common

Select anybody then save.

Configure fluxbox

Start uzbl when fluxbox starts

Fluxbox has a nice feature, the startup file to start anything when fluxbox starts.

So edit the ~/.fluxbox/startup file

$ $EDITOR ~/.fluxbox/startup

Add the following lines before exec fluxbox

sleep 1 { /usr/bin/uzbl https://ajnasz.hu } &

Configure uzbl appearance

I would like to open the browser without any window decoration, in fullscreen and above every other element.
Edit the ~/.fluxbox/apps file and to configure it:

$ $EDITOR ~/.fluxbox/apps

[app] (name=uzbl-core) (class=Uzbl-core) [Deco] {NONE} [FocusNewWindow] {yes} [Minimized] {no} [Maximized] {yes} [Fullscreen] {yes} [Layer] {2} [end]

These are the basic steps to configure any application besides uzbl to open when the device boots up.

Rotate pages in uzbl

My main goal was to change the graphs, dashing boards and other pages regularly. To do that, put the following script into a file, for example into the home directory:

$ $EDITOR ~/rotate.js

(function () { var pages = [ 'https://ajnasz.hu', 'https://team.ajnasz.hu', 'https://scrumpoker.ajnasz.hu', 'http://www.ustream.tv', ];

var timeout = 120000;

function getValidIndex(index) {
    var undef;

    return index > -1 ? index : undef;
}

function slice(str, index, tries) {
    var output;

    while (tries.length) {
        output = str.indexOf(tries.shift(), index);

        if (output > -1) {
            break;
        } else {
            output = -1;
        }
    }

    return output;
}

function createUrlObj(url) {
    var obj = {
        proto: '',
        host: '',
        path: '',
        search: ''
    }, index, endIndex;

    obj.proto = url.slice(0, url.indexOf(':') + 1);

    index = obj.proto.length + 2;

    endIndex = slice(url, index, \['/', '?', '#'\]);
    obj.host = url.slice(index, getValidIndex(endIndex));

    index += obj.host.length;
    endIndex = slice(url, index, \['?', '#'\]);
    obj.pathname = url.slice(index, getValidIndex(endIndex));

    if (obj.pathname === '') {
        obj.pathname =  '/';
    } else {
        index += obj.pathname.length;
    }

    endIndex = slice(url, index, \['#'\]);
    obj.search = url.slice(index, getValidIndex(endIndex));

    index += obj.search.length;
    obj.hash = url.slice(index);

    return obj;
}

function getCurrent(href) {
    var current = -1,
        p;

        for (var i = 0, tl = pages.length; i = pages.length) {
            current = 0;
        }

        current = Math.max(0, current);

        console.log('load ' + pages\[current\]);

        window.location.assign(pages\[current\]);
    }
};

function schedule() {
    setTimeout(function () {
        uzbl.pager.next();
    }, timeout);
}

schedule();

}());

At the beginning of the file you can see the pages variable, edit and extend it to list all of the pages you want to rotate. The timeout variable defines how often you want to change page.

Run the rotate script

To run the rotate script, open the uzbl configuration file:

$ $EDITOR ~/.config/uzbl/config

There will be a bunch of configuration options. Search for js uzbl = {};

Then add the following line after it:

@on_event LOAD_COMMIT script /home/pi/rotate.js

Thats all, $ sudo reboot and you must be fine.

Hozzászóláshoz a Disqus szolgáltatását használom, korábbi vélemények elovlasásához és új hozzászólás írásához engedélyezd a Disqus-tól származó JavaScripteteket.