how do I prevent github hijacking my browser back button?

159 views Asked by At

I'm using firefox.

Now I am back at an empty tab, instead of the main code page.

It is very annoying.

How can I either entirely prevent github (and other sites) overriding my browser back button, or implement a workaround when they do?

2

There are 2 answers

0
jhnc On

Despite the back button not working, the history stack seems to be unchanged. Executing history.go(-1) in the console works, so I wrote a greasemonkey script to bind new hotkeys (Shift Ctrl [, Shift Ctrl ]):

(function(){
document.addEventListener('keyup', function(e) {
  if (e.ctrlKey && e.shiftKey && !e.altKey && !e.metaKey) {
    switch (e.keyCode) {
        
      case 219: // [
        history.go(-1);
        break;
        
      case 221: // ]
        history.go(1);
        break;
        
      default:
        break;        
    }
  }
}, false);
})();

Still hoping there is a way to make the back button work directly.

1
jhnc On

After much experimenting, I found this non-default config setting:

browser.navigation.requireUserInteraction = true

which led me to this relevant bug report:

I have no recollection of setting that option but resetting it to default (false) immediately made the location history reappear when right-clicking the back button.


It's slightly odd that only github was affected (but I can see they use javascript that mentions things like "poping a state from the history stack" and "prevent our state from getting out of sync with the browser's history stack", so ...).

Thanks to @0stone0 for pointing me in the right direction.