Command to open a webview in Visual Studio Code Extension

PHOTO EMBED

Wed Feb 03 2021 16:55:32 GMT+0000 (Coordinated Universal Time)

Saved by @mishka #json

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
  let openWebview = vscode.commands.registerCommand('exampleApp.openWebview', () => {
    const panel = vscode.window.createWebviewPanel(
	'openWebview', // Identifies the type of the webview. Used internally
	'Example Page', // Title of the panel displayed to the user
	vscode.ViewColumn.One, // Editor column to show the new webview panel in.
	{ // Enable scripts in the webview
		enableScripts: true //Set this to true if you want to enable Javascript. 
	}
	);
  }
  context.subscriptions.push(openWebview);
}

function getWebviewContent() {
  return `<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example Webview</title>
</head>
<body>
   <h1>This works!</h1>
	//Add some custom HTML here
</body>
</html>`;
}
content_copyCOPY

Mishka.codes/webviews-in-vscode