coder / coder/code-server

Dynamically webview resources fail to load in some browser/OS combinations

Abierto
#3,410 74 comentarios 4 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
TypeScript
Estrellas
79.3k
Forks
6.8k
Merge medio
2 d 6 h
PR fusionados (30 d)
41

Descripción

Hi, I have two issues, they may all be related to https certificates.

- One is `code-server` prompt can‘t register serviceworker error
- The other is that I can't `load resources dynamically` on my expansion webview.

I run `code-server --host 0.0.0.0 --port 8223 --cert` in docker `ubuntu:20.04`, and expose `8223` in my Windows 10 host, but I get an ssl error when I open a exntesion webview in code-server in my company.

when I use `Chrome command line` "**--ignore-certificate-errors**", my extension webview can't dynamic loading of resources(eg. js, css), which cause the page style confusion, the Chrome dev tool network display the resource keep pending until it fails.

At first, I thought it was the invalid certificate problem,but even if I use a valid certificate, I **still** can't dynamic loading resources.(**Without any certificate errors and any Chrome command line options**)

I use something like this to dynamic loading resources
```
function addCss(path, callback) {
if(!checkcache(path)) { /*Check if it has been loaded*/
var head = dom.getElementsByTagName('head')[0];
var link = dom.createElement('link');
link.href = path;
link.rel = 'stylesheet';
link.type = 'text/css';
head.appendChild(link); /*Add to HTML*/
link.onload = link.onreadystatechange = function() { /*whether the loading is successful*/
if(!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
link.onload = link.onreadystatechange = null;
callback();
}
};
cache[path] = 1; /*Store loaded paths*/
}
};
```

-->

## OS/Web Information

- Web Browser: Chrome 90.0.4430.212 64bit
- Local OS: Windows 10
- Remote OS: ubuntu:20.04 (docker)
- Remote Architecture: x86
- `code-server --version`: 3.9.0

## Steps to Reproduce

1. installl code-server 3.9.0 in docker ubuntu:20.04
2. code-server --host 0.0.0.0 --port 8223 --cert
3. enter localhost:8888 and open my extension webview

## Expected

No error.

## Actual

get an error in bottom right corner:
```
Error loading webview: Could not register service workers: SecurityError: Failed to register a ServiceWorker for scope ('https://localhost:8223/webview/') with script ('https://localhost:8223/webview/service-worker.js'): An SSL certificate error occurred when fetching the script.
```

## Screenshot

![image](https://user-images.githubusercontent.com/18023066/118653196-db6d5200-b819-11eb-94bd-0091f9fbd2b3.png)

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.