Overview
This article documents the Lab Client API (window.api.v1
) endpoints used for JavaScript. For each endpoint, you'll find:
Event ID: Identifies the event associated with the message.
Description: Explains the endpoint’s behavior and context.
Request parameters: Lists the required fields to include in the message payload.
Returns: Describes the structure and content of the message returned.
Example: Provides a sample request to demonstrate usage.
General Notes
All methods are available via direct JavaScript (
window.api.v1.methodName
) and viapostMessage
for iframe integrations.For event/callback registration, the callback will be triggered with the relevant data when the event occurs.
Endpoints
getEnvironmentConnectionStatus()
Description: Returns the current connection status of the lab environment (e.g., VM connection state). The response includes the environment type, machine ID, current status, and any error details (if available). Use this method to verify whether automation or user actions can proceed.
Request Parameters
None
Returns
Requests return an object with these properties:
Name | Type | Values | Description |
---|---|---|---|
| string |
| Type of environment |
| number |
| Numeric code for the environment type |
| string or null | — | Unique ID of the machine, if available |
| string |
| Connection state |
| number |
| Numeric code for the status |
| string or null | — | Error message, if applicable |
Example
const status = api.v1.getEnvironmentConnectionStatus();
getEnvironmentLatency()
Description: Returns the current latency in milliseconds (ms) between the lab client and the selected VM, allowing you to monitor connection responsiveness and troubleshoot network issues.
Request Parameters
None
Returns
Name | Type | Description |
---|---|---|
| number | Latency in ms, or |
Example
const latency = api.v1.getEnvironmentLatency();
sendTextToEnvironment(text)
Description: Sends the provided text into the active VM console, enabling automation of commands, credentials, or guided lab steps. This method has no return value. Ensure the environment is connected before calling this method.
Response
This event does not return a response.
Request Parameters
Name | Type | Required? | Default Value | Description |
---|---|---|---|---|
| string | Yes | — | The text or command to send to the VM console |
Returns
None
Example
api.v1.sendTextToEnvironment("ls -la");
getLabToken(name)
Description: Retrieves the runtime value of a named lab token (without the @lab.
prefix), which is used as a placeholder for dynamic content in instructions or scripts.
Request Parameters
Name | Type | Required? | Default Value | Description |
---|---|---|---|---|
| string | Yes | — | The name of the lab token to retrieve, without the |
Returns
Name | Type | Description |
---|---|---|
| string or null | The value of the requested lab token, or |
Example
const userName = api.v1.getLabToken("LabProfile.Name");
getLabVariable(name)
Description: Retrieves the value of a named lab Variable, which stores and shares state across the lab environment.
Request Parameters
Name | Type | Required? | Default Value | Description |
---|---|---|---|---|
| string | Yes | — | The name of the lab variable to retrieve |
Returns
Name | Type | Description |
---|---|---|
| string or null | The value of the requested lab variable, or |
Example
const value = api.v1.getLabVariable("myVariable");
setLabVariable(name, value)
Description: Sets or updates a named lab variable, making the specified value available to other scripts or instructions in the lab session.
Response
This event does not return a response.
Request Parameters
Name | Type | Required? | Default Value | Description |
---|---|---|---|---|
| string | Yes | — | The name of the lab variable to set |
| string | Yes | — | The value to set on the lab variable |
Returns
None
Example
api.v1.setLabVariable("myVariable", "newValue");
sendLabNotification(text)
Description: Displays a message in the lab client UI, typically as a toast popup, for alerts, confirmations, or guidance.
Response
This event does not return a response.
Request Parameters
Name | Type | Required? | Default Value | Description |
---|---|---|---|---|
| string | Yes | — | The notification message to display in the lab client UI |
Returns
None
Example
api.v1.sendLabNotification("Lab step completed!");
getInstructionsPageIndex()
Description: Returns the index of the currently displayed instructions page, allowing you to track progress or synchronize the UI.
Request Parameters
None
Returns
Name | Type | Description |
---|---|---|
| number or null | The index of the current lab instructions page, or |
Example
const pageIndex = api.v1.getInstructionsPageIndex();
getMinutesRemaining
Description: Returns the number of minutes remaining in the lab session, which you can use to display countdowns or warn learners that time is running out.
Request Parameters
None
Returns
Name | Type | Description |
---|---|---|
| number or | The number of minutes remaining in the lab session, or |
Example
const minutes = api.v1.getMinutesRemaining();
gotoInstructionsPage(index)
Description: Programmatically navigates to a specific instructions page by index, which you can use for guided experiences or LMS-driven navigation.
Response
This event does not return a response.
Request Parameters
Name | Type | Required? | Default Value | Description |
---|---|---|---|---|
| number | Yes | — | The index of the instructions page to open |
Returns
None
Example
api.v1.gotoInstructionsPage(2);
evaluateActivity(alias, index = 0)
Description: Triggers evaluation of a specific lab activity (e.g., check whether a lab step is complete), which you can use for progress tracking or gamification.
Request Parameters
Name | Type | Required? | Default Value | Description |
---|---|---|---|---|
| string | Yes | — | The unique identifier of the activity to evaluate, used to check whether the specified activity has been completed |
| number | No |
| The index of the activity to target when multiple activities share the same alias |
Returns
None
Example
api.v1.evaluateActivity("step1");
onEnvironmentConnectionStatusChange(callback)
Description: Registers a callback that listens for changes in the lab environment’s connection status, receiving the updated status object whenever the VM connects or disconnects.
Response
This event does not return a response.
Request Parameters
Name | Type | Required? | Default Value | Description |
---|---|---|---|---|
| function | Yes | — | The function called with the status object when the connection status changes |
Returns
None
Example
api.v1.onEnvironmentConnectionStatusChange((status) => {
console.log("Connection status:", status);
});
onLabVariableChanged(callback)
Description: Registers a callback that listens for changes to lab variables, providing the variable name and its updated value.
Response
The event doesn’t return a response.
Request Parameters
Name | Type | Required? | Default Value | Description |
---|---|---|---|---|
| function | Yes | — | The function called with |
Returns
None
Example
api.v1.onLabVariableChanged((name, value) => {
console.log(`Variable ${name} changed to ${value}`);
});
onInstructionsPageChanged(callback)
Description: Registers a callback that listens for instruction page changes, providing the new page index when the user navigates.
Response
This event doesn’t return a response.
Request Parameters
Name | Type | Required? | Default Value | Description |
---|---|---|---|---|
| function | Yes | — | The function called with |
Returns
None
Example
api.v1.onInstructionsPageChanged((pageIndex) => {
console.log("Now on page:", pageIndex);
});
onActivityCompleted(callback)
Description: Registers a callback that listens for lab activity completion events, providing an activityInfo
object with details about the completed activity.
Response
This event doesn’t return a response.
Request Parameters
Name | Type | Required? | Default Value | Description |
---|---|---|---|---|
| function | Yes | — | The function called with |
Returns
None
Example
api.v1.onActivityCompleted((activityInfo) => {
console.log("Activity completed:", activityInfo);
});