Search code examples
google-chrome-extensionbrowser-history

Count urls in chrome browser history that were visited via google search


Is it possible to use Chrome History API to count the number of URLs in the history that were visited using google search engine?

For each visited URL, Chrome History API provides a VisitItem object which can be used to access the visit id of the referrer (referringVisitId attribute). https://developer.chrome.com/extensions/history#type-VisitItem

If the URL (say https://en.wikipedia.org/wiki/java) is visited (clicked) from google search results, then the value of referringVisitId is always 0 when it should be the visit id of google search results URL. Why is the value of referringVisitId 0 in this case? What is the purpose of referringVisitId attribute?


Solution

  • The Chrome History API does not provide list of visited url on basis of the referrer. Infact it provides referringVisitId, but not always.

    I did a test and found that the Chrome History API will provide a referringVisitId ony if the url is visited in the same tab using an anchor tag inside the referring webpage. Other wise the referringVisitId will always be 0. See below the screen-shot.

    enter image description here

    Here is my test code I used grab the history forhttps://en.wikipedia.org/wiki/Java_(programming_language) url:

      chrome.history.getVisits({"url":"https://en.wikipedia.org/wiki/Java_(programming_language)"}, function(details){
          console.log(details);
      });
    

    Separately, If you are trying to build a solution only for Google. I would suggest you to do this using a content-script instead of using Chrome History API. Because, I think it won't fulfill your requirement of grabbing all the links visited through the Google.