Switch browser tabs without browser extensions or plugins, using
xdotool and crontab.
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
To start Chromium in kiosk mode, create a customized
mkdir -p ~/.config/lxsession/LXDE-pi cp /etc/xdg/lxsession/LXDE-pi/autostart ~/.config/lxsession/LXDE-pi vi ~/.config/lxsession/LXDE-pi/autostart
@lxpanel --profile LXDE-pi @pcmanfm --desktop --profile LXDE-pi # CHANGED #@xscreensaver -no-splash @point-rpi # BEGIN ADDED @/usr/bin/chromium-browser --incognito --start-maximized --kiosk https://blog.gordonturner.com https://google.com @unclutter @xset s off @xset s noblank @xset -dpms # END ADDED
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 run the following:
sudo apt-get install xdotool -y
Now edit the shell script to toggle tabs, this script will be in the
#!/bin/bash export DISPLAY=:0.0 export XAUTHORITY=/home/pi/.Xauthority /usr/bin/xdotool key Ctrl+Shift+Tab
chmod u+x ~/switch-tab.sh
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:
Finally, call the script automatically by creating a crontab entry for the
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.
switch-tab.sh script every minute:
* * * * * /home/pi/switch-tab.sh
switch-tab.sh script every 2 minutes:
*/2 * * * * /home/pi/switch-tab.sh
switch-tab.sh script every 5 minutes
*/5 * * * * /home/pi/switch-tab.sh
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.