Cannot open jpg, gif, or png in code-server web IDE
See original GitHub issueOS/Web Information
- Web Browser: chrome/firefox/edge
- Local OS: Microsoft Windows 10 Pro 10.0.19042 Build 19042
- Remote OS: N/A
- Remote Architecture: N/A
code-server --version
: 3.11.1 and 3.11.0
Steps to Reproduce
- Open a docker image of code-server with the specified versions above
- Upload a jpg, gif, or png image into the web IDE
- Double click the uploaded file to display the image
Expected
The image should display in a webview without error
Actual
Same error message below appears in chrome, firefox, and edge
Notes
There was a regression between versions 3.10.2 and 3.11.0. The bug does not occur on versions earlier than 3.11.0. There is no output on the console whenever this error occurs, which is 100% of the time. I am going to attempt to isolate the version which the bug starts. I will comment when I have done this.
This issue can be reproduced in VS Code: No
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Using VS Code for Remote Development (#367339) - GitLab
We have to decide if we want to go the proven route of using the desktop VS code (and having it separate from...
Read more >How to Display Images in ESP32/ESP8266 Web Server
This tutorial shows how to display images (.png and .jpg) in your ESP32 or ESP8266 web servers using Arduino IDE. We cover how...
Read more >Image is not showing in browser? - html - Stack Overflow
I am currently practice with JSP and I try this html code to make a web page on NetBeans IDE 7.0 but when...
Read more >How to Fix All Problem of Image File Not opening in Windows ...
How to Fix JPG PNG Photo Files Not Opening in Windows 10 JPG, JPEG, Exif, TIFF, GIF, BMP, PNG, BAT, BPG, IMG, Code...
Read more >loadImage() / Reference / Processing.org
Four types of images ( .gif, .jpg, .tga, .png) images may be loaded. ... Load image from a web server webImg = loadImage(url,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ahh maybe the CSP no longer works because the URL has a port in it now? So to fix I think we can patch the directive to be:
Taking a look here…
Going to use this comment as a place to take notes.
This seems to be the solution that might work but unsure where to put it 🤔
Doing a search for “Content-Security-Policy” to find a couple places. In the meantime, going to run
yarn watch
and reproduce it locally.Reproducing it
I can reproduce very easily.
It seems like the issue is coming from
lib/vscode/src/vs/workbench/contrib/webview/browser/pre/index.html
but there is no meta tag with a Content-Security-Policy there. It must be injected in later.Searching for “Content-Security-Policy”
Really hard to tell which one this is exactly.
I think I’ve narrowed it down to two places:
lib/vscode/src/vs/code/electron-browser/workbench/workbench.html
lib/vscode/src/vs/code/electron-sandbox/workbench/workbench.html
These are the only two HTML files under
lib/vscode/src
that have “Content-Security-Policy” and mentionvscode-webview
. I’ll see if the change has any effect.No luck. That didn’t work:
no luck though.
I may be doing this in the wrong place entirely 🤔 I guess I can check by commenting out this line.
Yeah, I commented out the line. This doesn’t seem to be the problem file (lib/vscode/src/vs/code/electron-browser/workbench/workbench.html)
I tried commenting out any CSP meta tags in these files to see if I could isolate which one it is but nothing worked.
I wonder if this policy is definitely elsewhere?
I FOUND IT
I was looking in the wrong place. Image previews (I was previewing a
.png
image) happen thanks to an extension bundled with vscode here:lib/vscode/extensions/image-preview/src/preview.ts
If you remove the CSP policy, it loads the image:
If we look at the code, we see this:
cspSource
appears to behttps://*.vscode-webview.net
. After some digging around, I found out where it is defined: https://github.com/cdr/code-server/blob/main/lib/vscode/src/vs/workbench/api/common/shared/webview.ts#L27And if I change that to match what @code-asher suggested, it works!
PR incoming.