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

Webview Api Prototype #42690

Merged
merged 10 commits into from
Feb 15, 2018
Merged

Webview Api Prototype #42690

merged 10 commits into from
Feb 15, 2018

Conversation

mjbvz
Copy link
Collaborator

@mjbvz mjbvz commented Feb 1, 2018

Moving #41853 to branch on main repo


Proposes a new Api for webviews. This API aims to make the current html preview api more usable, safer, and more extensible for the future.

Besides the new API, the new webviews also differ in several important ways:

  • They are no longer loaded in the file:// origin so they can't read files on disk (you have to use the new protocols for this)
  • Scripts are disabled by default
  • Command uris are disabled by default
  • postMessage inside of webviews now posts back to vscode directly (no more weird click faking required)

TODO

  • Discuss and finalize API
  • Add onFocus and onBlur to the webview object
  • See if implementation can be cleaned up
  • Add dispose method on webview
  • Add editorColumn property on webview
  • Make enableCommandUris option actually enable command uris
  • Add a new protocol for accessing a resource inside of a workspace folder (markdown loading a local image for example)
  • Finish moving markdown extension to use the new API

@mike-lischke
Copy link

mike-lischke commented Feb 1, 2018

A suggestion: allow reading the current content of the view as text. This way it's possible to see the actual HTML text, including what vscode added/changed (and store it on disk, for further use). And I would love to see a way to access variables in the DOM. That doesn't require to make the entire DOM public, just a way to read and set variables. This would make updating a webview a lot simpler, without fully reloading it. It would also allow to save and restore state, in case such a view must be generated the same way as it was when the user left it.

@mjbvz mjbvz merged commit 3412eab into master Feb 15, 2018
@mjbvz
Copy link
Collaborator Author

mjbvz commented Feb 15, 2018

@mike-lischke This new API makes it easier to implement that functionality if you would find it useful. They are a bit too high level in my view for the vscode core api

@mike-lischke
Copy link

Thanks @mjbvz, I'll certainly give it a try. The simplified messaging looks good, I can probably come up with a function that allows to update variables via that. Does keepAlive keep the content also if the webview's tab is closed or only when it becomes inactive (switching to another tab). For me it is enough keep the content as long as the tab exists, not longer.

@mjbvz mjbvz deleted the webview-api branch March 2, 2018 20:54
@mike-lischke
Copy link

@mjbvz Will you add a WebView example to https://github.com/Microsoft/vscode-extension-samples?

@chongchai
Copy link

@mjbvz when the WebView can be used in the extension development?
I can't wait to use it.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants