vscode-webview-expert

Implement secure VS Code WebView panels with CSP and message protocols.

21|11|Updated Jul 4, 2025
One-click install
npx skills add https://github.com/s-hiraoku/vscode-sidebar-terminal --skill vscode-webview-expert
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vscode-webview-expert
Source: https://github.com/s-hiraoku/vscode-sidebar-terminal/tree/main/.claude/skills/vscode-webview-expert
Command: npx skills add https://github.com/s-hiraoku/vscode-sidebar-terminal --skill vscode-webview-expert

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill provides expert guidance to overcome the complexities of implementing secure, performant, and well-integrated WebViews in VS Code extensions. It simplifies challenges like Content Security Policy (CSP), inter-process communication, and state management, saving developers significant time and effort.

Core Features & Use Cases

  • Secure CSP Implementation: Generate and configure robust Content Security Policies to protect WebViews from XSS and other vulnerabilities.
  • Extension ↔ WebView Communication: Design and implement reliable message passing protocols for seamless data exchange.
  • State Management & Persistence: Manage WebView state, ensuring it persists across hide/show cycles and VS Code restarts.
  • Use Case: Design a secure communication protocol for a VS Code WebView panel that sends data to the extension and persists its state across user sessions, ensuring data integrity and security.

Quick Start

Use the vscode-webview-expert skill to generate a Content Security Policy for a new WebView panel, ensuring scripts and styles from the extension's 'media' directory are allowed.

Frequently Asked Questions about vscode-webview-expert

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement Content Security Policy for a VS Code WebView?

Content Security Policy protects WebViews from XSS attacks by restricting script and style sources. Generate a CSP that allows resources from your extension's media directory, then apply it via the WebView's `cspSource` and `localResourceRoots` configuration to safely load scripts and styles.

How do I set up communication between a VS Code extension and its WebView?

Extension-WebView communication uses message passing protocols. Define a message contract, send data from the extension using `webview.postMessage()`, and listen on the WebView side with `window.addEventListener('message')`. This ensures reliable, secure data exchange between processes.

How do I persist WebView state across VS Code sessions?

WebView state management requires storing data in the extension's storage backend and restoring it on panel creation. Use `context.globalState` or `context.workspaceState` to persist state, then pass it to the WebView on initialization so content survives hide/show cycles and restarts.

What security best practices should I follow when building VS Code WebViews?

Enforce Content Security Policy, validate all messages between extension and WebView, restrict resource loading to `localResourceRoots`, avoid inline scripts, and use `nonce` attributes for dynamic script injection to prevent injection attacks and unauthorized access.

Can I use custom editors with VS Code WebViews?

Yes. WebViews support custom editor implementations through the `CustomEditorProvider` API, enabling rich UI for document types. Combine WebView panels with state persistence and secure messaging to build performant custom editors with full VS Code integration.