Is there a way to test when a web page was opened?

I’m writing a script to keep a site from timing out. I access a website where after x minutes the site times out and forces you to log back in. I would like to write a script to keep the page alive by refreshing the page every x minutes, but don’t want the script to perform the refresh if I’m actively using the site. If there were a way to check when the last time that window was used or that page was loaded would solve my problem. Is there a way to test when a web page was opened or last accessed?



you could use the following script saved as stay open application.
It can refresh your site after a certain time of idle

property triggerTime : 2 * minutes
property checkInterval : 30 

on idle
	set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'") as integer
	if idleTime > triggerTime then
		-- do something
	end if
	return checkInterval
end idle

I had thought of this, but this only measures computer idle time much like a screensaver. This won’t work because I will be using the computer doing other things while needing the page refreshed.

If I knew when the last time the page was refreshed (by me and not the script) is probably the only way to do this. I’m trying to prevent the script from refreshing the page while I’m using the page. I could also be doing something else in Safari, like reading or searching on a different site at the same time too.