BrightScript Engine API
October 30, 2025 ยท View on GitHub
The engine worker library (brs.worker.js), has a programmable interface (brs.api.js), built in packages/browser/lib/, with the goal to facilitate the integration of the engine into web based applications.
Check the documentation to learn how to start using it. The only pre-requisites are to expose, on the default document, a canvas object named display and a video object named player, and optionally, if you want to show the performance statistics, you also need to expose a div object named stats.
Methods
| Method | Description | Parameters / Details |
|---|---|---|
initialize(customDeviceInfo?, options?) | Initializes the engine simulated device |
|
subscribe(observerId, observerCallback) | Subscribes to the engine events (see list below) |
|
unsubscribe(observerId) | Unsubscribes to the engine events |
|
execute(filePath, fileData, options?, deepLink?) | Loads and run an app package (.zip/.bpk), a source code file (.brs) or plain text BrightScript code |
|
terminate(reason) | Terminates the current app/source code execution |
|
redraw(fullScreen, width?, height?, dpr?) | Requests a display redraw (always keeps the aspect ratio based on display mode) |
|
setDisplayMode(mode) | Configures the display mode (if an app is running will reset the simulated device) |
|
| getDisplayMode() | Returns the current display mode. | |
setOverscanMode(mode) | Configures the overscan mode. |
|
| getOverscanMode() | Returns the current overscan mode. | |
setCaptionMode(mode) | Configures the closed caption mode. |
|
| getCaptionMode() | Returns the current closed caption mode. | |
setCaptionStyle(style) | Configures the closed caption style options. |
|
| getScreenshot() | Returns an ImageData with the latest rendered screenshot or null if not available. | |
enableStats(state) | Enables or disables the performance stats overlay |
|
setAudioMute(mute) | Mutes or un-mutes the audio during app execution |
|
| getAudioMute() | Returns true if the audio is muted | |
| getSerialNumber() | Returns the device serial number, this value changes when the deviceData.deviceModel is updated. | |
setControlMode(controls) | Enable/Disable the remote control simulation | controls (object) contains following properties:
|
| getControlMode() | Returns an object with the control mode flags | Same options sent to the setControlMode above. |
setCustomKeys(keysMap) | Sends a custom map of keyboard keys to add/remove from the remote control simulation |
|
setCustomPadButtons(buttonsMap) | Sends a custom map of game pad buttons to add/remove from the remote control simulation |
|
sendKeyDown(key, remote?, index?) | Sends a remote control key down event to the engine |
|
sendKeyUp(key, remote?, index?) | Sends a remote control key up event to the engine |
|
sendKeyPress(key, delay?, remote?, index?) | Sends a remote control key press event to the engine |
|
sendInput(params) | Sends custom events to the current application to be raised by roInput component |
|
mountExt(zipData) | Mounts a zip file as the external volume ext1: |
|
| umountExt() | Unmounts the external volume ext1: | |
updateMemoryInfo(used, total) | A method for the host application to inject memory usage information to the engine. |
|
debug(command) | Sends a debug command to the Engine |
|
| getDebugState() | Returns true if debug functionality is enabled, false if disabled | |
setDebugState(enabled) | Enables or disables the debug functionality |
|
| getVersion() | Returns the version of the API library |
Events
| Event | Description | Data Type |
|---|---|---|
| loaded | Triggered when the source code data has finished loading | object: {id: string, file: string, title: string, subtitle: string, version: string, running: boolean} |
| icon | Triggered when the zip file is loaded and manifest links to a valid icon for the app | base64: A base64 string of the app icon, extracted from the zip file. |
| registry | Triggered when the app updates the registry | Map: the registry with all recent recent updates. |
| started | Triggered when the engine started running the source code | object: {id: string, file: string, title: string, subtitle: string, version: string, running: boolean} |
| closed | Triggered when the engine terminated the execution of the source code | string: the exit reason based on Roku documentation |
| reset | Triggered when the RebootSystem() function is executed from the engine | null: Nothing is returned as data |
| control | Triggered when a control key is sent to the engine | object: {key: string, mod: number}. The property key contains an ECP key code and mod contains 0 for key down or 100 for key up |
| captionMode | Triggered when the closed caption mode is changed | string: The new caption mode, options are "Off", "On", "Instant replay", "When mute" |
| redraw | Triggered when the display canvas is redrawn/resized | boolean: If true the display canvas is in full screen mode |
| resolution | Triggered when the emulated screen resolution changes (controlled via BrightScript) | object: {width: integer, height: integer} |
| launch | Triggered when the methods roAppManager.launchApp() or roNDK.start() (with SDKLauncher app) are called from BrightScript | object: {app: string, params: Map}. |
| browser | Triggered when the library sub RokuBrowser is called from BrightScript | object: {url: string, width: integer, height: integer}. The parameters width and height defines the dimensions of the browser window |
| debug | Triggered when debug messages arrive from the worker library (BrightScript Interpreter) | object: {level: string, content: string}, levels are: print, beacon, warning, error, stop, pause, continue |
| error | Triggered when the any execution exception happens on the API library | string: The message describing the error |