Conflicts with browser shortcuts

Is there a way to override the browser shortcuts, in particular ctrl-w? Ctrl-w closes the tab which closes VS code completely, rather than closing the one tab in VS Code. That’ll be a hard one to stop using.


I just did a quick search and I found this (I assume you mean Virtual Studio Code?)

I’m not looking for vs code bindings, I’m wondering if it’s possible to override browser bindings (per the question).

Ctrl+w is not a shortcut browsers allow to override. :frowning:

If you go into full screen mode (Run the VS Code Toggle Full Screen command or press F11), then you can use Ctrl+w (and other browser blocked shortcuts) and it will work as expected.


That’s a good tip, but if a user is in full screen mode and casually tries to close an editor tab, it’s still super painful to accidentally close the whole session, especially since it can take a bit for the page/session to reload. I think trying to give a warning before closing the whole editor might be helpful.

Unfortunately, it doesn’t even get to the JavaScript handler - potentially intentionally for security reasons and run away scripts since this is one of the only ways to shut down something that’s going crazy.

Seems like a feature the chrome devs could add to allow specific sites to override ctrl-w, kind of like you can allow extensions to only work on specific sites.

Appears you can at least warn users before closing based on this issue:

While not great, would be a lot better than closing with no warning.


The other way around: If you hit ctrl+shfit+b (in Edge) it doesn’t hide the favorites bar but opens the build task. There’s not way to switch context other than opening a new tab.

Actually, I tried it (and it may be only in Edge beta) but it hid the favorites.
Here, anyone who reads this, please try doing it and putting results here:

What happened

  • Closed favorites
  • Opened build mode
  • Something else

0 voters

For me, ctrl+w is prominently used to delete unix word in terminal. I don’t see myself ever changing that habbit.

Just to clarify - you will not see these issues if you are using VS Code itself to connect to your Codespace via the Codespaces extension. On the web there are some key bindings we may not be able to change, but you can continue to use the keybindings you’re familiar with from VS Code client. (We also plan to add the ability to create a Codespace from VS Code as well if you prefer that workflow.)

Could you clarify here what you mean? Are you saying there’s a technical limitation that makes it either difficult or impossible to catch the Ctrl+W with beforeunload?

1 Like

I ran across this same issue attempting to use Ctrl+Shift+P to open the Command Palette - a shortcut that, in Firefox, opens a new “Private Browsing” window!

Is that’s the case, would a potential work-around be to provide an alternative default preset for keybindings that are compatible with (i.e. work around) supported browsers? I imagine, though, that the list that require changing would be monumental.

I feel like this should be something discussed with the Chrome and Firefox teams to allow specific sites to override these types of things, otherwise this browser based experience just can’t match a desktop installed app.

Chrome has this for extensions already so it doesn’t seem too far fetched to be able to allow certain sites to override special shortcuts. Extensions have this:

Screenshot 2020-09-03 at 9.16.38 AM

Agree! I keep hitting CMD + w too!!

I wrote a UserScript


  window.addEventListener('beforeunload', function (e) {
    e.returnValue = 'Are you sure?';
1 Like

So the downside with doing this, is that it would appear all the time - we can’t just do it for Ctrl+W.

However, you can actually get all your key bindings including Cmd/Ctrl+W by installing GitHub as a “Progressive Web App” using Chrome. Here’s how:

  1. In Chrome, go to (or any URL under it)
  2. Click on the “…” in the upper right corner
  3. Select More Tools > Create a Shortcut…
  4. In the dialog that appears, check “Open as Window”
  5. Click “Create”

You can now pin this app to your start menu / dock. When you’re using this app, you should have all keybindings.

Edit: Forgot to mention, on Edge this is under “…” > Apps… > Install this site as an app


Ahh, brilliant. That works great… but looks like you’d need to do it for every different codespace instance? Which means every repo.

The good news is you can add a shortcut as described above and then any Codespace will work.

EDIT: I should also note that we’re working on allowing you to install as a PWA without the shortcut method which will make this a bit easier (e.g. there would be a + icon in the address bar).