code-server icon indicating copy to clipboard operation
code-server copied to clipboard

[Bug]: Image not showing up

Open gogobd opened this issue 3 years ago • 30 comments

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

  1. run code-server --bind-addr 0.0.0.0:443 --cert -- /app
  2. Connect to the address
  3. 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

gogobd avatar Jan 27 '22 17:01 gogobd

Additionally "Cannot reconnect. Please reload the window." pops up after some minutes... that's probably related.

gogobd avatar Jan 27 '22 18:01 gogobd

I was able to reproduce this locally on macOS + Brave with code-server --bind-addr 0.0.0.0:443 --cert

image

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.

jsjoeio avatar Jan 27 '22 23:01 jsjoeio

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

enric1994 avatar Feb 02 '22 12:02 enric1994

Seems likely to be the same issue as https://github.com/coder/code-server/issues/4693#issuecomment-1009039212

code-asher avatar Feb 08 '22 19:02 code-asher

I updated to version 4.0.2 and this issue seems to be fixed!

gogobd avatar Feb 12 '22 13:02 gogobd

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)

enric1994 avatar Feb 12 '22 21:02 enric1994

I realised that it did work when docker was running on the same machine, but not when code server was on another machine. Reopening.

gogobd avatar Feb 13 '22 10:02 gogobd

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.

gogobd avatar Feb 13 '22 11:02 gogobd

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

jsjoeio avatar Feb 14 '22 21:02 jsjoeio

But why does it work on localhost? Maybe browsers don't block Service Workers over http on localhost?

gogobd avatar Feb 14 '22 21:02 gogobd

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 :-(

gogobd avatar Feb 14 '22 22:02 gogobd

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

jsjoeio avatar Feb 14 '22 22:02 jsjoeio

Thank you for mentioning this issue there! Let's hope this can be fixed "at the source".

gogobd avatar Feb 14 '22 22:02 gogobd

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.

antofthy avatar Feb 18 '22 03:02 antofthy

I upgraded from 3.12.0 to 4.1.0 but still not working with code-server v4.1.0

  1. installed code-server normally
  2. code-server --port 60000 --cert
  3. still getting below error with self-signed cert image

ky1emoon avatar Mar 19 '22 06:03 ky1emoon

@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.

jsjoeio avatar Mar 23 '22 17:03 jsjoeio

Can someone verify if this is still an issue with 4.2.0?

jsjoeio avatar Mar 23 '22 17:03 jsjoeio

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

antofthy avatar Mar 25 '22 04:03 antofthy

I am using v4.2.0, still has this problem

HaoLiuHust avatar Apr 08 '22 03:04 HaoLiuHust

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.

gogobd avatar Apr 08 '22 16:04 gogobd

Hmm...okay we will have to dig into this again. Sorry y'all!

Thank you for the notes!

jsjoeio avatar Apr 11 '22 23:04 jsjoeio

That could well be related to https://github.com/coder/code-server/issues/4421 i suppose...

gogobd avatar Apr 12 '22 09:04 gogobd

Still broken in 4.3.0 Screenshot 2022-04-19 at 19 30 59

gogobd avatar Apr 19 '22 17:04 gogobd

@gogobd thanks for confirming! Are you sure that your browser sees your SSL certificate as valid?

jsjoeio avatar Apr 19 '22 18:04 jsjoeio

@jsjoeio I always have to confirm that I want to accept the certificate:

Screenshot 2022-04-19 at 20 56 56

After confirming the browser marks it as not secure:

Screenshot 2022-04-19 at 20 59 09

I run code-sever in docker using `--cert' :

CMD ~/.local/bin/code-server --cert --bind-addr 0.0.0.0:8080 /app

gogobd avatar Apr 19 '22 19:04 gogobd

Thanks for the details! That part sounds like it's working as expected 🤔 We'll have to dig into this.

jsjoeio avatar Apr 19 '22 19:04 jsjoeio

I was wondering if there's any news on this...

gogobd avatar May 16 '22 13:05 gogobd

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

jsjoeio avatar May 19 '22 21:05 jsjoeio

@gogobd Have a look at mkcert for making locally-trusted development certificates.

benz0li avatar Jul 21 '22 08:07 benz0li

This could all be the same problem, I'm using "--cert", see https://github.com/coder/code-server/issues/5338

gogobd avatar Jul 21 '22 08:07 gogobd