html property

String get html

HTML contents of the webview.

This should be a complete, valid html document. Changing this property causes the webview to be reloaded.

Webviews are sandboxed from normal extension process, so all communication with the webview must use message passing. To send a message from the extension to the webview, use {@linkcode Webview.postMessage postMessage}. To send message from the webview back to an extension, use the acquireVsCodeApi function inside the webview to get a handle to the editor's api and then call .postMessage():

<script>
    const vscode = acquireVsCodeApi(); // acquireVsCodeApi can only be invoked once
    vscode.postMessage({ message: 'hello!' });
</script>

To load a resources from the workspace inside a webview, use the {@linkcode Webview.asWebviewUri asWebviewUri} method and ensure the resource's directory is listed in {@linkcode WebviewOptions.localResourceRoots}.

Keep in mind that even though webviews are sandboxed, they still allow running scripts and loading arbitrary content, so extensions must follow all standard web security best practices when working with webviews. This includes properly sanitizing all untrusted input (including content from the workspace) and setting a content security policy.

Implementation

_i2.String get html => _i5.getProperty(
      this,
      'html',
    );
set html (String value)

Implementation

set html(_i2.String value) {
  _i5.setProperty(
    this,
    'html',
    value,
  );
}