This document contains a loose set of message definitions between the front-end and the host.
This maps to the vscode-host.ts
module.
Communication between the frontend and host take place over the IHTMLWindow.postMessage
channel. If a message expects a response, the message will include an id
property. Presently,
only requests from the frontend support responses.
Indicates that the frontend is ready to process messages. This is fired once the
VsCodeApplicationHost
has been created, so that none of the messages are sent without
any listeners.
{
type: 'CONSOLE_READY'
}
Requests the host to issue a network request on behalf of the front-end.
{
type: 'EXECUTE_REQUEST';
id: number; // Uniquely identifies this request to correlate request/response
configuration: IHttpRequest;
}
Requests the host to save a request into an existing collection.
{
type: 'SAVE_REQUEST';
id: number; // Uniquely identifies this request to correlate request/response
request: ISerializableNetConsoleRequest;
toCollectionId: string | undefined;
}
The toCollectionId
parameter indicates which collection folder the request should be saved into.
If the parameter is omitted, it should replace the existing request with the matching request ID. If no
matching request ID exists (perhaps because the request has been deleted from disk since it was loaded),
the host should raise an error to the frontend.
The return value of this function should include two properties:
result
, of typeISerializableNetConsoleRequest
; andresultRequestId
of typestring
. If thetoCollectionId
parameter was specified, the result request ID will be different (it functions like Save-As).
Requests the host to save Authorization settings into an existing collection folder.
{
type: 'SAVE_COLLECTION_AUTHORIZATION_PARAMETERS';
id: number;
collectionId: string;
authorization: INetConsoleAuthorization;
}
Requests the host to save a set of environment variables to a particular environment.
{
type: 'SAVE_ENVIRONMENT_VARIABLES';
id: number;
variables: ISerializableNetConsoleParameter[];
environmentId: string;
}
Requests the host launch a browser or new tab to a particular URL. This is a fire-and-forget API and does not monitor for a result.
{
type: 'OPEN_WEB_LINK';
url: string;
}
Requests the host present a new tab and associates it to a particular ID. This is a fire-and-forget message insofar as it doesn't require a result or response, but the ID is stateful.
{
type: 'OPEN_NEW_UNATTACHED_REQUEST';
requestId: string;
}
Notifies the host that the current Network Console window is dirty or clean so that the host can query the user to save a request before closing the window. This is a fire-and-forget API and does not monitor for a result.
{
type: 'UPDATE_DIRTY_FLAG';
requestId: string;
isDirty: boolean;
}
Logs some message via the message port. No response is expected to this.
{
type: 'LOG';
[key: string | number]: unknown;
}
Instructs the host to prompt to create a new collection. No response is required from
this message, but if a user does in fact create a new collection, the Host should issue
an UPDATE_COLLECTIONS_TREE
message (which it can do at any time, regardless of user
input). This allows for "Save to Collection" dialogs to save even when there are no
collections open within the host.
{
type: 'PROMPT_FOR_NEW_COLLECTION';
}
Instructs the host to make an ARIA announcement. This is to satisfy WCAG 2.1 requirements of interaction status messages. The message to announce should already be localized.
{
type: 'ARIA_ALERT';
message: string;
}
Initializes the application according to the host settings.
{
type: 'INIT_HOST';
cssVariables: string; // CSS variables injected by host
isDark: boolean; // Whether the host theme is a dark theme
isHighContrast: boolean; // Whether the host theme is a high-contrast theme
persistedState?: string;
messagePort?: MessagePort; // Allows the host to provide an alternative message port
}
If persistedState
is set, the frontend will attempt to rehydrate its state from the JSON
payload contained within that property. (This allows for hosts like VS Code to store state
in the event of crashes or process suspension).
Initializes a new empty request. This does not include any parameters nor have a response
message defined; however, if a new empty request is successfully created, an
OPEN_NEW_UNATTACHED_REQUEST
message will be sent from the frontend to the host.
{
type: 'INIT_NEW_EMPTY_REQUEST';
}
Updates the application styles.
{
type: 'CSS_STYLE_UPDATED';
cssVariables: string; // CSS variables injected by VS Code
isDark: boolean; // Whether the VS Code theme is a dark theme
}
Updates the preferences registered to the application.
{
type: 'SET_PREFERENCES';
shouldShowDescription: boolean; // Whether to show the 'Description' field in editor grids
}
Loads a request from a collection.
{
type: 'LOAD_REQUEST';
request: INetConsoleRequest;
requiresSaveAs: boolean;
/** Deprecated in 0.11.1-preview **/
environmentAuth?: INetConsoleAuthorization;
/** Deprecated in 0.11.1-preview **/
environmentAuthPath?: string[];
}
requiresSaveAs
dictates whether the request may not be saved directly, but needs a toCollectionId
property to be included with the SAVE_REQUEST
message.
environmentAuth
and environmentAuthPath
are optional parameters, but if one is included, both
must be included. This enables the frontend to view and modify the environment authorization. The
environmentAuthPath
is an array of strings. These parameters are deprecated in 0.11.1-preview
and will no longer be respected, and will be removed entirely in the future.
Indicates that a request has been completed.
{
type: 'REQUEST_COMPLETE';
id: number; // Corresponds to the ID that was sent with EXECUTE_REQUEST
response: INetConsoleResponse;
}
Indicates that the set of loaded collections has been modified. The loaded collections are folders, allowing a user to choose where to "Save As".
{
type: 'UPDATE_COLLECTIONS_TREE';
collections: IHostCollection[];
}
interface IHostCollection {
id: string;
name: string;
children: IHostCollection[];
/** New in 0.11.1-preview **/
authorization: INetConsoleAuthorization | undefined;
}
The authorization
parameter is introduced in 0.11.1-preview. This allows the host to keep the
front-end's view of the entire collections tree up-to-date, and does not require the corresponding
environment to be passed as part of the LOAD_REQUEST
message.
Indicates that the user has requested to edit an environment.
{
type: 'EDIT_ENVIRONMENT_VARIABLES';
id: string; // Environment ID, from host
environment: INetConsoleEnvironment;
file: string;
collectionName: string; // friendly name of collection
}
If the frontend successfully edits the environment, it will dispatch the SAVE_ENVIRONMENT_VARIABLES
message. If the frontend dismisses the edit modal, no action will be dispatched.
Indicates that the user has activated an environment as the current environment.
{
type: 'UPDATE_ENVIRONMENT';
environment: INetConsoleEnvironment;
}
This frontend needs to see the active environment for environment variable substitution display.
Clears the current active environment with no replacement.
{
type: 'CLEAR_ENVIRONMENT';
}
Switches the root currently-displayed-view to a different request ID.
{
type: 'SHOW_OPEN_REQUEST';
requestId: string;
}
Closes a view.
{
type: 'CLOSE_VIEW';
requestId: string;
}