Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect browser "back" input for Chrome extension

I want to make a chrome extension which performs a certain action when the user enters the a "back" navigation action.

ie: they click the back button in the browser, or they swipe backwards with 3 fingers on a macbook pro, or if they enter the shortcut alt + left arrow.

How can I detect these actions? Should I create some type of listener or handler which accounts for each one individually?

like image 470
Dan Q Avatar asked May 01 '26 03:05

Dan Q


1 Answers

You can use the webNavigation API.

Start monitoring the details for each transition type that you mentioned. And then try to do something with this information.

chrome.experimental.webNavigation.onCommitted(function(details){
    console.log(details);
});
like image 130
kbtz Avatar answered May 05 '26 08:05

kbtz