3

For now, I've only found a way to listen to "reload" event using:

chrome.webNavigation.onCommitted.addListener(function(details) {
  if (details.frameId == 0) {
    if (details.transitionType == "reload") {
      // do something
    }
  }
});

What about "go back" and "go next" events? I'm looking for a Firefox's nsISHistoryListener alternative in Chrome.

Edit: Submitted a feature request to Chromium.

Michael Spector
  • 36,723
  • 6
  • 60
  • 88

1 Answers1

0

You could use the window.beforeunload event to capture when a user intends to navigate to another page (which would be triggered when using the back and forward buttons).

window.onbeforeunload = function () {
    // do something
};

There is no way to get the target destination when using onbeforeunload.

More info here: Is there a cross-browser onload event when clicking the back button?

Community
  • 1
  • 1
Adam Ayres
  • 8,732
  • 1
  • 32
  • 25