API to fetch visits by multiple urls

Hi all, as I’m trying to port an old extension to webextension, I’m looking for a way to query for visits with multiple urls.

The only way I found is History.getVisits, but as I understand it takes only one url. In my case that means, after searching for keywords to get N HistoryItem, I need to call History.getVisits N times to get all the related visits with each HistoryItem. May I ask if there’re alternative ways to query browsing history in WebExtension?

Thanks!

You can use history.search() to get all history items and then use a normal loop to look for the desired items.

text
string. Specifies a free-text query to the history service. Specify an empty string ("") to retrieve all history.HistoryItem objects that meet all the other criteria.

Thanks for replying. Actually I used history.search() before history.getVisits, similarly as example here. In fact my approach may be similar as yours in Historia, especially the part of “query all HistoryItem using a keyword, and then fetch all the VisitItem associated with each HistoryItem”.

The main problem in my case is, in addition to querying the VisitItems associated with the keyword, I need to get all the referrer visits and all of their descendants in order to display the browsing history in “threads”, based on the clickstream. As I didn’t see any API to query VisitItem by VisitIDs, or query VisitItem by their referrer’s visitID, I actually carried out a generic search (with empty keyword) to pull all the HistoryItems within a period (like within a month), and then construct the threads by walking through all of them and checking referringVisitId. With my own browsing history, I had 4k+ HistoryItems within last month, and fetching VisitItems for all of them will take 5+ seconds.

History searches has been slow for ages, especially for a large database. There isn’t any API at the moment to get what you want. The other option, as mentioned, is to get all and walk through them,

Thanks again. In current live version, I used nsPIPlacesDatabase to run raw sql queries to achieve this. I suppose I’ll resort to caching and/or pre-fetch as plan B.