Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Chrome extension determine if the user clicked the browser's Back or Forward button

How can I know whether the user clicked back/forward button in Chrome from within my Chrome Extension?

The only API that could give me any such info is the chrome.webNavigation.onCommitted which in the case of when the back or forward button are clicked, sends a NavigationQualifier containing the string 'forward_back'. The problem here is that I'm not able to distinguish between the two buttons.

like image 604
georgehdd Avatar asked Nov 11 '22 02:11

georgehdd


1 Answers

You could use the tabs API's onUpdated event if that's good enough for you.

Alternatively, you could use the HTML5 history API and register a window.onpopstate handler. Do that from within a content script that runs before the page.

like image 131
Nitzan Shaked Avatar answered Nov 14 '22 21:11

Nitzan Shaked