Skip to content
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

Upgrade to VS Code's webview API #1602

Closed
mjbvz opened this issue Nov 6, 2018 · 13 comments
Closed

Upgrade to VS Code's webview API #1602

mjbvz opened this issue Nov 6, 2018 · 13 comments
Assignees
Labels
Area-HTML Content View Issue-Enhancement A feature request (enhancement).

Comments

@mjbvz
Copy link

mjbvz commented Nov 6, 2018

Hi, I'm on the VS Code team. I noticed that your extension uses the vscode.previewHtml command which is deprecated and which we are actively working to remove: microsoft/vscode#62630

We've developed a webview API that provides a much better developer experience and offers a number of important security and compatibility benefits over previewHtml. We cannot fix previewHtml without breaking backwards compatibility, and have instead opted to remove it.

To ensure that your extension continues to work properly in VS Code, please try upgrading to use the new Webview API. You can find documentation on the API usage here. Let me know if you have any questions or concerns about this migration

@rkeithhill
Copy link
Contributor

Thanks for the heads up!

@TylerLeonhardt TylerLeonhardt added the Issue-Enhancement A feature request (enhancement). label Nov 10, 2018
@rkeithhill rkeithhill self-assigned this Nov 18, 2018
@mjbvz
Copy link
Author

mjbvz commented Feb 1, 2019

Just a heads up: in VS Code 1.32 (the February update), using the previewHtml command will show an alert to the user, although the command should still work. We plan to remove the command entirely with VS Code 1.33 (March update)

@rkeithhill
Copy link
Contributor

I started the switch over but am having a bit of a tough go at it. Folks who use this feature with the PowerShell extension expect to be able to run their own personal JavaScript files (not under some extension's subdir). They tend to put these JS files in a workspace or their home dir. I guess I could inline the JavaScript in the HTML?

@wycats
Copy link

wycats commented Apr 21, 2019

I discovered this problem after trying to understand why this wasn't working. What's the status of this?

@TylerLeonhardt
Copy link
Member

@mjbvz do you have any insight on how we could accomplish running a users own personal js files (besides just inlining)?

@TylerLeonhardt
Copy link
Member

@wycats it is indeed broken as of 1.33 of vscode. We'll get it fixed but there might be some breaking changes that come with it as the underlying API is very different.

@mjbvz
Copy link
Author

mjbvz commented Apr 24, 2019

@TylerLeonhardt Your webview can pass any set of paths to localResourceRoots. Try passing in the path to the user scripts

@TylerLeonhardt
Copy link
Member

@mjbvz that sadly doesn't seem to work:

See the variables section:
image

The URI to my js file is there... but the function defined in said js file is not available
image

@mjbvz
Copy link
Author

mjbvz commented Apr 24, 2019

Are the scripts also referenced on the page using vscode-resource URIs? Can you share a branch that has your current code?

@TylerLeonhardt
Copy link
Member

Ah... wasn't also including them in the body of the html... sorry about that.

Now that I've referenced them using vscode-resource:///full/path/to/fdsa.js everything works as expected!

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Apr 24, 2019

There doesn't seem to be a way to update the localResourceRoots once you've already created a webview. Is that true, @mjbvz? That field in webviewPanel.webview.options.localResourceRoots seems to be readonly.

@mjbvz
Copy link
Author

mjbvz commented Apr 24, 2019

The options objects are immutable but Webview.options is mutable

@TylerLeonhardt
Copy link
Member

#1919 fixed in this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-HTML Content View Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

No branches or pull requests

5 participants