For the author's stated use-cases, it would be easier to do this via. a chrome extension. Relevant documentation: https://developer.chrome.com/docs/extensions/reference/histo...
Interesting note: the visits.visit_duration column is not exposed through this API (or at least - not listed in the documentation). This may be because it's apparently misleading. (It apparently captures the time the tab was open not the time the tab was active)
Hope this helps