Snapping Back to Google

I’ve been playing around with trying to implement a JavaScript version of SnapBack like in Safari. I thought I’d try it first as a bookmarklet since the JavaScript History object already provides some of what’s needed.

With JavaScript you can easily jump back to the previous Google page in history. Here’s a bookmarklet to do just that: BackToGoogle. This is limited, but may be a nice shortcut. The feature in Safari has the advantage that the SnapBack button only appears when it would be useful. Safari also resets the location of the SnapBack if you use a bookmark or type a URL. In the case of this bookmarklet, it always goes back to the previous Google entry in the history.

I believe I may have found a bug in Mozilla in writing this. According to the documentation, history.go(location) should load the nearest history entry whose URL contains location as a substring (the most recently visited). Mozilla appears to be loading the first history entry that has that substring (the first one visited). Or so it seemed.

I’ve done some more experimenting with this including working with the UniversalBrowserRead privilege so I can use the history array, but that has not helped. What I’d like to be able to do is traverse the history looking at the referrers. If an item has no referrer then it would likely be a nice location to jump back to. (Or potentially the page right after it if it has a query string; it would be more likely to be a search results page.) Unfortunately, I see no way to get the referrers from JavaScript other than for the current page. I wonder if the browser’s history mechanism actually keeps track of the referrer or if it just contains the list of URLs loaded in the window.