Raspberry Pi Switch Chromium Browser Tabs

TL;DR

Switch browser tabs without browser extensions or plugins, using xdotool and crontab.

Details

A common Raspberry Pi use case is to run Chromium browser full screen as a digital sign.

The following instructions will use the xdotool to send keypresses to switch browser tabs. The commands will be saved in a shell script. The shell can be triggered by crontab or input from GPIO.

Setup and Configure

It is assumed that Raspbian Buster desktop has been installed with Chromium and setup to automatically login the user pi to the desktop.

Tested with the following versions:

  • Raspbian, Buster desktop version 2019-07-10
  • Chromium version 74.0.3729.157
  • xdotool version 3.20160805.1

Starting Chromium

To start Chromium in kiosk mode, create a customized autostart file:

This should start Chromium in incongnito, maximized, in kiosk mode with two tabs (https://blog.gordonturner.com & https://google.com).

Additionally, screen blanking and screensavers are disabled and the mouse cursor is hidden.

xdotool Script

To install xdotool run the following:

Now edit the shell script to toggle tabs, this script will be in the /home/pi directory.

Make executable:

This will send the keypresses Ctrl+Shift+Tab to the desktop application that has focus, which should be Chromium and switch to the next tab.

With Chromium fullscreen and with two tabs, test the script by calling it from a remotely connected ssh session:

Crontab

Finally, call the script automatically by creating a crontab entry for the pi user.

As the user pi, edit the crontab:

A couple of options, depending on how often the tabs should be switched, every 1, 2 or 5 minutes.

Run the switch-tab.sh script every minute:

Run the switch-tab.sh script every 2 minutes:

Run the switch-tab.sh script every 5 minutes

Conclusion and Commentary

That should be it, no browser plugin, just good old fashioned command line tools and crontab.

If you have setup lirc, you can also configure irexec to call the script and you have a remote control mapped to toggle the browser tabs.

Comments are closed.