0

I'm trying to develop a chrome extension which will capture http packets, their source and destination URLS, the packet size. Basically I want to know how much time the user spends on a particular site for the duration the browser is active.

I used JNetPcap and successfully have written a java code for the same but i cant find a way to implement the browser close event in Java. Also chrome extensions need to be in javascript. Can anyone suggest a way to go about this?

1 Answers1

0

Your initial approach is flawed to begin with. What do you mean by "time spent on a site"? The page loads, packets cease to flow, yet the user is still reading the page. Just network analysis is hardly a good metric.

And what about external resources? Do your users "spend time" on Google Analytics website when trackers make their requests?

If you are dead-set on network capture, chrome.webRequest or chrome.webNavigation APIs should let you tap into requests made by the client.


As for implementing this properly as a Chrome extension, it should be trivial. You can use chrome.tabs API to keep track of open/active tabs.

  1. Declare "tabs" permission to get access to URL data
  2. On initialization, query current tabs (or just the active tab)
  3. Listen to onCreated for new tabs, or better yet for onActivated for change of visible tab (possibly do so with windows too, there's a separate API for that)
  4. Within the active tab, track URL changes with onUpdated

If you're new to extension development, start with the Overview. Good read, and a good hub to other documentation.

As for recommending JavaScript resources, I'll pass; too many of them.

Xan
  • 74,770
  • 16
  • 179
  • 206
  • Ill try and rephrase it. By "time spent" i mean, the data usage the website makes. I guess there's a problem in the question. – user3702425 Jun 03 '14 at 19:28