Skip to content

RegisterConsoleCallback

Registers a callback to receive JavaScript console messages (console.log, console.warn, console.error, etc.) from a PrismaView. This is useful for debugging your web UI directly from your SKSE plugin’s log.

void RegisterConsoleCallback(
PrismaView view,
ConsoleMessageCallback callback
);
enum class ConsoleMessageLevel : uint8_t {
Log = 0,
Warning,
Error,
Debug,
Info
};

Represents the severity level of a JavaScript console message, matching the standard console API methods.

typedef void (*ConsoleMessageCallback)(
PrismaView view,
ConsoleMessageLevel level,
const char* message
);

The function signature for the console message callback.

  • Type: PrismaView
  • Description: The PrismaView instance from which to receive console messages
  • Type: ConsoleMessageCallback
  • Description: The C++ callback function that will be called whenever a JavaScript console message is produced in the view
  • Note: Pass nullptr to unregister a previously registered callback

This method returns void.

PRISMA_UI_API::IVPrismaUI2* PrismaUIv2 = nullptr;
PrismaUIv2 = PRISMA_UI_API::RequestPluginAPI<PRISMA_UI_API::IVPrismaUI2>();
// Always guard V2 calls with a null check
if (PrismaUIv2) {
PrismaUIv2->RegisterConsoleCallback(view, [](PrismaView view, ConsoleMessageLevel level, const char* message) {
switch (level) {
case ConsoleMessageLevel::Log:
SKSE::log::info("[JS] {}", message);
break;
case ConsoleMessageLevel::Warning:
SKSE::log::warn("[JS] {}", message);
break;
case ConsoleMessageLevel::Error:
SKSE::log::error("[JS] {}", message);
break;
case ConsoleMessageLevel::Debug:
SKSE::log::debug("[JS] {}", message);
break;
case ConsoleMessageLevel::Info:
SKSE::log::info("[JS] {}", message);
break;
}
});
}
// JavaScript — these messages will appear in the SKSE log
console.log("UI initialized"); // [JS] UI initialized
console.warn("Missing optional field"); // [JS] Missing optional field
console.error("Failed to load data"); // [JS] Failed to load data
  • Always Check for V2: Wrap every RegisterConsoleCallback call with if (PrismaUIv2) — never assume V2 is available
  • Graceful Degradation: Your plugin must work correctly even if V2 is not available — treat console callbacks as an optional enhancement
  • Use for Debugging: This callback is primarily a development tool — use it to diagnose JavaScript issues without attaching a debugger
  • Filter by Level: Only log the severity levels relevant to your needs
  • Unregister When Done: Pass nullptr to clean up the callback when it’s no longer needed