coder / coder/code-server

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

Đang mở
#3,410 74 bình luận 4 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
TypeScript
Star
79.3k
Fork
6.8k
Merge trung bình
2 ngày 6 giờ
Pull request đã merge (30 ngày)
41

Mô tả

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)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.