wbickle
Posts: 8
Joined: Wed Mar 02, 2016 2:41 am

Chromium Auto Refresh

Wed Mar 22, 2017 2:59 pm

Running the current version of Pixel on my Pi 3, is it possible to add something to the crontab file which will auto refresh the open Chromium page on a scheduled basis?

TIA.

Bill

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5747
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Chromium Auto Refresh

Wed Mar 22, 2017 3:30 pm

There are chrome addons that can do this. Does this work?
https://chrome.google.com/webstore/deta ... njkc?hl=en

wbickle
Posts: 8
Joined: Wed Mar 02, 2016 2:41 am

Re: Chromium Auto Refresh

Sat Mar 25, 2017 2:38 pm

Yes! Thanks so much.

Bill

relayman357
Posts: 3
Joined: Mon Nov 06, 2017 3:28 pm

Re: Chromium Auto Refresh

Mon Nov 06, 2017 3:30 pm

You may want to check this out before using that extension: https://www.youtube.com/watch?v=9k0wqHMOyD0

This suggests rather convincingly that it is malware.

relayman357
Posts: 3
Joined: Mon Nov 06, 2017 3:28 pm

Re: Chromium Auto Refresh

Mon Nov 06, 2017 3:39 pm

Also, if you just need to refresh a local html file then just embed the following meta line in your html file:

<META HTTP-EQUIV="refresh" CONTENT="30"> <! -- This is to force refresh of this page every 30 seconds>

Leon71
Posts: 1
Joined: Sun Nov 26, 2017 10:41 am

Re: Chromium Auto Refresh

Sun Nov 26, 2017 3:11 pm

I have solved it with xdotools

I copied the autostart file from /etc/xdg/lxsession/LXDE-pi/autostart to /home/pi/.config/lxsession/LXDE-pi/autostart with the command:
cp /etc/xdg/lxsession/LXDE-pi/autostart /home/pi/.config/lxsession/LXDE-pi/autostart

After that, I edited the local version:
sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart :

@xscreensaver -no-splash
@xset s off
@xset -dpms
@xset s noblank
@chromium-browser --incognito --kiosk http://www.yoursite.com # load chromium after boot

Next, create a file called 'autorefresh-chromium.sh' in /home/pi/ #or any folder you like
chmod the file with the command: chmod 755 /home/pi/autorefresh-chromium.sh to make it exetcutable

Open /home/pi/autorefresh-chromium.sh

Add the following lines:

#!/bin/bash
while true; #create an infinite loop
do
sleep 1200 #refresh time in seconds so 1200 = every 20 min
xdotools key = ”ctrl+F5” & #you need to have xdotools installed
done

Add @/home/pi/autorefresh-chromium.sh to /home/pi/.config/lxsession/LXDE-pi/autostart.
So the file looks like this:

@xscreensaver -no-splash
@xset s off
@xset -dpms
@xset s noblank
@chromium-browser --incognito --kiosk http://www.yoursite.com # load chromium after boot
@/home/pi/autorefresh-chromium.sh

This worked for me

MWZotti
Posts: 9
Joined: Wed Mar 14, 2018 9:52 pm

Re: Chromium Auto Refresh

Wed Mar 28, 2018 1:57 am

Leon71 wrote: I have solved it with xdotools

I copied the autostart file from /etc/xdg/lxsession/LXDE-pi/autostart to /home/pi/.config/lxsession/LXDE-pi/autostart with the command:
cp /etc/xdg/lxsession/LXDE-pi/autostart /home/pi/.config/lxsession/LXDE-pi/autostart

After that, I edited the local version:
sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart :

@xscreensaver -no-splash
@xset s off
@xset -dpms
@xset s noblank
@chromium-browser --incognito --kiosk http://www.yoursite.com # load chromium after boot

Next, create a file called 'autorefresh-chromium.sh' in /home/pi/ #or any folder you like
chmod the file with the command: chmod 755 /home/pi/autorefresh-chromium.sh to make it exetcutable

Open /home/pi/autorefresh-chromium.sh

Add the following lines:

#!/bin/bash
while true; #create an infinite loop
do
sleep 1200 #refresh time in seconds so 1200 = every 20 min
xdotools key = ”ctrl+F5” & #you need to have xdotools installed
done

Add @/home/pi/autorefresh-chromium.sh to /home/pi/.config/lxsession/LXDE-pi/autostart.
So the file looks like this:

