Skip to content

RegisterJSListener

Registers a C++ function as an event handler for a JavaScript event within a PrismaView. This method enables bidirectional communication between your web UI and SKSE plugin, allowing JavaScript to call C++ functions and pass data back to the game.

void RegisterJSListener(
PrismaView view,
const char* functionName,
JSListenerCallback callback
);
  • Type: PrismaView
  • Description: The PrismaView instance in which the handler is registered
  • Type: const char*
  • Description: The name of the JavaScript function to which the C++ function will be bound
  • Note: This becomes a global function accessible via window.functionName
  • Type: JSListenerCallback
  • Description: The C++ callback function that will be executed when the corresponding JavaScript function is called
  • Parameters: The callback’s string argument will contain the data passed from JavaScript

This method returns void.

// Register a simple event handler
PrismaUI->RegisterJSListener(view, "sendDataToSKSE", [](const char* data) -> void {
SKSE::log::info("Received data from JS: {}", data);
});
// JavaScript - call the registered function
window.sendDataToSKSE("Hello from JavaScript!");
  • Data Validation: Always validate incoming data from JavaScript
  • Error Handling: Use try-catch blocks when parsing complex data
  • Function Naming: Use descriptive names for your JavaScript functions
  • Single Responsibility: Keep each listener focused on a specific task