DebugConsole
A published deck's console output never reaches devtools: on
castle.xyz the deck runs in a sandboxed frame of its own, and in the
app it runs in a WebView. DebugConsole draws the deck's console as a
panel along the bottom of the deck itself, so it can be read on the
device the deck is running on.
DebugConsole.show()โ opens the panel. It holds the last 300 lines ofconsole.log,console.warnandconsole.error, plus uncaught errors and unhandled promise rejections. Aftersetup()that includes everything since the deck started; in a deck that never callssetup(), only what comes after the firstshow(). The panel has Clear and Hide buttons.DebugConsole.hide()โ closes the panel. Lines keep being recorded.DebugConsole.lines(): DebugConsoleLine[]โ the recorded lines, oldest first, each{ level: "log" | "warn" | "error", text, time }withtimefromDate.now(), for a deck that draws its own.
The panel covers the bottom of the deck and takes touches there, so open it from a gesture or a debug option the deck controls, and remove that before the deck is for players:
import { DebugConsole } from "castle-web-sdk";
// Three fingers on the card toggles the console.
let open = false;
window.addEventListener("touchstart", (event) => {
if (event.touches.length === 3) {
open = !open;
if (open) DebugConsole.show();
else DebugConsole.hide();
}
});
To open it without changing the deck, the deck's owner adds ?debug=1
to the deck's address on castle.xyz (https://castle.xyz/d/<deck id>?debug=1).
The page checks that the signed-in viewer owns the deck, and only then
opens the console as the deck starts; anyone else gets the deck as
usual. It needs a deck saved with SDK 0.4.56 or later, and it works on
the website only. In the Castle app, use DebugConsole.show().