Macos – How to prevent command-arrow keys from navigating macOS Chrome forward/backward

google-chromekeyboard shortcutsmacos

On macOS, I commonly use the commandleft arrow or commandright arrow shortcuts to move the cursor to the start or end of text.

Unfortunately, if I do this in Chrome desktop web browser app, and the keyboard focus accidentally escapes whatever text field, then the browser will navigate forward or backward in history.

I only expect command[ or command] keyboard shortcuts to navigate history.

What's the simplest (preferably avoiding third-party apps) way to do this (something in chrome://, perhaps)?

Best Answer

If you have access to the code, you can trap the key shortcut for the page:

document.addEventListener("keydown", function(e) {
  if ( ( e.metaKey || e.ctrlKey )
      && e.keyCode == 37 ) // left arrow key.
  {
         e.preventDefault();
  }
}, false);