OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How do I detect if the user goes back or forward through the history in the current tab? [duplicate]

  • Thread starter Thread starter terrorrussia-keeps-killing
  • Start date Start date
T

terrorrussia-keeps-killing

Guest
I'm going to implement a simple web extension for my personal needs (currently for Chrome, but I consider moving to Firefox and abandon the former), and this extension only requires the history and tabs permissions. What I'm looking for is a way to detect if I move forward or back within the current tab.

In short, I want to build a stack per tab, and push an element to it or pop an element from it on moving forward (including navigation to a non-history element that's also considered a move forward) or back respectively.

From what I've seen in the documentation for both Chrome and Firefox, the closest methods and events I could find are the following:

  • chrome.tabs.goForward and chrome.tabs.goBack: these are just methods, not events, but trigger the below events;
  • chrome.history.onVisited: an event, provides neither the direction, back or forward, nor the tab ID;
  • chrome.tabs.onUpdated: the event that seems to be the most relevant to what I'm looking for, it also provides both status: "loading" and url via the changeInfo callback parameter, but still there doesn't seem any flag that indicates the direction.

None of them do exactly what I want. Is there any way to detect the direction?

The extension is planned to use Manifest v3 if it matters but I'm really okay to use Manifest v2 and Firefox.

<p>I'm going to implement a simple web extension for my personal needs (currently for Chrome, but I consider moving to Firefox and abandon the former), and this extension only requires the <code>history</code> and <code>tabs</code> permissions. What I'm looking for is a way to detect if I move forward or back within the current tab.</p>
<p>In short, I want to build a stack per tab, and push an element to it or pop an element from it on moving forward (including navigation to a non-history element that's also considered a move forward) or back respectively.</p>
<p>From what I've seen in the documentation for both Chrome and Firefox, the closest methods and events I could find are the following:</p>
<ul>
<li><code>chrome.tabs.goForward</code> and <code>chrome.tabs.goBack</code>: these are just methods, not events, but trigger the below events;</li>
<li><code>chrome.history.onVisited</code>: an event, provides neither the direction, back or forward, nor the tab ID;</li>
<li><code>chrome.tabs.onUpdated</code>: the event that seems to be the most relevant to what I'm looking for, it also provides both <code>status: "loading"</code> and <code>url</code> via the <code>changeInfo</code> callback parameter, but still there doesn't seem any flag that indicates the direction.</li>
</ul>
<p>None of them do exactly what I want. Is there any way to detect the direction?</p>
<p>The extension is planned to use Manifest v3 if it matters but I'm really okay to use Manifest v2 and Firefox.</p>
 

Latest posts

Top