Views
A PrismaView is a page rendered over the game. This plugin creates one, calls its JavaScript, and receives a call from it:
using SkyrimForge;
using SkyrimForge.Events;
using SkyrimForge.PrismaUi;
using System.Threading.Tasks;
namespace ViewPlugin;
public sealed class ViewPlugin(PrismaUiApi prisma, IGameEvents events, ILog log) : IPlugin
{
public void Start()
{
events.OnInputLoaded.Subscribe(_ =>
{
PrismaView view = prisma.CreateView("view-plugin/index.html");
view.RegisterJSListener("sendToPlugin", argument => log.Write($"The page sent {argument}."));
view.OnDomReady.Subscribe(OnDomReadyAsync);
});
}
private async Task OnDomReadyAsync(DomReadyEventArgs args)
{
args.View.InteropCall("setStatus", "Hello from the plugin.");
string title = await args.View.Invoke("document.title");
log.Write($"The page's title is {title}.");
}
}
The page declares the function the plugin calls and calls the function the plugin registered:
<p id="status"></p>
<script>
function setStatus(text) {
document.getElementById("status").textContent = text;
}
// Prisma UI binds sendToPlugin after the page finishes loading.
var bound = setInterval(function () {
if (typeof sendToPlugin === "function") {
clearInterval(bound);
sendToPlugin("The page loaded.");
}
}, 50);</script>
Calling the Page
InteropCallcalls a function the page has declared, passing one string.Invokeevaluates JavaScript and returns the expression's value as text, such asundefinedor[object Object]. It returns an empty string where the script throws or does not parse.
Await Invoke. Blocking on it on the game's thread or in queued work can deadlock, because the result arrives as queued work.
Receiving Calls
RegisterJSListener registers a global function the page can call. Prisma UI binds the name after the page finishes loading, which can follow OnDomReady.
A script that runs during the load tests for the function first, as the page above does. An event handler such as a button's click handler can call it directly.
Threads
Callbacks run as queued work, so the rules for ITaskQueue apply. An exception a callback throws is logged.
Focus and Visibility
A hidden view cannot take focus, so call Show before Focus. Focus disables the player's controls until Unfocus. disableFocusMenu omits Prisma UI's focus menu, which draws the cursor.
Typing
Skyrim acquires the keyboard exclusively, so a focused page receives clicks but no keys. Media Keys Fix removes that exclusive access. A mod with text input in a page should list it as a requirement.
Lifetime
A view survives a save load, and only Destroy releases it. After Destroy, members have no effect.
Debugging
Warning and Error messages from the page's JavaScript console reach the plugin's log. Subscribe to OnConsoleMessage to receive every message, if PrismaUiApi.ConsoleMessagesSupported is true.
CreateInspectorView creates a developer view of the page's DOM. It requires the Ultralight SDK's inspector folder at Data\PrismaUI\inspector.