Docs: web panel API
Plugin contract (docs/WEB_PANEL.md) and changelog for the v93 web panel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4e30b16bf5
commit
6918e6736f
2 changed files with 331 additions and 0 deletions
43
Changelog/2026-11-07-web-panel.md
Normal file
43
Changelog/2026-11-07-web-panel.md
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# In-game web panel: plugin API v93
|
||||
|
||||
Branch `up/web-panel`, from upstream `main` 418d80b. Not deployed. The API number 93 is provisional
|
||||
(upstream may take 93 first; it renumbers on merge). CoreCLR engine only.
|
||||
|
||||
## What changed
|
||||
|
||||
- Four new function slots at the end of the plugin API table (`WebPanelOpenFn`, `WebPanelNavigateFn`,
|
||||
`WebPanelCloseFn`, `WebPanelGetStateFn`), and SDK wrappers on `RynthCoreHost`: `HasWebPanel`,
|
||||
`OpenWebPanel(WebPanelOptions)`, `NavigateWebPanel`, `CloseWebPanel`, `GetWebPanelState`. Types are in
|
||||
`RynthCore.PluginSdk/WebPanelTypes.cs`. No call blocks its caller.
|
||||
- `WebPanel/WebPanelHost.cs` (engine): one WebView2 panel over the game window, on its own STA thread, with an
|
||||
unowned popup window, a caption bar with a close box, a remembered size and place, and Escape / Alt+F4 / `X` to close.
|
||||
- Navigation allowlist (`WebPanelUrlPolicy`): https only, default port, no user info, exact host or `*.suffix`
|
||||
(`*.x.com` does not match `x.com`: list both). Off-list navigations, pop-ups and custom-scheme launches never
|
||||
load in the panel; an absolute http(s) URL goes to the system browser, anything else is dropped.
|
||||
- Per-world, per-key WebView2 profile (`WebPanelProfile`): the plugin's key is lower-cased and hashed, and the world is added.
|
||||
- `/rc webpanel [status|close]`: a redacted one-line report, and a close.
|
||||
- `engine.json` `"WebPanel": false`: kill switch. `OpenWebPanel` then answers `Unavailable`.
|
||||
- `RynthCore.PluginSdk.targets` already raised a shared-SDK release build's `RynthPluginMinEngineApi` below 88 to the
|
||||
SDK's API; that is now 93 for every such plugin. Plugins that must run on older cores declare 88 or higher.
|
||||
- `tools\WebPanelHarness`: an offline 32-bit harness for the host (see the doc).
|
||||
- Docs: `docs/WEB_PANEL.md` is the plugin contract.
|
||||
|
||||
## How it behaves
|
||||
|
||||
- The panel never takes focus from another program. It takes the foreground only if the foreground window already
|
||||
belongs to the game, and it hides while another program is in front.
|
||||
- Logs and chat never carry a URL's query, fragment or user info (the launch code rides in the query).
|
||||
- Failures: the panel fails only when the WebView2 browser process or the main renderer exits, or the renderer is
|
||||
reported unresponsive 3 times in 30 s. Other process failures are logged. `RuntimeMissing` / `CreateFailed` fall back to
|
||||
the system browser when the plugin asked for it (the default). Page permission `ClipboardRead` is allowed only
|
||||
for allowlisted origins; the rest are denied.
|
||||
- The NativeAOT engine flavour has no web panel: the slots stay zero and `HasWebPanel` is false.
|
||||
|
||||
## Tests
|
||||
|
||||
`tools/WebPanelTests`: URL allowlist and redaction, window visibility and layout, profile folder, the ABI glue.
|
||||
`tools/WebPanelHarness`: the host in a collectible load context against real WebView2 (needs a desktop, the
|
||||
WebView2 runtime and the x86 .NET 10 runtime; not part of `Run-AllTests.ps1`). Checks that need another program in
|
||||
the foreground report UNVERIFIED and are owner in-game checks.
|
||||
|
||||
Not yet tested in game.
|
||||
288
docs/WEB_PANEL.md
Normal file
288
docs/WEB_PANEL.md
Normal file
|
|
@ -0,0 +1,288 @@
|
|||
# In-game web panel (plugin API v93)
|
||||
|
||||
A plugin can show a web page in a panel over the Asheron's Call window. The page runs in WebView2.
|
||||
The engine owns the window, the navigation allowlist, focus and the lifetime; the plugin passes a URL,
|
||||
an allowlist and a profile key, then polls for state. This file is the contract plugin authors build against.
|
||||
|
||||
The API number 93 is provisional: upstream may take 93 first, in which case it renumbers on merge
|
||||
(`PluginContractVersion.cs`). Write `HasWebPanel` checks, not `Version >= 93` checks, and nothing breaks.
|
||||
|
||||
## Calls
|
||||
|
||||
The SDK wrappers are on `RynthCoreHost` (`RynthCore.PluginSdk`). None of them blocks, and all of them are safe
|
||||
to call from any thread (AC's main thread, the plugin pump, an ImGui draw). Never wait on the panel: call
|
||||
`OpenWebPanel`, return, and poll `GetWebPanelState`.
|
||||
|
||||
| Call | Does |
|
||||
|---|---|
|
||||
| `bool HasWebPanel` | True only on an engine at API 93 or newer that fills all four function slots. Check it before any other call. |
|
||||
| `int OpenWebPanel(WebPanelOptions)` | Opens the panel, or replaces the open one. Returns a handle > 0, or a negative `WebPanelResult`. |
|
||||
| `int NavigateWebPanel(int handle, string url)` | Points the open panel at a URL. `1` queued. |
|
||||
| `int CloseWebPanel(int handle)` | Closes the panel. `1` queued, `0` already closed. |
|
||||
| `WebPanelStatus GetWebPanelState(int handle, out WebPanelState state)` | Where the panel is. |
|
||||
|
||||
On an engine without the feature the wrappers return `Unavailable` (`GetWebPanelState` returns `None`).
|
||||
The NativeAOT engine flavour has no web panel: it leaves the four slots zero, so `HasWebPanel` is false there.
|
||||
Setting `"WebPanel": false` in `engine.json` is a kill switch: `OpenWebPanel` then returns `Unavailable`. A
|
||||
panel that is already open stays until it is closed.
|
||||
|
||||
### WebPanelOptions
|
||||
|
||||
| Field | Meaning |
|
||||
|---|---|
|
||||
| `Url` (required) | At most 4096 UTF-8 bytes. Must pass the same allowlist test as every other URL (below). |
|
||||
| `Allowlist` (required) | 1 to 16 entries; no `\n` inside an entry. |
|
||||
| `ProfileKey` | Opaque string, at most 256 UTF-8 bytes. Default empty. |
|
||||
| `Title` | Caption text, at most 128 UTF-8 bytes. Default empty, which shows "RynthCore". |
|
||||
| `WidthPercent`, `HeightPercent` | 0 means 88; otherwise clamped to 30..100. Used only when no layout has been remembered. |
|
||||
| `Flags` | `WebPanelFlags`. Default `FallbackToBrowser`. |
|
||||
|
||||
`WebPanelFlags`:
|
||||
|
||||
| Flag | Value | Meaning |
|
||||
|---|---|---|
|
||||
| `FallbackToBrowser` | 1 | If the panel cannot start (no WebView2 runtime, creation failed), the engine opens the URL in the system browser. |
|
||||
| `PageKeepsEscape` | 2 | Escape goes to the page instead of closing the panel. |
|
||||
|
||||
Bit 4 is reserved. Unknown bits are ignored.
|
||||
|
||||
### Return codes (`WebPanelResult`)
|
||||
|
||||
| Value | Name | Meaning |
|
||||
|---|---|---|
|
||||
| 1 | `Queued` | Navigate or Close accepted. |
|
||||
| 0 | `AlreadyClosed` | Close: the panel was already Closed or Failed. |
|
||||
| -1 | `BadArgs` | Empty URL or allowlist, more than 16 entries, a bad allowlist entry, a string over its byte limit, invalid UTF-8, or a struct `Size` that is too small. |
|
||||
| -2 | `UrlNotAllowed` | The URL is not allowed by the allowlist. See Navigate below. |
|
||||
| -3 | `NoGameWindow` | There is no game window to cover. |
|
||||
| -4 | `Unavailable` | Older engine, NativeAOT engine, `engine.json` kill switch, or an internal error. |
|
||||
| -5 | `ShuttingDown` | The engine is shutting down. |
|
||||
| -6 | `StaleHandle` | The handle is not the live panel (Navigate, Close). |
|
||||
| -7 | `RuntimeMissing` | State `Error` only: the WebView2 runtime is not installed. |
|
||||
| -8 | `CreateFailed` | State `Error` only: the panel window or WebView2 could not be created. |
|
||||
| -9 | `ProcessFailed` | State `Error` only: the WebView2 browser or renderer process died or hung. |
|
||||
|
||||
`OpenWebPanel` returns a handle (> 0) as soon as the request is queued. The panel loads after that, so a handle
|
||||
does not mean the page loaded. A later failure shows up in the state as `Failed` with `Error` set.
|
||||
|
||||
### State
|
||||
|
||||
`GetWebPanelState` returns the status and fills `WebPanelState(Handle, Status, Flags, Error, LastHttpStatus, NavigationCount)`.
|
||||
|
||||
| `WebPanelStatus` | Value | Meaning |
|
||||
|---|---|---|
|
||||
| `None` | 0 | Returned by the wrapper (not by the engine) on an older engine, bad arguments, or while the engine shuts down. |
|
||||
| `Starting` | 1 | Open accepted; the WebView2 window is being created. |
|
||||
| `Loading` | 2 | A navigation has started. |
|
||||
| `Ready` | 3 | A navigation completed. This means the page answered, not that it succeeded: check `LastHttpStatus`. |
|
||||
| `Closed` | 4 | Closed by the plugin, the player, or the engine. |
|
||||
| `Failed` | 5 | See `Error`. |
|
||||
| `Superseded` | 6 | The handle is not the live panel: a newer Open replaced it, or no panel was ever opened. |
|
||||
|
||||
`WebPanelStateFlags`: `Visible` = 1, `Focused` = 2, `OpenedInBrowser` = 4 (the engine's fallback opened the URL in
|
||||
the system browser). `LastHttpStatus` is the last non-zero HTTP status of a completed navigation. `NavigationCount`
|
||||
counts navigations that started on an allowed URL since Open (the `about:blank` the engine uses to clear the page is
|
||||
not counted).
|
||||
|
||||
## Allowlist
|
||||
|
||||
The allowlist decides what the panel may show. It is checked on Open, on Navigate, on every navigation the page
|
||||
starts itself, and on pop-up requests. Entries are matched against the URL's host:
|
||||
|
||||
- `host`: exactly that host. `example.com` matches `example.com` only.
|
||||
- `*.suffix`: any subdomain, at any depth, but not the suffix itself. `*.example.com` matches `a.example.com`
|
||||
and `a.b.example.com`, and does **not** match `example.com`. To allow both, list both entries.
|
||||
- The suffix after `*.` must contain a dot, so `*.com` is rejected.
|
||||
- No scheme, path, port or other `*`. Entries are lower-cased and trimmed; blank lines are ignored.
|
||||
- Entries are ASCII: letters, digits, `-` and `.`; each label 1 to 63 characters, not starting or ending with `-`;
|
||||
at most 253 characters per entry. Write an internationalised host in its punycode form (`xn--...`).
|
||||
- 1 to 16 entries, and the joined list must fit in 8192 bytes.
|
||||
|
||||
A URL is allowed only if it is `https`, has no user info, uses the default port (443), and its host matches an entry
|
||||
(compared in lower case, one trailing dot ignored, IDN hosts in punycode). `about:blank` is also always allowed.
|
||||
That means an `http:` URL and a URL with a port are never allowed, whatever the list says.
|
||||
|
||||
### What the engine does with a URL that is not allowed
|
||||
|
||||
- `OpenWebPanel`: returns `UrlNotAllowed` and opens nothing.
|
||||
- `NavigateWebPanel`: returns `UrlNotAllowed`, and the engine opens the URL in the system browser instead if it
|
||||
is absolute `http` or `https` without user info. Anything else is dropped and logged.
|
||||
- A navigation the page starts: cancelled, then handled the same way as Navigate.
|
||||
- `window.open` and other new-window requests: never a second window. An allowed URL loads in the panel; any
|
||||
other goes to the system browser as above.
|
||||
- Custom-scheme launches (`foo://`): blocked and logged.
|
||||
|
||||
When the engine opens the system browser for an off-list URL it writes `[RynthCore] Opened <host> in your web
|
||||
browser.` to chat. Only the host is shown. Logs and chat never contain a URL's query, fragment or user info (the
|
||||
launch code of a login URL rides in the query), only `scheme://host[:port]/path`.
|
||||
|
||||
### Page permissions
|
||||
|
||||
Everything the page asks permission for is denied, except `ClipboardRead`, which is allowed only for a frame whose
|
||||
URL is on the allowlist (a blank frame gets none). Developer tools, browser accelerator keys, the status bar,
|
||||
host objects, web messages and password autosave are all off.
|
||||
|
||||
## Profile key
|
||||
|
||||
WebView2 keeps cookies and storage in a profile folder. The plugin passes an opaque key; the engine builds the folder:
|
||||
|
||||
```
|
||||
<LocalAppData>\RynthCore\WebPanel\<world>\<hex>
|
||||
```
|
||||
|
||||
- `<hex>`: the key is trimmed and lower-cased, and the first 16 bytes of its SHA-256 (of the UTF-8 text) are written
|
||||
as lower-case hex. An empty key is the folder `default`.
|
||||
- `<world>`: the connected world's name, with every character outside `A-Z a-z 0-9 space _ -` replaced by `_`,
|
||||
at most 64 characters; empty becomes `_default`.
|
||||
|
||||
So the same key on two worlds is two separate profiles, and `Key` and `key` are the same profile. Use a key that
|
||||
names the site or account. Do not put a secret in it.
|
||||
Opening with a different profile than the last Open tears WebView2 down and creates it again; same profile, the
|
||||
WebView2 environment is reused.
|
||||
|
||||
## Window, focus and close
|
||||
|
||||
- The panel is a window over the game's client area, with a 28 px caption bar (the title, and an `X` close box).
|
||||
The caption bar drags it; the frame resizes it. Minimum size is 480 x 320, or the whole client if smaller.
|
||||
- The panel's size and place are remembered as fractions of the game window in
|
||||
`<LocalAppData>\RynthCore\WebPanel\layout.json`, shared by all profiles. A valid stored layout wins over
|
||||
`WidthPercent` / `HeightPercent`.
|
||||
- **The panel never takes focus from another program.** On Open it takes the foreground only if the foreground
|
||||
window already belongs to the game's process; if the player is in another program (or mid alt-tab) it does not.
|
||||
It hides while another program is in the foreground, and comes back when the game is. The panel's own
|
||||
WebView2 dialogs (alert, file picker) do not count as another program.
|
||||
- The panel runs on its own thread, so a slow page never stalls the game's thread or the plugin pump.
|
||||
|
||||
The panel closes (status `Closed`) when:
|
||||
|
||||
- the plugin calls `CloseWebPanel(handle)`;
|
||||
- the player presses Escape (unless `PageKeepsEscape` is set), clicks the `X`, or presses Alt+F4 on the panel;
|
||||
- the game window goes away;
|
||||
- `/rc webpanel close` runs;
|
||||
- a newer `OpenWebPanel` replaces it (the old handle then reads `Superseded`).
|
||||
|
||||
Closing hides the panel and loads `about:blank`; the WebView2 environment stays for the next Open. `CloseWebPanel`
|
||||
returns `1` (queued) for the live panel, `0` if it is already `Closed` or `Failed`, and `-6` for any other handle.
|
||||
After `Closed` or `Failed`, `NavigateWebPanel` returns `StaleHandle`.
|
||||
At engine shutdown the panel is torn down after the plugins' own Shutdown, so a plugin may still call Close there.
|
||||
|
||||
## Failures
|
||||
|
||||
The state is `Failed`, with `Error` set, and the panel is hidden.
|
||||
|
||||
- `RuntimeMissing` / `CreateFailed`: the panel could not start. With `FallbackToBrowser`, and only if no navigation
|
||||
has happened yet and the URL is absolute `http` or `https`, the engine opens the URL in the system browser, sets
|
||||
`OpenedInBrowser`, and tells the player in chat. The plugin must not open it a second time.
|
||||
- `ProcessFailed`: the engine fails the panel for only these causes: the WebView2 browser process exited
|
||||
(`BrowserProcessExited`), the page's main renderer exited (`RenderProcessExited`), or the renderer is reported
|
||||
unresponsive (`RenderProcessUnresponsive`) 3 times within 30 seconds of the first report (a completed
|
||||
navigation or a new Open resets that count). Every other kind of process failure (GPU, utility, a
|
||||
frame-only renderer, and so on) is logged and the panel is kept. There is never a browser fallback for
|
||||
`ProcessFailed`: a navigation already ran, so the launch code is spent. Open again to retry; WebView2 is
|
||||
recreated.
|
||||
|
||||
## Plugins that must run on older cores
|
||||
|
||||
A plugin built against this SDK runs against the installed core's `Runtime\PluginShared` copy of the SDK. If you want
|
||||
the plugin to keep working on a core without the web panel, with ShellExecute as the fallback:
|
||||
|
||||
1. **Declare `RynthPluginMinEngineApi` at the plugin's true minimum.** In release builds
|
||||
(`-p:RynthPluginSharedSdk=true`, as `Publish-Update.ps1` and `Build-Installer.ps1` pass), a declared minimum
|
||||
*below 88* is raised to the API of the SDK the plugin was built with (93 now), and the launcher then holds the
|
||||
plugin back from older cores, which kills the fallback (`RynthCore.PluginSdk.targets`: `RynthCoreManagedPluginApi`
|
||||
is 88). There is no separate opt-out property: declaring a minimum of **88 or higher** is the opt-out, and a
|
||||
declared 88 or higher is used as it is. Declare the lowest API your plugin really needs at load, and make
|
||||
sure every call newer than that sits behind its `Has*` check. (`RynthPluginManifest=false` drops the manifest
|
||||
altogether, and with it the minimum; do not use it for this.) The build prints a message when it raises a minimum.
|
||||
2. **Put every reference to `HasWebPanel`, `OpenWebPanel`, `WebPanelOptions` and the other WebPanel types in one helper
|
||||
marked `[MethodImpl(MethodImplOptions.NoInlining)]`, taking only strings,** and call it inside
|
||||
`try { } catch (MissingMethodException) { } catch (TypeLoadException) { }`. An older `PluginShared` SDK without
|
||||
these members fails the method (or the type load), not the plugin's load.
|
||||
3. **Fall back to ShellExecute** when the helper throws, when `HasWebPanel` is false, or when `OpenWebPanel` returns
|
||||
`Unavailable`, `NoGameWindow` or `ShuttingDown`. Do nothing more when the state is `Failed` with `OpenedInBrowser`
|
||||
(the engine already opened it). Never fall back on `UrlNotAllowed` (or `BadArgs`): those are plugin bugs, and
|
||||
sending the URL to the browser hides them. Only pass absolute `http` or `https` URLs without user info to ShellExecute.
|
||||
|
||||
```csharp
|
||||
using System.Runtime.CompilerServices;
|
||||
using RynthCore.PluginSdk;
|
||||
|
||||
// Returns false when the caller should open the page in the system browser itself.
|
||||
private bool TryShowPanel(string url, string profileKey)
|
||||
{
|
||||
try { return ShowPanelCore(url, profileKey); }
|
||||
catch (MissingMethodException) { return false; }
|
||||
catch (TypeLoadException) { return false; }
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private bool ShowPanelCore(string url, string profileKey)
|
||||
{
|
||||
if (!Host.HasWebPanel) return false;
|
||||
int h = Host.OpenWebPanel(new WebPanelOptions
|
||||
{
|
||||
Url = url,
|
||||
Allowlist = new[] { "example.com", "*.example.com" },
|
||||
ProfileKey = profileKey,
|
||||
Title = "Example",
|
||||
});
|
||||
if (h > 0) { _panelHandle = h; return true; }
|
||||
var r = (WebPanelResult)h;
|
||||
return !(r == WebPanelResult.Unavailable || r == WebPanelResult.NoGameWindow || r == WebPanelResult.ShuttingDown);
|
||||
}
|
||||
```
|
||||
|
||||
Poll the state from a second helper written the same way (`GetWebPanelState` and `WebPanelState` are SDK types too).
|
||||
|
||||
## Native layout (for callers that do not use the SDK wrappers)
|
||||
|
||||
`RynthCoreAPI` gains four function pointers at the end of the table, in this order, all `cdecl`:
|
||||
`int WebPanelOpen(WebPanelOpenNative*)`, `int WebPanelNavigate(int handle, byte* url)`,
|
||||
`int WebPanelClose(int handle)`, `int WebPanelGetState(int handle, WebPanelStateNative*)`.
|
||||
Test `Version >= 93` before reading them: an older engine's table is shorter.
|
||||
|
||||
`WebPanelOpenNative` (pack 4, 48 bytes on x86): `uint Size`, `uint Flags`, `byte* Url`, `byte* Allowlist`
|
||||
(`\n`-separated), `byte* ProfileKey` (may be null), `byte* Title` (may be null), `int WidthPercent`, `int HeightPercent`,
|
||||
`uint Reserved[4]`. All strings are NUL-terminated UTF-8; the engine copies them before the call returns. It accepts
|
||||
`Size` of 32 or more.
|
||||
|
||||
`WebPanelStateNative` (pack 4, 48 bytes): `uint Size`, `int Handle`, `int Status`, `uint Flags`, `int Error`,
|
||||
`int LastHttpStatus`, `uint NavigationCount`, `uint Reserved[5]`. The engine accepts `Size` of 28 or more and writes
|
||||
only the fields before `Reserved`. At the native level `WebPanelGetState` returns the status (a handle that is not the
|
||||
live panel reads 6) or a negative code (`-1` bad arguments, `-5` shutting down); the wrapper turns a negative into `None`.
|
||||
|
||||
## /rc webpanel
|
||||
|
||||
- `/rc webpanel` or `/rc webpanel status`: one line, redacted (no query, fragment or user info): thread state,
|
||||
handle, status, error, HTTP status, navigation count, WebView2 environments created, visible / focused / in browser,
|
||||
the WebView2 browser process id, the URL as `scheme://host/path`, whether the `engine.json` setting is on, and the
|
||||
free address space. It never opens a URL.
|
||||
- `/rc webpanel close`: closes the live panel. Replies `web panel: closing.`, `web panel: already closed.`, or
|
||||
`web panel: nothing to close.` when no panel was ever opened.
|
||||
|
||||
## Offline harness
|
||||
|
||||
`tools\WebPanelHarness` runs the real panel host in a 32-bit stand-in for the game, with a fake game window, a fake
|
||||
plugin pump and a collectible load context like the engine's. Pages are served from local folders through
|
||||
virtual hosts (`panel.test`, `other.test`), so it needs no network.
|
||||
|
||||
```
|
||||
cd tools\WebPanelHarness
|
||||
dotnet run -c Release
|
||||
```
|
||||
|
||||
Prerequisites:
|
||||
|
||||
- A desktop session (it opens windows) and the Evergreen WebView2 runtime.
|
||||
- A **32-bit dotnet host**: the x86 .NET 10 runtime (the x86 SDK from `BUILD.md` brings it). The harness
|
||||
refuses to run unless the process is 32-bit like acclient (`FAIL Bitness`).
|
||||
- `--foreground` (or `WEBPANEL_HARNESS_FOREGROUND=1`) is an opt-in: the harness then asks Windows to put its fake game
|
||||
window in the foreground, so the foreground-dependent checks (Escape hands focus back, same-process visibility)
|
||||
can run. Without the opt-in, or when Windows refuses the request because you are active in another program,
|
||||
those checks print `UNVERIFIED`. `--payload=<dir>` overrides the payload folder.
|
||||
- It posts input to its own windows only and never uses `SendInput`, so it does not steer a live game client on
|
||||
the same desktop. It is not part of `scripts\Run-AllTests.ps1`.
|
||||
|
||||
Each check prints `ok <name>`, `FAIL <name>: ...` or `UNVERIFIED <name>: ...` (not provable offline, an owner in-game
|
||||
check). Exit code 0 = all ok, 1 = a FAIL, 2 = no FAIL but something UNVERIFIED. The output is also written to
|
||||
`harness-output.txt` under `%TEMP%\rynth-webpanel-harness\<timestamp>\`.
|
||||
Loading…
Reference in a new issue