-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading external resources in VSCode Extension Webview fails due to CORS Policy #102959
Comments
Can you please share some example extension code that demonstrates the issue |
I have done some digging and cornered down the issue to the following change: it seems that Before:After:Since we are relying on path to join the webview uri to the resource path, this The solution/workaround is to pass the full joined path to I'm not sure if this is an intended change or a bug, feel free to close it if it is intended. |
Yes sounds like it may be a bug in the extension code. Can you share the code that generates the font's uri? |
Old way (worked before 1.47.2):JS:const fontPath = path.join(extensionPath, "out", "fonts", "font.ttf"); CSS:@font-face {
font-family: 'Font Name';
font-style: normal;
font-weight: normal;
src:
url(vscode-resource:${fontPath}) format('truetype');
} Fixed way:JSconst fontPath = panel.webview.asWebviewUri(vscode.Uri.file(
path.join(extensionPath, "out", "fonts", "font.ttf")
)); CSS @font-face {
font-family: 'Font Name';
font-style: normal;
font-weight: normal;
src:
url('${fontPath}') format('truetype');
} |
Thanks. I believe this is expected. Last iteration, we removed support for You can also simplify your code by using const fontPath = panel.webview.asWebviewUri(vscode.Uri.file(
vscode.Uri.joinPath(extensionUri, "out", "fonts", "font.ttf")
)); |
Version: 1.47.2
Commit: 17299e4
Date: 2020-07-15T18:18:50.054Z (4 days ago)
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 19.5.0
Tested with insiders as well:
Version: 1.48.0-insider
Commit: 6c21258
Date: 2020-07-20T05:27:28.503Z (9 hrs ago)
Electron: 8.3.3
Chrome: 80.0.3987.165
Node.js: 12.13.0
V8: 8.0.426.27-electron.0
OS: Darwin x64 19.5.0
Issue
It seems like this change broke loading external
vscode-resource
s.A similar issue: #99190
Steps to Reproduce:
Loading external resources (ttf font for example), produces the following error in Webview console
This used to work fine in previous versions.
I have updated the webview HTML to support the new "vscode-webview-resource" as follows
Fonts are getting loaded in
<style>
tag as such:Related issue: #97777
Does this issue occur when all extensions are disabled?: Yes
cc: @mjbvz
The text was updated successfully, but these errors were encountered: