Files
vscode-extension-samples/webview-sample
Matt Bierner 2ee6b0b7b9 Update all of our samples to target VSCode 1.100 or newer
This makes sure that if folks get a relatively recent `vscode.d.ts`. It also lets us safely bump up the target to es2024 so you can use all the latest lib additions
2025-08-07 07:57:14 -07:00
..
2020-05-29 14:20:07 -07:00
2021-10-01 21:30:20 -04:00
2024-10-26 17:44:03 -07:00

Cat Coding — A Webview API Sample

Demonstrates VS Code's webview API. This includes:

  • Creating and showing a basic webview.
  • Dynamically updating a webview's content.
  • Loading local content in a webview.
  • Running scripts in a webview.
  • Sending message from an extension to a webview.
  • Sending messages from a webview to an extension.
  • Using a basic content security policy.
  • Webview lifecycle and handling dispose.
  • Saving and restoring state when the panel goes into the background.
  • Serialization and persistence across VS Code reboots.

Demo

demo

VS Code API

vscode module

Running the example

  • Open this example in VS Code 1.47+
  • npm install
  • npm run watch or npm run compile
  • F5 to start debugging

Run the Cat Coding: Start cat coding session to create the webview.

Commands

This extension provides the following commands:

  • Cat Coding: Start cat coding session: Creates and displays the Cat Coding webview.
  • Cat Coding: Do refactor: Halves the count of lines of code displayed in the Cat Coding webview.

Messages

The Cat Coding webview can send the following messages to the extension:

  • alert: Sent when the cat introduces a bug. The message includes the text '🐛 on line ' followed by the current line count.