feat: the theatre browser (client 1.3.3)

The game page can put a web page on the theatre's screen for its player
alone, when the server allows it (the admin panel's switch).

- the page is a <webview> of its own partition (aj-browser): no preload,
  sandboxed, no plugins, no webviews of its own; any other partition is
  refused. it loads http(s) only and opens links in place; its session
  denies every permission and download, and its user agent names no
  Electron or Burrow.
- placed and clipped as the game page says (where the screen is and what
  the game draws over it), and closed with the game.
- the page asks with ipc "browser"; it is told "browserSupported" when
  this client can, and "browserState" for back, forward and the address.
  a webview made inside a webview's ipc handler crashed the window, so
  the message is handled a moment later.
- the old "Theatre browser (experimental)" tick under Advanced is gone:
  the server turns it on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
BurrowdevandClaude Opus 5.5 committed 2026-10-21 20:50:59 +03:00
1 parent 66f0c80430
commit 17347462cc
4 files changed
+188 -3

No files matched your search

+120
View File
@@ -259,6 +259,12 @@
width: min(100vw, calc((100vh - var(--bar-height)) * 900 / 550));
height: min(calc(100vh - var(--bar-height)), calc(100vw * 550 / 900));
}
/* the theatre's browser, over the theatre screen (theatreBrowser below) */
#theatre-browser-view {
position: absolute;
z-index: 1;
background: #fff;
}
#loading {
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
@@ -1077,6 +1083,7 @@
webview.remove();
webview = null;
}
theatreBrowser.close();
session = null;
$("game").hidden = true;
$("login").hidden = false;
@@ -1121,12 +1128,117 @@
$("hud").textContent = "HUD";
};
// the theatre's browser (experimental; the server's admin turns it on
// for its game page): the game page (the server's game.html) says where the
// theatre screen is and what to show, and a webview of its own is laid
// over it here, in a session that keeps nothing (main.js). nothing of
// it goes to the server, and it sees nothing of the game.
const theatreBrowser = (() => {
let view = null;
let ready = false; // a webview answers nothing before its first dom-ready
const webAddress = text => {
try {
const url = new URL(String(text));
return url.protocol === "https:" || url.protocol === "http:" ? url.href : null;
}
catch (err) {
return null;
}
};
const tell = () => {
if (view && ready && webview) {
let url = "";
try {
url = view.getURL();
}
catch (err) {
// not attached yet
}
webview.send("browserState", {url, back: view.canGoBack(), forward: view.canGoForward(), loading: view.isLoading()});
}
};
const close = () => {
if (view) {
view.remove();
view = null;
ready = false;
}
};
const open = url => {
if (view && ready) {
view.loadURL(url);
return;
}
if (view) {
view.src = url;
return;
}
view = document.createElement("webview");
view.id = "theatre-browser-view";
view.setAttribute("partition", "aj-browser");
view.src = url;
view.style.visibility = "hidden";
view.addEventListener("dom-ready", () => {
ready = true;
tell();
});
for (const name of ["did-navigate", "did-navigate-in-page", "did-start-loading", "did-stop-loading", "did-fail-load"]) {
view.addEventListener(name, tell);
}
$("stage").append(view);
};
// where: {x, y, w, h} in the game page's pixels, `clip` its CSS
// clip-path (what the game draws over it cut out), `shown`.
const place = where => {
if (!view || !webview || !where) {
return;
}
const game = webview.getBoundingClientRect();
const stage = $("stage").getBoundingClientRect();
const number = value => (Number.isFinite(Number(value)) ? Number(value) : 0);
view.style.left = `${game.left - stage.left + number(where.x)}px`;
view.style.top = `${game.top - stage.top + number(where.y)}px`;
view.style.width = `${Math.max(0, number(where.w))}px`;
view.style.height = `${Math.max(0, number(where.h))}px`;
view.style.clipPath = typeof where.clip === "string" && /^(?:none|polygon\(evenodd,[0-9a-z%.,\s]*\))$/.test(where.clip) ? where.clip : "none";
view.style.visibility = where.shown === true ? "visible" : "hidden";
};
return {
close,
// one message from the game page: {action, url?, where?}
handle(message) {
if (!message || typeof message !== "object") {
return;
}
const url = webAddress(message.url);
if (message.action === "go" && url) {
open(url);
}
else if (message.action === "close") {
close();
}
else if (view && ready && message.action === "back" && view.canGoBack()) {
view.goBack();
}
else if (view && ready && message.action === "forward" && view.canGoForward()) {
view.goForward();
}
else if (view && ready && message.action === "reload") {
view.reload();
}
place(message.where);
tell();
},
};
})();
const openGame = () => {
// A reload keeps the sound as it was; a login starts as the setting says.
const muted = webview ? isMuted() : fieldValue("start-muted");
if (webview) {
webview.remove();
}
theatreBrowser.close();
// A fresh webview each time: the page and the plugin start clean.
webview = document.createElement("webview");
webview.setAttribute("plugins", "");
@@ -1135,6 +1247,8 @@
webview.addEventListener("dom-ready", () => {
setMuted(muted);
webview.send("flashVarsReady", session.flashVars);
// this client can show the theatre's browser; the server says whether it is offered
webview.send("browserSupported", true);
}, {once: true});
webview.addEventListener("did-fail-load", event => {
if (event.isMainFrame) {
@@ -1166,6 +1280,12 @@
// main.js opens http and https addresses only
window.client.openPage(String(event.args[0]));
}
else if (event.channel === "browser") {
// not inside this handler: Electron 11 takes the whole window
// down when a webview is made while another's message is handled.
const message = event.args[0];
setTimeout(() => theatreBrowser.handle(message), 0);
}
else if (event.channel === "ownVideo") {
// the player's own theatre video (the game page's link box): main.js
// lets that one address load, then the page plays it.