georgehdd
georgehdd

Reputation: 433

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.

Upvotes: 7

Views: 1107

Answers (1)

Nitzan Shaked
Nitzan Shaked

Reputation: 13598

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.

Upvotes: 1

Related Questions