code-server
code-server copied to clipboard
[Bug]: Image not showing up
Is there an existing issue for this?
- [X] I have searched the existing issues
OS/Web Information
- Web Browser: Brave
- Local OS: MacOS Monterey
- Remote OS: debian
- Remote Architecture: amd54
-
code-server --version
: 4.0.1 735c6da829535969ff7193c79379299e4a1cb9bc
Steps to Reproduce
- run code-server --bind-addr 0.0.0.0:443 --cert -- /app
- Connect to the address
- Click an image
Expected
Image should be shown in editor
Actual
An SSL certificate error occurred when fetching the script. log.ts:313 ERR [Service Worker] registration DOMException: Failed to register a ServiceWorker for scope ('https://--server--/') with script ('https://--server--/service-worker.js'): An SSL certificate error occurred when fetching the script.
Logs
No response
Screenshot/Video
No response
Does this issue happen in VS Code?
- [X] I cannot reproduce this in VS Code.
Are you accessing code-server over HTTPS?
- [X] I am using HTTPS.
Notes
Please note i'm running it in docker but 443 is exposed (via 8080 in my case).
This is a re-opening of https://github.com/coder/code-server/issues/4658
Additionally "Cannot reconnect. Please reload the window." pops up after some minutes... that's probably related.
I was able to reproduce this locally on macOS + Brave with code-server --bind-addr 0.0.0.0:443 --cert
Error loading webview: Error: Could not register service workers: SecurityError:
Failed to register a ServiceWorker for scope ('https://localhost/webview/6659afd9-08e4-4b14-9528-570c9d7107cc/') with script
('https://localhost/webview/6659afd9-08e4-4b14-9528-570c9d7107cc/service-worker.js?id=a8c6338a-43f4-450a-a373-44c7b0e0d34a&swVersion=2&extensionId=&platform=browser&vscode-resource-base-authority=vscode-resource.vscode-webview.net&parentOrigin=https%3A%2F%2Flocalhost'):
An SSL certificate error occurred when fetching the script..
@code-asher any ideas on where to troubleshoot the cause of this? I haven't spent much time generating SSL certificates locally before. I wonder what broke there.
In the meantime, you can use version 3.9.1 if you really have to display images:
docker pull codercom/code-server:3.9.1
Seems likely to be the same issue as https://github.com/coder/code-server/issues/4693#issuecomment-1009039212
I updated to version 4.0.2 and this issue seems to be fixed!
Still not working for me. I have the following setup:
docker-compose.yml:
vscode:
image: codercom/code-server:4.0.2
ports:
- "8080:8080"
volumes:
- ../:/desk/
- ./:/home/coder/.config/code-server/
restart: always
user: "1000:1000"
config.yaml:
bind-addr: 127.0.0.1:8080
auth: password
password: 1234
cert: false
I access it using a tunnel (Ngrok)
I realised that it did work when docker was running on the same machine, but not when code server was on another machine. Reopening.
I tried the same Dockerfile on two machines, localhost and another. My browser (Brave Browser) one time shows an exclamation mark with a circle around it (localhost) and on the remote machine it shows an exclamation mark with a triangle around it (for "connection security" next to the URL). On localhost the image is shown, from the remote host it isn't.
Maybe this message in console is a hint:
Uncaught (in promise) Error: Service Workers are not enabled. Webviews will not work. Try disabling private/incognito mode.
at :8180/webview/1e6c8813-ba31-4e1f-bb46-d48f13a2b8b2/main.js:115:83
at new Promise (<anonymous>)
at :8180/webview/1e6c8813-ba31-4e1f-bb46-d48f13a2b8b2/main.js:115:23
I don't see this on localhost.
Creating an ssh tunnel ssh -L ... to the remote server showed, that the image does show as soon as the address is "http://localhost...".
Note: Disabling private/incognito mode was not possible (my browser wasn't in incognito mode) and even disabling "Brave Shields" didn't help. I was able to reproduce this with Safari, it's just the same, localhost works, remote doesn't.
I'm running code-server inside docker, it is code-server-4.0.2-linux-amd64.tar.gz
started with CMD ~/.local/bin/code-server --bind-addr 0.0.0.0:8080 /app
, accessing it via http.
accessing it via http.
Images are rendered in webviews. Webviews use Service Workers. Browsers require HTTPS to enable Service Workers. Therefore, this isn't a bug in code-server since it's not something we can change :(
The only solution I can offer is to use HTTPS
But why does it work on localhost? Maybe browsers don't block Service Workers over http on localhost?
When I run code server with "--cert" to ask it to generate self-signed certificates i get
Error loading webview: Error: Could not register service workers: SecurityError: Failed to register a ServiceWorker for scope ('https://localhost:8080/webview/0abd743e-7e8b-4e72-a0c5-07c32e890f5e/') with script ('https://localhost:8080/webview/0abd743e-7e8b-4e72-a0c5-07c32e890f5e/service-worker.js?id=e0f9b720-4357-404a-87d5-060b4629d1d7&swVersion=2&extensionId=&platform=browser&vscode-resource-base-authority=vscode-resource.vscode-webview.net&parentOrigin=https%3A%2F%2Flocalhost%3A8080'): An SSL certificate error occurred when fetching the script..
when I click on an image... So https seems to be broken :-(
But why does it work on localhost? Maybe browsers don't block Service Workers over http on localhost?
I don't fully understand why/how it works, but yes, I think browsers allow localhost. See this answer on S/O
When I run code server with "--cert" to ask it to generate self-signed certificates i get
I believe this is a different error which should be fixed in the next version: https://github.com/coder/code-server/issues/4773
Thank you for mentioning this issue there! Let's hope this can be fixed "at the source".
I am also seeing the 'reconnect' issue with code-server v4.0.2 -- which is the latest release available at this time (18 Feb 2022)
I do hope a new release is provided soon, as in 2 week the new semester begins and I would like to upgrade the version the students are using.
I upgraded from 3.12.0 to 4.1.0 but still not working with code-server v4.1.0
- installed code-server normally
-
code-server --port 60000 --cert
- still getting below error with self-signed cert
@ky1emoon can you try with 4.2.0?
Based on that error, it seems like you're not using HTTPS or your browser doesn't recognize the validity of your certificate perhaps. You could also share browser logs.
Can someone verify if this is still an issue with 4.2.0?
I have install v4.2.0 in testing. Looks like the reconnect issue has been resolved as I am not seeing them any more. I will now look at update the images student use from v3.12.0 to v4.2.0
I am using v4.2.0, still has this problem
I am also using v4.2.0 now, seeing
Error loading webview: Error: Could not register service workers: SecurityError: Failed to register a ServiceWorker for scope ('https://.../static/out/vs/workbench/contrib/webview/browser/pre/') with script ('https://.../static/out/vs/workbench/contrib/webview/browser/pre/service-worker.js?v=4&vscode-resource-base-authority=vscode-resource.vscode-webview.net'): An SSL certificate error occurred when fetching the script..
This error comes up on localhost and when I connect from another computer.
BUT: I realised that Safari does show the image from another computer and on localhost - it doesn't bring up the certificate problem. However Brave Browser Version 1.37.111 Chromium: 100.0.4896.79 (Official Build) (x86_64)
shows the error above, even when "Shields down for this site" is selected.
Hmm...okay we will have to dig into this again. Sorry y'all!
Thank you for the notes!
That could well be related to https://github.com/coder/code-server/issues/4421 i suppose...
Still broken in 4.3.0
@gogobd thanks for confirming! Are you sure that your browser sees your SSL certificate as valid?
@jsjoeio I always have to confirm that I want to accept the certificate:

After confirming the browser marks it as not secure:

I run code-sever in docker using `--cert' :
CMD ~/.local/bin/code-server --cert --bind-addr 0.0.0.0:8080 /app
Thanks for the details! That part sounds like it's working as expected 🤔 We'll have to dig into this.
I was wondering if there's any news on this...
Unfortunately not :( I've been pulled onto another project so my code-server work as slowed down this month. Hopefully soon though! PRs/help welcome though
@gogobd Have a look at mkcert for making locally-trusted development certificates.
This could all be the same problem, I'm using "--cert", see https://github.com/coder/code-server/issues/5338