Users often wonder what, exactly, does ProcrasDonate track. This is an entirely reasonable thing to wonder. Clay and the rounds of beta testers are iterating on how to make this clearer on the website.
Proudly ProcrasDonating is a technology blog, so I can happily overwhelm readers with all the subtleties of time track and if no one is the wiser then I’ll return to coding undeterred, and will try another blog post later, no harm done. If you have feedback, do share
The ProcrasDonate extension tracks the webpage currently being viewed. Let’s say you open Firefox and start reading GMail. Our extension records the start time.
Your friend has emailed you a link to Proudly ProcrasDonating, which opens in a new tab when you click on it. When you go to the new tab, the URL bar changes, which triggers our url bar listener. The listener stops recording the GMail visit, which is in turn saved in the database, and starts recording the Proudly ProcrasDonating visit.
If you switch back to the GMail tab, the visit to Proudly ProcrasDonating is halted and saved, and a visit to GMail is initiated. Same for switching between multiple Firefox windows.
We only record the webpage currently being viewed.
(This might be problematic for people who listen to internet radio or stream tv shows while they work. If you never visit the audio page, then we don’t know about it. I personally wouldn’t count that time as ProcrasDonating if the tabs I were actively viewing are work, but if I wanted to contribute to the audio content providers via TimeWellSpent, I wouldn’t be able to.)
* * *
Tracking the URL bar notifies us whenever the user visits a different webpage. However, we also need to be notified when the user does other things, including:
- Opens or closes Firefox
- Switches to another application and back to Firefox
- Walks away from the computer and comes back
- Puts his computer to sleep and wakes it up
- Force quits Firefox (or Firefox quits unexpectedly)
I’m going to explain each of these issues in turn, including the current state of things.
User opens or closes Firefox
This is covered by our InitListener, which is an
on the browser for ‘load’ and ‘unload’ events. Its time tracking is straightforward: stop recording when Firefox closes.
The tricky part is that when Firefox opens we don’t know whether it is in focus or not. The user might have opened Firefox and then switched to a different application before our extension is fully loaded and listening.
Right now we assume Firefox is out of focus; thus, we err on not recording the initial visit rather than record a false visit.
User switches to another application and back to Firefox
This is covered by our FocusBlurListener, which is an
on the browser for ‘focus’ and ‘blur’ events. A focus event occurs when an element, such as form field or the url bar, gains focus. A blur occurs when an element loses focus.
Let’s say the user is typing “procrastinate less” into the google search bar. The search bar has the focus. Halfway through typing, the user decides to click on the ProcrasDonate meter in their toolbar. The search bar blurs and the meter icon gains focus.
Because of “bubbling,” the containing elements also gain and lose focus. Thus, a single mouse click can trigger a dozen focus and blur events.
We care about the last event. If the user is clicking on Firefox elements, then the last event is some element gaining focus. If the user is clicking on a different application, or alt-tabbing to a different application, the last event is a blur event, since no Firefox element is gaining focus from the one that loses it.
Thus, the first time* a focus or blur event occurs, a timeout is set to run in 1 second. Also, every focus and blur event sets a last event type flag to either focus or blur.
After 1 second, the timeout function is called. If the last event type flag is focus, then we know Firefox is the active application and we may need to start recording a visit. Otherwise, we know Firefox is not active, and we should stop recording the visit.
*The timeout function also resets the first time flag.
User walks away from the computer and comes back
This is covered by our IdleBackListener, which registers with Mozilla’s idleServer,
. This is a neat service since the notifications come for the user’s operating system. I suspect this means that pressing volume and lighting controls, in addition to standard keyboard and mouse actions, including scrolling, also triggers non-idle-ness. It might be different per operating system, and it also can add up to a 5-second delay on notifications.
Detecting idleness is pretty tricky. We don’t know whether the user is reading an article or taking a bathroom break, nor whether the user is watching a video or was interrupted and is now talking to a friend.
To make matters worse, we can’t tell what’s happening with flash. Is the movie paused or is it playing? Is it an advertisement or an hour long show?
We try to err on the side of caution. We register two IdleBackListeners, one for flash pages and one for no-flash pages. The no-flash idle timeout occurs after a few minutes. There’s only so long one can read a single screen of text. If nothing happens, we give the user the benefit of the doubt and stop recording the visit. When the user comes back, we start recording again.
If the currently viewed webpage does contain flash then we wait for the 20 minute “idle with flash” timeout to occur. We figured that 20 minutes was the length of a short TV show, and would do for a default guess. If the user is watching a full movie, then maybe he will have to move his mouse within 20 minutes anyway to keep the screensaver from interrupting.
We plan to make idle detection more precise eventually. The backend already supports per-website idle timeout lengths. Time yet for iteration.
User puts his computer to sleep and wakes it up
I hadn’t initially thought about this case. Of course, it didn’t take long to realize that if I closed my laptop with Firefox the active application, I’d return to see a sudden spike in ProcrasDonation visits.
At first it seemed there was no Mozilla listener for the computer going to sleep or waking up. One solution would be to set our own timer to periodically chirp. If it ever chrips and notices that its last chirp was longer ago than expected, then some kind of pause occurred, and the current visit should stop at that last chirp.
Fortunately for my street cred, I was able to google and forum search it up until I found something interesting about Firefox’s download manager: it pauses downloads when a computer goes to sleep, and resumes them when the computer wakes up. A code search immediately turned up this gem here:
mObserverService->AddObserver(this, "sleep_notification", PR_FALSE); mObserverService->AddObserver(this, "wake_notification", PR_FALSE);
That looks like C code. Futzing around with Javascript soon yielded success, which now lives in our SleepWakeListener:
this.observerService.addObserver(this, "sleep_notification", false); this.observerService.addObserver(this, "wake_notification", false);
it was almost too easy. I emailed Eric Shepherd, Developer Documentation Lead, to ask why these notifications were not included in the Observer Notification page.
Simple omission apparently. I’ve since added a Computer Sleep, Wake section to the Observer Notification wiki page.
(A side-benefit of having sleep and wake work is that now when I close my laptop to go to bed, a time when I often forget to update my meticulous life-tracking calendar, I can simply read the last few messages in my development logs the next morning.)
User force quits Firefox (or Firefox quits unexpectedly)
There may be times when Firefox’s close notifications are not called, for instance an unexpected power outage, or a memory-leak-induced forced quit.
The chirps don’t sound like a bad idea now, although there might be a notification for when Firefox opens after not closing correctly.
I’m going to have to get back to you on this one since I’m still working on it.
It might also be nice to show the largest visits of the past week and allow submitting them as bugs, which would also subtract them from the time tracking totals.
I hope that cleared some thing up. Questions and suggestions are welcome as usual.
Proudly ProcrasDonating,
Lucy.







