Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome.History get referring URL (JS)

I would like to write a chrome extension which not only lists the URLs visited in the History, but the referring URLs as well. For example, if I clicked on Wikipedia from Google, it should say "Wikipedia: referred to by Google".

My initial attempt was to take a HistoryItem for the URL in question, extract its most recent VisitItem, and then use referringVisitId to track down the initial URL, however this is where I got stuck. My problem comes down to not understanding the meaning of referringVisitId. Is it the ID of the history item which opened the new page? Is it the ID of the VisitItem initiated by the URL click? The documentation states that it is the "visit ID of the referrer", however this still leaves me puzzled.

1) What is the meaning of referringVisitId?

2) Can I use referringVisitId to track down the referring URL? If so, how?

Thank you for your time!

like image 487
Sergiy Avatar asked Jun 27 '13 16:06

Sergiy


1 Answers

  1. referringVisitId seems to be the ID of the VistItem which led to the current VisitItem.

  2. It looks like it isn't possible to query for a VisitItem using only it's ID. Or try to get the HistoryItem that the VisitItem belongs to.

The next best thing would be to try using the onCreated and onUpdated event together to try to track the last tab the user was in.

This also has it's flaws though, if a new tab is opened using window.open while you are in another tab, you would get the wrong referrer. Unless you tried to intercept all calls to window.open.

TL;DR: It's not easy to get the tab that opened the current tab.

like image 192
samfundev Avatar answered Oct 09 '22 04:10

samfundev