Home Assistant Community Add-on: Visual Studio Code

I have the same issue unfortunately. Even the window reload doesn’t help sometimes. Here is the error log from the browser console (Chrome 85):

(index):1 Uncaught (in promise) DOMException: Failed to register a ServiceWorker for scope ('https://xxxx.duckdns.org/api/hassio_ingress/tLsREKFrBAHTW9rOUo4TlM88elm09dCno4x_-jra0jA') with script ('https://xxxx.duckdns.org/api/hassio_ingress/tLsREKFrBAHTW9rOUo4TlM88elm09dCno4x_-jra0jA/static/de41646fc402b968ca6d666fdf2da7de9554d28a/usr/local/lib/code-server/dist/serviceWorker.js'): The path of the provided scope ('/api/hassio_ingress/tLsREKFrBAHTW9rOUo4TlM88elm09dCno4x_-jra0jA') is not under the max scope allowed (set by Service-Worker-Allowed: '/api/hassio_ingress/tLsREKFrBAHTW9rOUo4TlM88elm09dCno4x_-jra0jA/'). Adjust the scope, move the Service Worker script, or use the Service-Worker-Allowed HTTP header to allow the scope.

Is there a way to connect to the code server from a desktop VSCode installation? Or does the development have to be in the browser for this add-on?

It is great either way I was just thinking that keyboard shortcuts might be more reliable in the desktop version in case there are any conflicts with the browser shortcuts.

3 Likes

After spending two evenings, I gave up, registered here and need the wisdom of the crowd.

Setup: Intel Nuc with x86 J5005, Official HASS Nuc Image with supervisor, pretty much just installed everything. No SLL certificates setup.

Steps to reproduce:

  1. Install latest VS Code Community addon
  2. Fill in ip (192.168.1.4:8123) or mDNS (homeassistant2:8123); check box for unsecure connections; enter valid access token

Expected:

  1. VS code starts
  2. File access possible
  3. The HomeAssistant VS Code Helper can connect to HASS and show e.g. auto completion

Experienced:

  1. VS code starts
  2. File access possible
  3. The HomeAssistant VS Code Helper cannot connect to HASS and does show e.g. auto completion. Error is always: Error connecting to your Home Assistant Server at http://192.168.1.4:8123 and token 'eyJ0e...', check your network or update your VS Code Settings, make sure to (also) check your workspace settings! Error: ERR_CANNOT_CONNECT

I reinstalled several times, tried FireFox and Chrome. Never got it to work. I tried new tokens, etc. all.

I even tried the test application in the thread (rather at the beginning). It uses the user/password login, but other than that, it shows my entities.

No error in the VS Code Logs.

Any idea where to start?

Log

[s6-init] making user provided files available at /var/run/s6/etc…exited 0.
[s6-init] ensuring user provided files have correct perms…exited 0.
[fix-attrs.d] applying ownership & permissions fixes…
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts…
[cont-init.d] 00-banner.sh: executing…

Add-on: Visual Studio Code
Fully featured VSCode experience, to edit your HA config in the browser, including auto-completion!

Add-on version: 2.8.0
You are running the latest version of this add-on.
System: HassOS 4.13 (amd64 / intel-nuc)
Home Assistant Core: 0.116.0
Home Assistant Supervisor: 247

Please, share the above information when looking for help
or support in, e.g., GitHub, forums or the Discord chat.

[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing…
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] code-server.sh: executing…
[cont-init.d] code-server.sh: exited 0.
[cont-init.d] mosquitto.sh: executing…
[cont-init.d] mosquitto.sh: exited 0.
[cont-init.d] mysql.sh: executing…
[cont-init.d] mysql.sh: exited 0.
[cont-init.d] user.sh: executing…
[cont-init.d] user.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[21:20:42] INFO: Starting the code server…
[2020-10-08T19:20:43.234Z] info Wrote default config file to ~/.config/code-server/config.yaml
[2020-10-08T19:20:43.236Z] info Using config file ~/.config/code-server/config.yaml
[2020-10-08T19:20:43.543Z] info Using user-data-dir /data/vscode
[2020-10-08T19:20:43.548Z] info code-server 3.5.0 de41646fc402b968ca6d555fdf2da7de9554d28a
[2020-10-08T19:20:43.554Z] info HTTP server listening on http://0.0.0.0:1337
[2020-10-08T19:20:43.554Z] info - No authentication
[2020-10-08T19:20:43.554Z] info - Not serving HTTPS

These steps worked for me:

Sorry if the question is dumb, but it seems this extension “grabs” the yaml association somehow.
Each and every vscode projects with yaml files show them associated with HA.

How do I limit the association to the one workspace where I actually need it?

EDIT: Dumb indeed. Just found out you can enable/disable extensions per workspace

Running latest vscode and HA and supervisor, but still getting the “reload the window” messages. Is this solved for others ( I saw the github ticket is closed)

I can’t seem to get pylint working. I ssh’d into my HA instance and ran pip install pylint and verified it being installed; opened up VS Code and it can’t find the install. Is it possible to do this?

No, I still have the issue.

Does anyone know why this add on is not available on my system? Its a Pi4.

You’re probably not running a 64bit O/S

Ah, yep, it’s 32 bit. That makes perfect sense. Thank you!

1 Like

So is this coming for a future update?

I have Problem installing / using Visual Studio Code add-on

I have installed Home Assistant 64-bits version on RPi 4 B 4GB.

