4

I want to get the history based on tabs not the global history.

  • I have tried the chrome.history but it is a global history API and it is not giving the tab specific history
  • Following the thread I checked chrome.webNavigation API but it was just giving the frames of that particular page not the history.

So what is the better way for achieving this?

Salman Arshad
  • 343
  • 6
  • 23
  • There's no dedicated API for this so you'll have to monitor the navigation history of every tab yourself. For example you can use chrome.tabs.onUpdated listener that writes and updates a global variable (object or `Map`) with key that is tab id and value is tab URL. – wOxxOm Aug 12 '18 at 13:33
  • @wOxxOm I am using that listener for tab updates but I also want the history of each tab when my extension is activated or installed – Salman Arshad Aug 12 '18 at 13:39
  • You can only monitor the history while your extension is active. – wOxxOm Aug 12 '18 at 13:41
  • @wOxxOm this is incorrect, see my answer below – éclairevoyant Aug 02 '21 at 19:01
  • @éclairevoyant, my comments are correct, but I gave just one example. You apparently misunderstood what I meant. My comment doesn't say the history can be accessed from the background script. It says the URL can be observed by the extension so it can build the history from that. – wOxxOm Aug 02 '21 at 19:20
  • your comment said "there's no dedicated API for this" which is untrue. trying to build the history manually via listeners is really the wrong way to go about this when there is already a session history API. – éclairevoyant Aug 02 '21 at 20:54

1 Answers1

-1

The history API you're referring is the browser history API. However, you're looking for the browser session history API (session meaning per-tab). Since this is a DOM-based API, you can only access this via content scripts. This cannot be used directly from service workers or background scripts, but of course you can use messaging if needed to indirectly access this.

éclairevoyant
  • 392
  • 2
  • 15