Skip to content

Webviews

If you need to display custom functionality that is beyond what the VS Code API supports, you can use webviews, which are fully customizable. It's important to understand that webviews should only be used if you absolutely need them.

✔️ Do

  • Only use webviews when absolutely necessary
  • Activate your extension only when contextually appropriate
  • Open webviews only for the active window
  • Ensure all elements in the view are themeable (see the webview-view-sample and color tokens documentation)
  • Ensure your views follow accessibility guidance (color contrast, ARIA labels, keyboard navigation)
  • Use command actions in the toolbar and in the view

❌ Don't

  • Use for promotions (upgrades, sponsors, etc.)
  • Use for wizards
  • Open on every window
  • Open on extension updates (ask via a Notification instead)
  • Add functionality that is unrelated to the editor or workspace
  • Repeat existing functionality (Welcome page, Settings, configuration, etc.)

Webview examples

Simple Browser

This extension opens a browser preview for the editor to the side.

Weview sample - Browser

This example shows VS Code Web being developed right inside VS Code. A Webview panel is used to render a browser-like window.

Pull Request

This extension shows pull requests for the repository of the workspace in a custom tree view and then uses a webview for a detail view of the pull request.

Webview sample - Pull Request

Webview views

You can also place webviews into any view container (sidebar or panel) and these elements are called webview views. The same webview guidance applies to webview views.

Webview View

This webview view shows content for creating a pull request that uses dropdowns, inputs, and buttons.

评论区
评论区空空如也
发送评论
名字
0 / 20
邮箱
0 / 100
评论内容
0 / 140
由于是非实名评论,所以不提供删除功能。如果你需要删除你发送的评论,或者是其他人的评论对你造成了困扰,请 发邮件给我 。同时评论区会使用 AI + 人工的方式进行审核,以达到合规要求。

© thebestxt.cc
辽ICP备16009524号-8
本站所有文章版权所有,转载请注明出处