@xscreensaver -no-splash
@xset s off
@xset -dpms
@xset s noblank
@chromium-browser --incognito --kiosk http://www.yoursite.com # load chromium after boot
@/home/pi/autorefresh-chromium.sh

This worked for me
I copied these directions then wondered why this didn't work. So just to clarify for all others that may want to use this..... you need xdotool and change the line to:

Code: Select all

export XAUTHORITY=/home/pi/.Xauthority; export DISPLAY=:0; xdotool key "your key combination here" & 
The latest key combos according to google support https://support.google.com/chrome/answer/157179?hl=en :
Reload current page: F5 or Ctrl+r
Reload the current page, ignoring cached content: Shift+F5 or Ctrl+Shift+r

User avatar
Gerrelt
Posts: 294
Joined: Sat Nov 10, 2012 9:01 am

Re: Chromium Auto Refresh

Tue Apr 10, 2018 6:47 pm

I didn't get this working either, even with the tip from MWZotti. But he did point me in the right direction for the solution, thank you MWZotti!
The problem is that xdotools doesn't work under the root user without setting Xauthority.
And adding it to LXDE autostart will make it run under root.

I solved it by creating another script that will set Xauthority for the root user. This script has to be executed before the autorefresh script.

Instructions:

Install xdotools:

Code: Select all

sudo apt-get install xdotool
Next create a script called "xauth_root.sh":

Code: Select all

cd /home/pi
sudo nano xauth_root.sh
Then add these lines to it:

Code: Select all

#!/bin/bash

#
# source: https://raspberrypi.stackexchange.com/questions/1719/x11-connection-rejected-because-of-wrong-authentication
#
touch /root/.Xauthority
xauth merge /home/pi/.Xauthority
export XAUTHORITY=/root/.Xauthority

Make it executable:

Code: Select all

sudo chmod 755 xauth_root.sh
Now create this auto refresh script:

Code: Select all

sudo nano autorefresh-chromium.sh
Add these lines:

Code: Select all

#!/bin/bash

#
# also see instructions here: https://www.raspberrypi.org/forums/viewtopic.php?t=178206#p1239241
#
# To make this run with sudo (which is the case when run at boot), execute "xauth_root.sh" before running this script.
#
# xdotools setup instructions found here: http://theembeddedlab.com/tutorials/simulate-keyboard-mouse-events-xdotool-raspberry-pi/
#

# This will only set up the DISPLAY variable for one command
DISPLAY=:0 xdotool key "ctrl+F5"

# This will set up the DISPLAY variable for every command executed on this terminal,
# and child processes spawned from this terminal
export DISPLAY=:0

while true; #create an infinite loop
do
  xdotool key "ctrl+F5" &
  sleep 300 #refresh time in seconds so 300 = every 5 min
done
(note that this will refresh it every 5 minutes)

Make it executable:

Code: Select all

sudo chmod 755 autorefresh-chromium.sh
Open the LXDE autostart file:

Code: Select all

sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart
And add these three lines to the end (set the desired URL in the first line):

Code: Select all

@chromium-browser --incognito --kiosk http://someURL.youwanttodisplay.com # load chromium after boot
@/home/pi/xauth_root.sh
@/home/pi/autorefresh-chromium.sh
This worked for me!

(see urls in scripts for sources)
my Raspberry Pi page: http://raspberry.gerrelt.nl

PaoloM
Posts: 5
Joined: Tue May 14, 2019 7:20 am

Re: Chromium Auto Refresh

Thu Jun 13, 2019 12:32 pm

Hi guys, is it possible to set only 1 refresh of chromium only at startup?

k0kster
Posts: 10
Joined: Tue Sep 03, 2019 9:02 am

Re: Chromium Auto Refresh

Mon Sep 09, 2019 2:39 am

relayman357 wrote:
Mon Nov 06, 2017 3:39 pm
Also, if you just need to refresh a local html file then just embed the following meta line in your html file:

<META HTTP-EQUIV="refresh" CONTENT="10"> <! -- This is to force refresh of this page every 30 seconds>
hi!

i tried adding the above line into the html file by opening it with chrome and pressing f12.

my head looks like this

https://drive.google.com/open?id=1spQ5B ... HPZMQMpDAA

however, 10 seconds later the meta line diasppears after being refreshed.

theWoosh
Posts: 2
Joined: Wed Dec 04, 2019 10:34 am

Re: Chromium Auto Refresh