I have already installed several add-ons including “Duck DNS” as well as “NGIX SSL proxy”. I am now trying to install “Visual Studio Code” add-on. I log on the HA system using my_domain.duckdns.org

I click on install and after a long time I get a pop-up window with this message:

<html> <head><title>504 Gateway Time-out</title></head> <body> <center><h1>504 Gateway Time-out</h1></center> <hr><center>nginx/1.16.1</center> </body> </html> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page -->

I click OK, then I click on Install again, and it install instantly. I check “show in sidebar” and start the add-on

The log file

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing...
-----------------------------------------------------------
 Add-on: Visual Studio Code
 Fully featured VSCode experience, to edit your HA config in the browser, including auto-completion!
-----------------------------------------------------------
 Add-on version: 2.8.2
 You are running the latest version of this add-on.
 System: HassOS 4.15 (aarch64 / raspberrypi4-64)
 Home Assistant Core: 0.117.1
 Home Assistant Supervisor: 2020.10.0
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing...
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] code-server.sh: executing...
[cont-init.d] code-server.sh: exited 0.
[cont-init.d] mosquitto.sh: executing...
[cont-init.d] mosquitto.sh: exited 0.
[cont-init.d] mysql.sh: executing...
[cont-init.d] mysql.sh: exited 0.
[cont-init.d] user.sh: executing...
[cont-init.d] user.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[11:34:46] INFO: Starting the code server...
[2020-11-01T10:34:46.987Z] info Wrote default config file to ~/.config/code-server/config.yaml
[2020-11-01T10:34:47.846Z] info Using user-data-dir /data/vscode
[2020-11-01T10:34:47.860Z] info code-server 3.6.0 a4a03c14922ccaec2a9ff8d1b7b2af8522a4214d
[2020-11-01T10:34:47.861Z] info Using config file ~/.config/code-server/config.yaml
[2020-11-01T10:34:47.873Z] info HTTP server listening on http://0.0.0.0:1337
[2020-11-01T10:34:47.874Z] info - No authentication
[2020-11-01T10:34:47.874Z] info - Not serving HTTPS

The first time I go the Visual studio panel nothing is displayed. I go to another panel and back to VSCode panel and now I can see a Welcome screen but after sometime, I get a window that indicates: “Cannot reconnect. Please reload the window”. I click “reload window” and it works but I very often get the same error window and I have to reload again and again.

Anybody has an idea what is the problem and how to fiw it because like this it is a pain to use;

Note: I have tested on a VM without Duck DNS and NGINX and it woks perfectly.
Note2: When accessing HA serveur using http I get the following message “code-server is being accessed over an insecure domain. Web views, the clipboard, and other functionality will not work as expected.”. Does that means that VSCode add-on only works correctly when HA is accessed with https ?

Actually it seems that the problem is caused by NGINX.

With the NGINX addon installed I had the same exact problem to install the VS Code add-on as well as the Unifi Controller add-on.

Therefore I have uninstalled the NGINX add-on and modified the configuration.yaml to specify the ssl key and certificate and now both VS Code and Unifi controller are working fine.

I guess I have therefore to report the problem to NGINX add-on

1 Like

In the past I have always used a simple drag and drop to upload files from my PC to HA via this add-on, which works really well.
I’m trying to use the HA app on my Android phone connected to a monitor so I have a big enough screen to used VSC but I can’t use that drag/ drop functionality as it simply doesn’t work. Is there a way to somehow upload files from my phone? I can’t seem to find anything in the menu’s.

This is a long shot but did you enter your host url and your long live token under settings-Extensions-homeassistant config-helper in vscode? That looks like my log when I first installed it on my system

Moreover, make sure you carefully copy the whole token. (I wasted about half an hour yesterday)
And the URL needs to be: https://ip:port (be careful of white-space - another 10 minutes wasted)

1 Like

First thanks to both of you.

As I said in my last post, since I have removed the NGINX add-on I do not see the problem anymore but I have tried your modifications

In User I have created a long-lived access token with the name of VSCode and I made a copy of the token

I clicked on the cog-wheel -> settings -> search config-helper. Clicked on the cog wheel of HA config helper and selected extension settings. Here I have a page with three tabs: User, Remote, and Workspace that looks like what you’re are taking about?

I first modified the User tab: in Host URL = https://my_local_ip:8123, I have checked Enable insecure transport, and I have entered the access token. After that, I was getting the following error message:

(node:2667)[DEPO123] Deprecation warning: Setting the TLS ServerName to an IP address is not permitted by RFC 6066. This will be ignored in future version

I have therefore changed Host URL to https://my_domain.duckdns.org, and uncheck Enable insecure transport and after that it seems to work.

But

What is the benefit of entering this information if it works without these settings?

The usage of the three tabs is confusing if I modify info in User it also modify in Remote but not in Workspace?

If I remove information from User and Remote and if I place this info in Workspace the info seems to apply to the three tab?

At the end, I removed everything I added!

VScode_reconnect
Anyone have the solution to the reconnect issue?
Running duckdns with port forwarding to the server.
Reading the documentation there isn’t any other configuration for the add-on to build in long live token or anything. The issue consistent with few successful connections to remote host. Love VS code and use it for work and hobbies.

Thanks in advance!

I don’t recall the actual error but VScode was throwing an error related to this entry once I entered it it showed green as good and no longer received the error and I also used my duckdns url and that did it