Search code examples
google-chromegoogle-chrome-extensionbrowser-history

google chrome extension for manipulating browsing history


I'm thinking of developing a Google Chrome extension for the first time; no previous experience. The extension I have in mind must be able to look at a user's browsing history and provide the URL of the earliest instance they visited a certain website, or any subdirectory within that website.

For example, a user's browsing history could be:

8:58 - http://mysite.com/page/page1.html
8:59 - http://mysite.com/test/index.php
9:00 - http://google.com
9:01 - http://google.com/?q=mysite
9:03 - http://mysite.com/this/info.html
9:04 - http://mysite.com/this/info2.html
9:05 - http://mysite.com/this/info3.html
9:06 - http://facebook.com

In this case, let's say the app is looking for instances of visiting http://mysite.com or any subdirectory. (This would be specified in the extension code itself; it's not set by the user.) The extension will look for the most recent "group" of visits to http://mysite.com, which is in this case:

9:03 - http://mysite.com/this/info.html
9:04 - http://mysite.com/this/info2.html
9:05 - http://mysite.com/this/info3.html

From this group, it will pick the earliest of the entries, and display that URL, which in this case is:

9:03 - http://mysite.com/this/info.html

Been looking at Google's documentation on working with History in extensions (http://developer.chrome.com/extensions/history.html), but I don't think what I'm looking for is on that documentation page...

Wondering if anyone could give me a push in the right direction?

Thanks!


Solution

  • Any history function available to your extension are listed here: http://developer.chrome.com/extensions/history.html

    If they aren't you won't be able to access them. There isn't an undocumented history API for chrome extensions.

    You'd probably want to do something like this:

    var siteToSearch = 'facebook.com';
    chrome.history.search({text: siteToSearch, callback: function(results) {
        //Iterate through the `results` array of `HistoryItem` objects
        //Look for lowest value of `lastVisitTime` OR call `chrome.history.getVisits` with
        //`results[i].url` and then check the returned `VisitItem` for the `visitTime` property
    }})
    

    You might want to use a regular expression for matching the URL of the site you are searching for with the result in the browsers history.