Skip to content

Webview Api Prototype#42690

Merged
mjbvz merged 10 commits intomasterfrom
webview-api
Feb 15, 2018
Merged

Webview Api Prototype#42690
mjbvz merged 10 commits intomasterfrom
webview-api

Conversation

@mjbvz
Copy link
Copy Markdown
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

@mjbvz mjbvz self-assigned this Feb 1, 2018
@mike-lischke
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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

@chongchai
Copy link
Copy Markdown

@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