Wed Dec 04, 2019 10:40 am

Hi Folks
Just wondering - rather than make a shell script that is always operating in a loop, why not just add a cron job that executes at regular intervals and calls a simple shell script?

SerGiggity
Posts: 10
Joined: Fri Oct 13, 2017 12:29 pm

Re: Chromium Auto Refresh

Sat Sep 12, 2020 11:44 am

relayman357 wrote:
Mon Nov 06, 2017 3:39 pm
Also, if you just need to refresh a local html file then just embed the following meta line in your html file:

<META HTTP-EQUIV="refresh" CONTENT="30"> <! -- This is to force refresh of this page every 30 seconds>
Apologies but I'm a total newbie at this- how would I use this command to refresh a chromium browser displaying google calendar pls??

stanwin00
Posts: 60
Joined: Tue Aug 06, 2019 9:55 am

Re: Chromium Auto Refresh

Thu Dec 17, 2020 8:44 am

Very good article! thank you!

deepo
Posts: 807
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: Chromium Auto Refresh

Thu Dec 17, 2020 9:23 am

SerGiggity wrote:
Sat Sep 12, 2020 11:44 am
relayman357 wrote:
Mon Nov 06, 2017 3:39 pm
Also, if you just need to refresh a local html file then just embed the following meta line in your html file:

<META HTTP-EQUIV="refresh" CONTENT="30"> <! -- This is to force refresh of this page every 30 seconds>
Apologies but I'm a total newbie at this- how would I use this command to refresh a chromium browser displaying google calendar pls??
You can't but if you wrote your own html code that would do the trick.
Don't the Google Calendar update the page automatically when something new happens? I would have thought that.

YoctoYotta
Posts: 1
Joined: Wed Mar 10, 2021 7:37 pm

Re: Chromium Auto Refresh

Wed Mar 10, 2021 8:05 pm

relayman357 wrote:
Mon Nov 06, 2017 3:39 pm
Also, if you just need to refresh a local html file then just embed the following meta line in your html file:

<META HTTP-EQUIV="refresh" CONTENT="30"> <! -- This is to force refresh of this page every 30 seconds>
A word of warning for the few people that might be in the same boat as me. If your web page is prone to time out after an extended time (mine are local-IIS hosted ASP pages for SQL SSRS charts being displayed 24/7), this refresh code can no longer load and the page stops refreshing automatically. In my case, a refresh of the browser page through some other means like a browser plugin or chron script is mandatory.

Also, if anyone has any tips for preventing IIS-hosted ASP pages displaying SQL SSRS charts 24/7 from timing out, please share =)

COASTER19
Posts: 2
Joined: Wed Mar 03, 2021 1:58 am

Re: Chromium Auto Refresh

Fri Mar 19, 2021 2:51 am

YoctoYotta wrote:
Wed Mar 10, 2021 8:05 pm
relayman357 wrote:
Mon Nov 06, 2017 3:39 pm
Also, if you just need to refresh a local html file then just embed the following meta line in your html file:

<META HTTP-EQUIV="refresh" CONTENT="30"> <! -- This is to force refresh of this page every 30 seconds>
A word of warning for the few people that might be in the same boat as me. If your web page is prone to time out after an extended time (mine are local-IIS hosted ASP pages for SQL SSRS charts being displayed 24/7), this refresh code can no longer load and the page stops refreshing automatically. In my case, a refresh of the browser page through some other means like a browser plugin or chron script is mandatory.

Also, if anyone has any tips for preventing IIS-hosted ASP pages displaying SQL SSRS charts 24/7 from timing out, please share =)
THANK YOU! This has issue has been plaguing my information kiosk for ages.

To avoid all of the root issues just add the following to crontab (run crontab -e, NOT sudo crontab -e)

Code: Select all

 * * * * * DISPLAY=:0 /home/pi/crontabrefresh.sh
and create the file crontabrefresh.sh in your home folder with the following content:

Code: Select all

#!/bin/bash
xdotool key shift+F5
and make it executable with

Code: Select all

chmod 755 /home/pi/crontabrefresh.sh
Rebooting every night was good enough 90% of the time but sometimes it crashed in the last 4 hours of the day. I assumed it was a memory management or poor programming on my part since I'm using a pi zero, but turns out it was chromium all along (and I know chromium isn't ideal on a pi zero, but midori and kweb have poor CSS support, and firefox doesn't support the older architecture).

Return to “Beginners”