Troubleshoot : XHR Failed on VSCode

Do you want to fix XHR Failed error in VSCode?

At its heart, VSCode is based on the Electron framework. That means VSCode is basically a Chromium with code editing features developed on top of it. Whenever you get an error from VSCode, it's most likely Chromium errors.

Users have reported that when they try to install an extension, especially behind a proxy network, they are presented with XHR Failed error. XHR Failed indicates that a few XHR requests may have been failed or interrupted while VSCode sends and receives extension information from the server.

In this article, we will discuss about possible fix for XHR Failed error in VSCode.

image-20210531161703991

Use a direct internet connection

If you're behind a proxy network, try to disable it if you can.

Most of the time, the proxy network includes a firewall that may block VSCode requests to its servers.

In rare cases, the proxy network supports only HTTP or HTTPS protocol, leaving other communication through its network blocked, which can causes strange behavior in VSCode.

You can follow the instructions from Microsoft Forum to disable proxy on Windows 10. macOS users can consult this guide to do just that. Linux users should be able to disable proxy on their own, given that they are often more tech-savvy, but here's a few tips on how to turn off proxy in Linux anyway.

Turn on automatic proxy detection

Chromium uses system proxy settings by default, so there's a chance VSCode's Chromium core does not recognize the proxy and cannot send/receive network data.

In order to turn on automatic proxy detection on Windows 10, follow HowToGeek guide.

automatic proxy detection Windows

Ignore certificate errors in VSCode

The actual implementation of the corporate proxy can vary from organization to organization, but there is one thing in common : they could all cause certificate errors.

Secure websites and applications use their own certificate to prevent themselves from online attacks. Internet traffic going through a corporate proxy can be modified by the proxy network in real time, causing certificate irregularities. Some other times, your organization offers their own CA certificate, which makes the situation even more complex.

You can try launching VSCode with --ignore-certificate-errors flag to disable strict certificate checking.

On Windows, the easiest way to do this is by running code.exe --ignore-certificate-errors from a Command Prompt window.

On Linux and macOS, you have to open Terminal app and run code --ignore-certificate-errors.

After that, try installing the extensions again to see whether the error message goes away.

Disable JS source maps

Source maps is basically a JavaScript engine feature that maps a combined/minified file back to an unbuilt state (think unminify). It was made for easier JavaScript debugging, but we don't need to debug VSCode itself, so disabling it is safe. Plus, users have reported that disabling JavaScript source maps and CSS source maps solves XHR Failed error message .

In order to disable JavaScript source maps and CSS source maps in VSCode, fire up Command Palette and search for Developer: Toggle Shared Process.

image-20210531154850224

On Developer Tools that just pops up, click the Gear button (settings button) in the upper right corner.

image-20210531155130985

Uncheck Enable JavaScript source maps and Enable CSS source maps, then close the window.

image-20210531155245439

Change your DNS

If you live in a country where heavy internet censorship is implemented, such as China, Egypt or Turkey, maybe the firewall has blocked some Microsoft servers. You can try setting your DNS to Google DNS (8.8.8.8) or Cloudflare's 1.1.1.1 servers to see if XHR Failed happens again or not. On Windows, you may have to run ipconfig /flushdns to flush the system's DNS cache before changing the DNS.

Change-Windows-DNS-servers-to-Cloudflare-1.1.1.1

On Linux machines, you have to edit /etc/resolvconf/resolv.conf.d/base to make DNS changes persistent through restarts. Add these two lines to the file before rebooting so that the changes take effect.

nameserver 1.1.1.1
nameserver 1.0.0.1

Install the extension offline using VSIX file

All VSCode extensions is now available in the form of VSIX-packaged files. This allows for offline installation as well as extensions which are not originated from VSCode Marketplace.

You can download VSIX files directly from VSCode Marketplace or Open VSX Registry and install it offline, without the need for an internet connection. See our guide on How to install extensions in VSCode for detailed installation steps.

We hope that this article helps you solve the XHR Failed error in VSCode. VSCode is an awesome code editor, equipped with numerous features that supports developers. Here's a few of them that we've covered, if you're interested :

Click to rate this post!
[Total: 17 Average: 5]

Leave a Comment