From 0d56a8bfd0d64d1e16f5eb26d70e08e7d29d40ae Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Wed, 18 Nov 2026 10:27:16 +0100 Subject: [PATCH 001/173] Diagnose inherited Snap paths in WebKitGTK --- docs/WEBKITGTK.md | 28 +++++++++++++++++++ include/webfront/frontend/WebKitGTK.hpp | 2 ++ include/webfront/frontend/WebKitGTKPolicy.hpp | 25 +++++++++++++++++ test/unit/WebKitGTKPolicyTests.cpp | 13 +++++++++ 4 files changed, 68 insertions(+) diff --git a/docs/WEBKITGTK.md b/docs/WEBKITGTK.md index cab3729a..6589500c 100644 --- a/docs/WEBKITGTK.md +++ b/docs/WEBKITGTK.md @@ -61,6 +61,34 @@ On WSLg, preserve its supplied display variables and runtime directory. Native Wayland and WSLg require manual verification on those desktops; automated coverage uses X11/Xvfb. No WSL-specific library environment changes are applied. +### Snap-hosted editor terminals + +A terminal inherited from a Snap-packaged editor can expose Snap library or GTK +module paths to a host application. This has been observed with VSCodium: the +system WebKit network process loaded Snap's `libpthread.so.0` and failed with a +`GLIBC_PRIVATE` symbol error. The particular variable responsible has not been +isolated; other Snap-hosted editors, including VS Code, may pass similar paths, +but have not been verified. WebFront warns when the common variables below contain +`/snap/` or `/var/lib/snapd/snap/` paths outside verified Snap confinement. This +heuristic does not prove a failure or cover every possible path and does not alter +the environment. The warning uses the WebFront logger and can be filtered by the +application. + +If this failure occurs, start the host application with a clean environment for +these variables, replacing the executable path as needed: + +```bash +env -u LD_LIBRARY_PATH -u LD_PRELOAD \ + -u GIO_MODULE_DIR -u GTK_PATH -u GTK_EXE_PREFIX \ + -u GTK_IM_MODULE_FILE -u GSETTINGS_SCHEMA_DIR -u LOCPATH \ + ./examples/WebFrontLifeDeveloper +``` + +This removes all values of those variables for the application and its children, +including legitimate custom configuration. Adjust the launcher if it needs any of +them. WebFront cannot safely remove them globally: the host application and other +threads may depend on them, and WebKit may launch child processes later. + Persistent data lives in `$XDG_DATA_HOME/webfront/-` and caches in `$XDG_CACHE_HOME/webfront/-`. Absolute XDG paths are honored; otherwise absolute `$HOME/.local/share` and `$HOME/.cache` are used. The stable hash diff --git a/include/webfront/frontend/WebKitGTK.hpp b/include/webfront/frontend/WebKitGTK.hpp index 091e08af..02bebc90 100644 --- a/include/webfront/frontend/WebKitGTK.hpp +++ b/include/webfront/frontend/WebKitGTK.hpp @@ -165,6 +165,8 @@ inline void requireMainThread() { inline void initialize(SandboxMode mode = SandboxMode::development) { requireMainThread(); + if (inheritedSnapToolkitPaths() && !snapConfinementVerified()) + log::warn("WebKitGTK: inherited Snap library or toolkit paths may break host WebKit processes; see docs/WEBKITGTK.md for a clean launch"); requireSandboxEnvironment(mode); static std::optional prepared; if (prepared && *prepared != mode) diff --git a/include/webfront/frontend/WebKitGTKPolicy.hpp b/include/webfront/frontend/WebKitGTKPolicy.hpp index acbc494f..feecf62b 100644 --- a/include/webfront/frontend/WebKitGTKPolicy.hpp +++ b/include/webfront/frontend/WebKitGTKPolicy.hpp @@ -2,6 +2,7 @@ #include "../ContentPolicy.hpp" +#include #include #include #include @@ -98,6 +99,30 @@ enum class SandboxMode { development, distribution }; #if defined(__linux__) +// These variables can point the host toolkit or its children at libraries and modules +// from a different runtime. Inspect names only in diagnostics; values may be private. +inline bool containsSnapPath(std::string_view value) { + while (!value.empty()) { + const auto end = value.find_first_of(": \t\n"); + const auto part = value.substr(0, end); + if (part.starts_with("/snap/") || part.starts_with("/var/lib/snapd/snap/")) + return true; + if (end == std::string_view::npos) + break; + value.remove_prefix(end + 1); + } + return false; +} + +inline bool inheritedSnapToolkitPaths() { + constexpr std::array names = {"LD_LIBRARY_PATH", "LD_PRELOAD", "GIO_MODULE_DIR", "GTK_PATH", "GTK_EXE_PREFIX", + "GTK_IM_MODULE_FILE", "GSETTINGS_SCHEMA_DIR", "LOCPATH"}; + for (const auto* name : names) + if (const auto* value = std::getenv(name); value && containsSnapPath(value)) + return true; + return false; +} + // Development is the default, independently of optimization level. A distribution binary requires the sandbox; // an inherited environment variable cannot weaken its build policy. inline bool sandboxRequiredByEnvironment() { diff --git a/test/unit/WebKitGTKPolicyTests.cpp b/test/unit/WebKitGTKPolicyTests.cpp index c29d593c..79e104ac 100644 --- a/test/unit/WebKitGTKPolicyTests.cpp +++ b/test/unit/WebKitGTKPolicyTests.cpp @@ -19,6 +19,19 @@ using namespace webfront; using namespace webfront::frontend::detail::webkitgtk; } // namespace +#if defined(__linux__) +const Scenario webKitGTKSnapPaths{"WebKitGTK detects inherited Snap toolkit paths", [] { + then("recognizes path lists without mistaking unrelated paths for Snap", [] { + check(containsSnapPath("/snap/core20/current/lib")); + check(containsSnapPath("/usr/lib:/var/lib/snapd/snap/core/current/lib")); + check(containsSnapPath("/usr/lib/a.so /snap/core/current/lib/a.so")); + check(!containsSnapPath("/usr/lib:/home/user/snap/app")); + check(!containsSnapPath("/snapshots/lib:/snap")); + check(!containsSnapPath("")); + }); +}}; +#endif + const Scenario webKitGTKApplies{"WebKitGTK applies navigation policy without toolkit objects", [] { const detail::BoundContentPolicy policy; struct Case { From 6985c099f20ced53f6db1c9eb375c03537e75026 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Wed, 18 Nov 2026 11:17:47 +0100 Subject: [PATCH 002/173] Compare raw pointers in CaptureRegistration::reset Comparing std::shared_ptr found std::expected::operator== through ADL and made libc++ (AppleClang) recurse on its constraints. Compare the raw pointers instead. Fixes #606 --- include/webfront/frontend/Capture.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/webfront/frontend/Capture.hpp b/include/webfront/frontend/Capture.hpp index d501455d..81d85c2e 100644 --- a/include/webfront/frontend/Capture.hpp +++ b/include/webfront/frontend/Capture.hpp @@ -106,7 +106,7 @@ class CaptureRegistration { auto& registry = detail::captureRegistry(); { std::scoped_lock lock{registry.mutex}; - if (registry.provider == owned) + if (registry.provider.get() == owned.get()) registry.provider.reset(); } owned.reset(); From 59625fb20b7cf9ab00ff22367fd2babb6027cc24 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Wed, 18 Nov 2026 11:21:03 +0100 Subject: [PATCH 003/173] Respect environment variable path separators --- include/webfront/frontend/WebKitGTKPolicy.hpp | 18 ++++++++++++------ test/unit/WebKitGTKPolicyTests.cpp | 11 +++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/include/webfront/frontend/WebKitGTKPolicy.hpp b/include/webfront/frontend/WebKitGTKPolicy.hpp index feecf62b..3d5c2d0b 100644 --- a/include/webfront/frontend/WebKitGTKPolicy.hpp +++ b/include/webfront/frontend/WebKitGTKPolicy.hpp @@ -101,9 +101,9 @@ enum class SandboxMode { development, distribution }; // These variables can point the host toolkit or its children at libraries and modules // from a different runtime. Inspect names only in diagnostics; values may be private. -inline bool containsSnapPath(std::string_view value) { +inline bool containsSnapPath(std::string_view value, std::string_view separators = {}) { while (!value.empty()) { - const auto end = value.find_first_of(": \t\n"); + const auto end = value.find_first_of(separators); const auto part = value.substr(0, end); if (part.starts_with("/snap/") || part.starts_with("/var/lib/snapd/snap/")) return true; @@ -115,10 +115,16 @@ inline bool containsSnapPath(std::string_view value) { } inline bool inheritedSnapToolkitPaths() { - constexpr std::array names = {"LD_LIBRARY_PATH", "LD_PRELOAD", "GIO_MODULE_DIR", "GTK_PATH", "GTK_EXE_PREFIX", - "GTK_IM_MODULE_FILE", "GSETTINGS_SCHEMA_DIR", "LOCPATH"}; - for (const auto* name : names) - if (const auto* value = std::getenv(name); value && containsSnapPath(value)) + struct Variable { + const char* name; + std::string_view separators; + }; + constexpr std::array variables = {Variable{"LD_LIBRARY_PATH", ":;"}, Variable{"LD_PRELOAD", ": "}, + Variable{"GIO_MODULE_DIR", ""}, Variable{"GTK_PATH", ":"}, + Variable{"GTK_EXE_PREFIX", ""}, Variable{"GTK_IM_MODULE_FILE", ""}, + Variable{"GSETTINGS_SCHEMA_DIR", ""}, Variable{"LOCPATH", ":"}}; + for (const auto& [name, separators] : variables) + if (const auto* value = std::getenv(name); value && containsSnapPath(value, separators)) return true; return false; } diff --git a/test/unit/WebKitGTKPolicyTests.cpp b/test/unit/WebKitGTKPolicyTests.cpp index 79e104ac..711a12f4 100644 --- a/test/unit/WebKitGTKPolicyTests.cpp +++ b/test/unit/WebKitGTKPolicyTests.cpp @@ -23,10 +23,13 @@ using namespace webfront::frontend::detail::webkitgtk; const Scenario webKitGTKSnapPaths{"WebKitGTK detects inherited Snap toolkit paths", [] { then("recognizes path lists without mistaking unrelated paths for Snap", [] { check(containsSnapPath("/snap/core20/current/lib")); - check(containsSnapPath("/usr/lib:/var/lib/snapd/snap/core/current/lib")); - check(containsSnapPath("/usr/lib/a.so /snap/core/current/lib/a.so")); - check(!containsSnapPath("/usr/lib:/home/user/snap/app")); - check(!containsSnapPath("/snapshots/lib:/snap")); + check(containsSnapPath("/usr/lib:/var/lib/snapd/snap/core/current/lib", ":;")); + check(containsSnapPath("/usr/lib;/snap/core/current/lib", ":;")); + check(containsSnapPath("/usr/lib/a.so /snap/core/current/lib/a.so", ": ")); + check(!containsSnapPath("/home/user/cache /snap/test/immodules.cache")); + check(!containsSnapPath("/home/user/cache /snap/test/modules", ":")); + check(!containsSnapPath("/usr/lib:/home/user/snap/app", ":")); + check(!containsSnapPath("/snapshots/lib:/snap", ":")); check(!containsSnapPath("")); }); }}; From b369e72c16e89f9a9b09f456b1943a4327325609 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:13:07 +0100 Subject: [PATCH 004/173] Show the WebKitGTK window at its first frame, add a window background and cheaper font stacks (#611) --- docs/CHANGELOG.md | 6 ++ docs/WEBKITGTK.md | 17 ++++ examples/host-loop/HostLoopUI.hpp | 6 +- examples/life/ui/style.css | 2 +- include/webfront/frontend/WebKitGTK.hpp | 94 ++++++++++++++++++- include/webfront/frontend/Window.hpp | 36 ++++++- .../system/DeveloperIndexHtmlData.hpp | 30 +++--- .../webfront/system/FallbackIndexHtmlData.hpp | 63 ++++++------- js/core/bootstrap/index.html | 2 +- js/core/fallback/index.html | 2 +- js/developer/environment/bundles.json | 4 +- js/developer/starters/app/style.css | 2 +- test/unit/FrontendContractTests.cpp | 29 ++++++ 13 files changed, 233 insertions(+), 60 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index bc4d781c..7bf710d7 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,12 @@ these entries stays in the GitHub releases and the Git history. ## Unreleased +### Added +- Choose the colour under the page with `WindowOptions::background`, and read the start-up milestones of a WebKitGTK view with `WEBFRONT_STARTUP_TRACE=1` (#611, `docs/WEBKITGTK.md`). + +### Changed +- Show the WebKitGTK window when the page has painted its first frame, or after one second, instead of black at once; the embedded pages, the starter and the examples use the cheap `sans-serif` and `monospace` font stacks (#611, `docs/WEBKITGTK.md`). + ## [1.0.0] - 2026-11-17 WebFront 1.0 ships with developer environment 1.0.0. This release adds host-loop integration, developer tools and diff --git a/docs/WEBKITGTK.md b/docs/WEBKITGTK.md index cab3729a..3dd4e6aa 100644 --- a/docs/WEBKITGTK.md +++ b/docs/WEBKITGTK.md @@ -97,6 +97,23 @@ unit tests cover the policy decision table, null error diagnostics, preserving the first failure when a timeout or callback reports a later error, and the sandbox launcher check described below. +## Startup and first display + +The window is mapped at once, but almost transparent, and is shown when the page reports its first frame (two animation +frames after `DOMContentLoaded`) or after one second, whichever comes first, so a window is never presented black while +the page loads. Without a compositing manager the opacity is ignored and the window appears immediately, as before. A +page that never paints still shows the window after the delay, and the navigation timeout and its diagnostics are +unchanged. `WindowOptions::background` (`"#rgb"`, `"#rrggbb"` or `"#rrggbbaa"`) paints the colour under the page, so a +dark interface does not flash white. `WEBFRONT_STARTUP_TRACE=1` prints the view's milestones (load started, first frame, +window shown) on standard error. A close request (`requestClose()`) made before the window is shown still ends the +session. + +The cost of the first layout depends on the fonts of the page: fontconfig walks every installed font for each family it +cannot find or that is a CSS generic such as `system-ui` or `ui-monospace`, for each weight and style. A page that +lists several absent families (`"Segoe UI"`, `Inter`, `"JetBrains Mono"`, `Menlo`) can spend hundreds of milliseconds +before its first paint on a machine with thousands of fonts. Prefer the generics `sans-serif` and `monospace`, or one +family you know to be installed, first in the stack; the embedded pages, the starter and the examples do. + ## Development and distribution WebKitGTK has two **build modes**, independent of Debug/Release, `NDEBUG`, diff --git a/examples/host-loop/HostLoopUI.hpp b/examples/host-loop/HostLoopUI.hpp index bd2f8416..2c24cd54 100644 --- a/examples/host-loop/HostLoopUI.hpp +++ b/examples/host-loop/HostLoopUI.hpp @@ -32,13 +32,13 @@ inline constexpr std::string_view page = R"js( const root = add(document.body, "div", {id: "host-loop"}); add(root, "style", {textContent: ` #host-loop { position: fixed; inset: 0; margin: 0; padding: 0; overflow: hidden; background: #0b0d12; color: #f2f4f8; - font: 14px/1.4 system-ui, sans-serif; text-align: left; } + font: 14px/1.4 sans-serif; text-align: left; } #host-loop canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; } #host-loop .panel { position: absolute; margin: 0; background: rgba(14, 16, 22, .72); border: 1px solid rgba(255, 255, 255, .16); border-radius: 14px; } #host-loop .controls { left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; padding: 8px; white-space: nowrap; } - #host-loop .stats { left: 20px; top: 20px; max-width: calc(100% - 230px); padding: 10px 14px; font: 11px/1.5 ui-monospace, monospace; + #host-loop .stats { left: 20px; top: 20px; max-width: calc(100% - 230px); padding: 10px 14px; font: 11px/1.5 monospace; white-space: pre-wrap; } #host-loop .status { left: 50%; bottom: 84px; transform: translateX(-50%); padding: 8px 14px; color: #ffd27d; } #host-loop .status:empty { padding: 0; border: 0; } @@ -52,7 +52,7 @@ inline constexpr std::string_view page = R"js( #host-loop [name=stop] { background: rgba(255, 96, 96, .22); } #host-loop [name=cuda] { right: 20px; top: 20px; padding: 10px 16px; border-radius: 14px; text-align: right; background: rgba(14, 16, 22, .72); border: 2px solid rgba(255, 255, 255, .25); color: #9aa3b2; } - #host-loop [name=cuda] b { display: block; font: 800 26px/1 system-ui, sans-serif; letter-spacing: 2px; } + #host-loop [name=cuda] b { display: block; font: 800 26px/1 sans-serif; letter-spacing: 2px; } #host-loop [name=cuda] span { font-size: 12px; } #host-loop [name=cuda].on { background: #76b900; border-color: #b6f03c; color: #0b1400; } #host-loop [name=cuda]:disabled { cursor: not-allowed; opacity: .6; } diff --git a/examples/life/ui/style.css b/examples/life/ui/style.css index cb7905b1..a062cdd8 100644 --- a/examples/life/ui/style.css +++ b/examples/life/ui/style.css @@ -1 +1 @@ -:root{font-family:Inter,"Avenir Next",system-ui,sans-serif;color:#e8f4ed;background:#101c1d;color-scheme:dark;font-synthesis:none}*{box-sizing:border-box}body{margin:0}button,input{font:inherit}button{cursor:pointer}button:focus-visible,input:focus-visible,a:focus-visible{outline:2px solid #d5ffd7;outline-offset:4px}button:disabled{opacity:.4;cursor:wait}.observatory{min-height:100svh;padding:28px 4vw 12px;overflow:hidden;position:relative;background:radial-gradient(ellipse at 54% 44%,#2c4d46 0%,transparent 58%),radial-gradient(ellipse at 100% 0%,#263332 0%,transparent 55%),#101c1d}header{display:flex;align-items:center;justify-content:space-between;gap:20px;position:relative;z-index:2}.identity{font-size:20px;letter-spacing:.2em;text-decoration:none;color:inherit;display:flex;align-items:center;gap:12px}.mark{font-size:32px;color:#c1e5c2}.edition{font-size:11px;color:#91a7a0;letter-spacing:.03em}.eyebrow{font-size:10px;letter-spacing:.15em;color:#9eb6ac;line-height:1.6}.engine{font-size:11px;color:#c9d9ce;white-space:nowrap}.engine i{display:inline-block;width:6px;height:6px;margin-right:8px;border-radius:50%;background:#b7edba;box-shadow:0 0 12px #a2edaf}.scene{position:relative;min-height:510px;height:calc(100svh - 225px);max-height:850px}.intro{position:absolute;top:13%;left:0;z-index:1;pointer-events:none}h1{font-size:clamp(28px,3.3vw,48px);font-weight:400;line-height:1.1;letter-spacing:-.055em;margin:15px 0 20px}.intro p{color:#91a9a0;font-size:12px;line-height:1.8}.world{position:absolute;inset:-5% 1% -3% 9%;display:flex;align-items:center;justify-content:center}canvas{position:relative;width:100%;height:100%;max-width:1100px;cursor:crosshair}.halo{position:absolute;width:60%;height:38%;left:22%;top:40%;border-radius:50%;background:#93ddae18;filter:blur(65px);transform:rotate(-18deg)}.glass{background:linear-gradient(135deg,#f1fff111,#d7ffe907 70%);border:1px solid #deffe328;border-top-color:#e4ffe34d;box-shadow:0 18px 60px #0003,inset 0 1px 1px #fff1;backdrop-filter:blur(24px) saturate(140%);-webkit-backdrop-filter:blur(24px) saturate(140%)}.telemetry{position:absolute;right:0;top:15%;padding:21px 24px;border-radius:20px;min-width:145px}.telemetry>div{margin-top:20px;display:flex;flex-direction:column;gap:4px}.telemetry output{font-size:30px;font-weight:300;letter-spacing:-.04em;font-variant-numeric:tabular-nums}.telemetry div span,.boundary{font-size:10px;color:#9db5a9}.boundary{display:block;margin-top:24px;font-size:9px}.coordinates{position:absolute;bottom:7%;left:0;right:0;display:flex;justify-content:space-between;font:9px ui-monospace,monospace;letter-spacing:.08em;color:#78968b}.coordinates span{font-size:8px}.controls{position:relative;z-index:2;display:flex;align-items:center;justify-content:space-between;gap:18px;padding:12px 15px;border-radius:23px;max-width:1120px;margin:auto}.controls button{border:1px solid transparent;background:transparent;color:#c2d4c8;padding:10px 13px;border-radius:12px;font-size:11px;white-space:nowrap;transition:background .18s}.controls button:hover{background:#e7ffe414}.controls button[aria-pressed=true]{background:#dfffdf16;color:#efffe9;border-color:#c7e8ca26}.transport{display:flex;gap:4px}.controls .primary{background:#dcf1cb;color:#183227;min-width:89px;box-shadow:inset 0 1px #fff8,0 3px 12px #0002}.controls .primary:hover{background:#edffdc}.speed{display:flex;align-items:center;gap:10px;font-size:10px;color:#9db7a8}.speed input{width:65px;accent-color:#c9e8b7}.speed span{min-width:24px;font-variant-numeric:tabular-nums}.patterns{display:flex;gap:2px}.controls .view{border-left:1px solid #b2c9bc26;border-radius:0 12px 12px 0}.caption{display:flex;justify-content:space-between;color:#819c8e;font-size:9px;letter-spacing:.02em;max-width:1090px;margin:15px auto 0}.error{color:#ffc5ad;font-size:12px;margin:8px 0;min-height:14px}@media(max-width:1000px){header>.eyebrow{display:none}.controls{flex-wrap:wrap;justify-content:center;gap:7px 14px}.speed{margin-left:auto}.scene{min-height:450px}.intro{top:8%}.world{inset:8% -13% -5% -3%}.telemetry{top:8%;padding:15px;min-width:118px}.telemetry output{font-size:24px}.telemetry>div{margin-top:12px}}@media(max-width:560px){.observatory{padding:18px 18px 8px}.scene{height:450px;min-height:450px}.intro{top:7%}h1{font-size:28px}.intro p{font-size:10px}.telemetry{top:7%;padding:12px;min-width:98px}.telemetry .eyebrow{font-size:8px}.boundary{font-size:8px;max-width:80px;line-height:1.5}.world{inset:26% -25% 0 -25%}.coordinates{bottom:2%;font-size:8px}.coordinates span{display:none}.controls{border-radius:19px;padding:10px;gap:6px}.controls button{font-size:10px;padding:9px}.speed{margin-left:6px;gap:6px}.speed input{width:53px}.patterns{order:3;width:100%;justify-content:center}.controls .view{margin-left:auto}.caption{font-size:8px;gap:15px;line-height:1.5}.caption span{text-align:right}}@media(prefers-reduced-motion:reduce){*{transition:none!important}}@supports not (backdrop-filter:blur(1px)){.glass{background:#233730f5}} +:root{font-family:sans-serif;color:#e8f4ed;background:#101c1d;color-scheme:dark;font-synthesis:none}*{box-sizing:border-box}body{margin:0}button,input{font:inherit}button{cursor:pointer}button:focus-visible,input:focus-visible,a:focus-visible{outline:2px solid #d5ffd7;outline-offset:4px}button:disabled{opacity:.4;cursor:wait}.observatory{min-height:100svh;padding:28px 4vw 12px;overflow:hidden;position:relative;background:radial-gradient(ellipse at 54% 44%,#2c4d46 0%,transparent 58%),radial-gradient(ellipse at 100% 0%,#263332 0%,transparent 55%),#101c1d}header{display:flex;align-items:center;justify-content:space-between;gap:20px;position:relative;z-index:2}.identity{font-size:20px;letter-spacing:.2em;text-decoration:none;color:inherit;display:flex;align-items:center;gap:12px}.mark{font-size:32px;color:#c1e5c2}.edition{font-size:11px;color:#91a7a0;letter-spacing:.03em}.eyebrow{font-size:10px;letter-spacing:.15em;color:#9eb6ac;line-height:1.6}.engine{font-size:11px;color:#c9d9ce;white-space:nowrap}.engine i{display:inline-block;width:6px;height:6px;margin-right:8px;border-radius:50%;background:#b7edba;box-shadow:0 0 12px #a2edaf}.scene{position:relative;min-height:510px;height:calc(100svh - 225px);max-height:850px}.intro{position:absolute;top:13%;left:0;z-index:1;pointer-events:none}h1{font-size:clamp(28px,3.3vw,48px);font-weight:400;line-height:1.1;letter-spacing:-.055em;margin:15px 0 20px}.intro p{color:#91a9a0;font-size:12px;line-height:1.8}.world{position:absolute;inset:-5% 1% -3% 9%;display:flex;align-items:center;justify-content:center}canvas{position:relative;width:100%;height:100%;max-width:1100px;cursor:crosshair}.halo{position:absolute;width:60%;height:38%;left:22%;top:40%;border-radius:50%;background:#93ddae18;filter:blur(65px);transform:rotate(-18deg)}.glass{background:linear-gradient(135deg,#f1fff111,#d7ffe907 70%);border:1px solid #deffe328;border-top-color:#e4ffe34d;box-shadow:0 18px 60px #0003,inset 0 1px 1px #fff1;backdrop-filter:blur(24px) saturate(140%);-webkit-backdrop-filter:blur(24px) saturate(140%)}.telemetry{position:absolute;right:0;top:15%;padding:21px 24px;border-radius:20px;min-width:145px}.telemetry>div{margin-top:20px;display:flex;flex-direction:column;gap:4px}.telemetry output{font-size:30px;font-weight:300;letter-spacing:-.04em;font-variant-numeric:tabular-nums}.telemetry div span,.boundary{font-size:10px;color:#9db5a9}.boundary{display:block;margin-top:24px;font-size:9px}.coordinates{position:absolute;bottom:7%;left:0;right:0;display:flex;justify-content:space-between;font:9px monospace;letter-spacing:.08em;color:#78968b}.coordinates span{font-size:8px}.controls{position:relative;z-index:2;display:flex;align-items:center;justify-content:space-between;gap:18px;padding:12px 15px;border-radius:23px;max-width:1120px;margin:auto}.controls button{border:1px solid transparent;background:transparent;color:#c2d4c8;padding:10px 13px;border-radius:12px;font-size:11px;white-space:nowrap;transition:background .18s}.controls button:hover{background:#e7ffe414}.controls button[aria-pressed=true]{background:#dfffdf16;color:#efffe9;border-color:#c7e8ca26}.transport{display:flex;gap:4px}.controls .primary{background:#dcf1cb;color:#183227;min-width:89px;box-shadow:inset 0 1px #fff8,0 3px 12px #0002}.controls .primary:hover{background:#edffdc}.speed{display:flex;align-items:center;gap:10px;font-size:10px;color:#9db7a8}.speed input{width:65px;accent-color:#c9e8b7}.speed span{min-width:24px;font-variant-numeric:tabular-nums}.patterns{display:flex;gap:2px}.controls .view{border-left:1px solid #b2c9bc26;border-radius:0 12px 12px 0}.caption{display:flex;justify-content:space-between;color:#819c8e;font-size:9px;letter-spacing:.02em;max-width:1090px;margin:15px auto 0}.error{color:#ffc5ad;font-size:12px;margin:8px 0;min-height:14px}@media(max-width:1000px){header>.eyebrow{display:none}.controls{flex-wrap:wrap;justify-content:center;gap:7px 14px}.speed{margin-left:auto}.scene{min-height:450px}.intro{top:8%}.world{inset:8% -13% -5% -3%}.telemetry{top:8%;padding:15px;min-width:118px}.telemetry output{font-size:24px}.telemetry>div{margin-top:12px}}@media(max-width:560px){.observatory{padding:18px 18px 8px}.scene{height:450px;min-height:450px}.intro{top:7%}h1{font-size:28px}.intro p{font-size:10px}.telemetry{top:7%;padding:12px;min-width:98px}.telemetry .eyebrow{font-size:8px}.boundary{font-size:8px;max-width:80px;line-height:1.5}.world{inset:26% -25% 0 -25%}.coordinates{bottom:2%;font-size:8px}.coordinates span{display:none}.controls{border-radius:19px;padding:10px;gap:6px}.controls button{font-size:10px;padding:9px}.speed{margin-left:6px;gap:6px}.speed input{width:53px}.patterns{order:3;width:100%;justify-content:center}.controls .view{margin-left:auto}.caption{font-size:8px;gap:15px;line-height:1.5}.caption span{text-align:right}}@media(prefers-reduced-motion:reduce){*{transition:none!important}}@supports not (backdrop-filter:blur(1px)){.glass{background:#233730f5}} diff --git a/include/webfront/frontend/WebKitGTK.hpp b/include/webfront/frontend/WebKitGTK.hpp index 091e08af..4001d8e8 100644 --- a/include/webfront/frontend/WebKitGTK.hpp +++ b/include/webfront/frontend/WebKitGTK.hpp @@ -80,6 +80,7 @@ class Api { const char* (*windowGetTitle)(Object) = symbol("gtk_window_get_title"); void (*windowSize)(Object, int, int) = symbol("gtk_window_set_default_size"); void (*windowChild)(Object, Object) = symbol("gtk_window_set_child"); + void (*widgetOpacity)(Object, double) = symbol("gtk_widget_set_opacity"); void (*windowPresent)(Object) = symbol("gtk_window_present"); void (*windowDestroy)(Object) = symbol("gtk_window_destroy"); Object (*loopNew)(Object, int) = symbol("g_main_loop_new"); @@ -100,6 +101,7 @@ class Api { const char* (*viewUri)(Object) = symbol("webkit_web_view_get_uri"); const char* (*viewTitle)(Object) = symbol("webkit_web_view_get_title"); void (*windowClose)(Object) = symbol("gtk_window_close"); + void (*emitByName)(Object, const char*, ...) = symbol("g_signal_emit_by_name"); void (*stop)(Object) = symbol("webkit_web_view_stop_loading"); Object (*navigationAction)(Object) = symbol("webkit_navigation_policy_decision_get_navigation_action"); Object (*request)(Object) = symbol("webkit_navigation_action_get_request"); @@ -142,6 +144,9 @@ class Api { Object (*scriptNew)(const char*, int, int, const char* const*, const char* const*) = symbol("webkit_user_script_new"); void (*scriptAdd)(Object, Object) = symbol("webkit_user_content_manager_add_script"); void (*scriptUnref)(Object) = symbol("webkit_user_script_unref"); + // Script messages (WebKitGTK 2.40 added the world name; an extra null argument is harmless to older callers' ABI). + int (*registerMessage)(Object, const char*, const char*) = symbol("webkit_user_content_manager_register_script_message_handler"); + void (*viewBackground)(Object, const float*) = symbol("webkit_web_view_set_background_color"); // Portal identifier of the window (ADR-020): the backend's own symbols exist only when GTK was built with it, so each is // optional and a missing one leaves the identifier empty. Object (*nativeSurface)(Object) = optionalSymbol("gtk_native_get_surface"); @@ -348,14 +353,21 @@ struct Session : FailureState { bool closed = false; bool initialNavigation = true; unsigned navigationTimer = 0; + unsigned presentTimer = 0; // presents the window anyway when the first frame is late + bool presented = false; + std::chrono::steady_clock::time_point created = std::chrono::steady_clock::now(); unsigned portalTimer = 0; // retries the Wayland export until the toplevel can be exported int portalAttempts = 0; std::uint64_t portalGeneration = 0; // the publication this session's identifier belongs to unsigned long windowHandler = 0; std::vector viewHandlers; + unsigned long messageHandler = 0; // on the content manager, not on the view std::shared_ptr captureTarget = std::make_shared(); CaptureRegistration captureRegistration; + /// The window is presented at the latest this long after the load starts, painted or not. + static constexpr unsigned maximumPresentDelayMs = 1000; + explicit Session(webfront::detail::BoundContentPolicy rules, WindowOptions settings = {}) : policy(std::move(rules)), windowOptions(resolveWindow(std::move(settings))) {} Session(const Session&) = delete; @@ -364,6 +376,7 @@ struct Session : FailureState { if (portalTimer) a.sourceRemove(std::exchange(portalTimer, 0)); stopNavigationTimer(); + stopPresentTimer(); releaseDownloads(); releaseView(); destroyWindow(); @@ -379,6 +392,10 @@ struct Session : FailureState { if (navigationTimer) a.sourceRemove(std::exchange(navigationTimer, 0)); } + void stopPresentTimer() { + if (presentTimer) + a.sourceRemove(std::exchange(presentTimer, 0)); + } void releaseView() { captureRegistration = {}; abandonCaptures(*captureTarget); @@ -386,6 +403,8 @@ struct Session : FailureState { return; for (auto handler : viewHandlers) a.disconnect(view, handler); + if (messageHandler) + a.disconnect(a.contentManager(view), std::exchange(messageHandler, 0)); a.stop(view); release(view); } @@ -449,7 +468,9 @@ struct Session : FailureState { a.windowSize(window, windowOptions.width, windowOptions.height); a.windowChild(window, view); configureSettings(); + applyBackground(); installViewAssociation(); + installFirstFrameProbe(); registerHandlers(); downloadStartedHandler = a.connect(network, "download-started", reinterpret_cast(onDownloadStarted), this, nullptr, 0); captureTarget->view = view; @@ -457,6 +478,69 @@ struct Session : FailureState { captureRegistration = CaptureRegistration{captureProvider(captureTarget)}; } + void applyBackground() { + if (const auto color = parseBackground(windowOptions.background)) + a.viewBackground(view, color->data()); + } + + /// The window is mapped at once but fully transparent: WebKit paints, and animation frames run, only in a mapped view, so + /// the first frame can be awaited. Without a compositing manager the opacity is ignored and the window shows as before. + /// WEBFRONT_STARTUP_TRACE=1 reports the milestones of the view's start, in milliseconds since the session was created. + void trace(const char* milestone) const { + static const bool enabled = [] { + const auto* value = std::getenv("WEBFRONT_STARTUP_TRACE"); + return value && *value && std::string_view{value} != "0"; + }(); + if (enabled) + std::fprintf(stderr, "WebFront startup: %s at %lld ms\n", milestone, + static_cast(std::chrono::duration_cast(std::chrono::steady_clock::now() - created).count())); + } + void presentHidden() { + a.widgetOpacity(window, 0.01); // GTK does not draw a widget at 0, and WebKit would wait for a frame forever + a.windowPresent(window); + startPortalExport(); + } + /// Shows the window once the page painted its first frame, or when the delay expired. + void presentWindow() { + if (presented || closed) + return; + presented = true; + stopPresentTimer(); + a.widgetOpacity(window, 1.0); + trace("window shown"); + } + static void onFirstFrame(Api::Object, Api::Object, Session* self) noexcept { + self->trace("first frame"); + self->guard([self] { + self->presentWindow(); + }); + } + static int onPresentTimeout(void* data) noexcept { + auto* self = static_cast(data); + self->presentTimer = 0; + self->trace("present delay expired"); + self->guard([self] { + self->presentWindow(); + }); + return 0; + } + /// The page tells the toolkit that its first frame is painted (two animation frames after DOMContentLoaded), so that the + /// window appears with content instead of black. The message handler is the content manager's: a page can only advance the + /// presentation, which the timer would do anyway. + void installFirstFrameProbe() { + constexpr const char* name = "webfrontFirstFrame"; + const auto script = a.scriptNew( + R"js((function(){if(window.top!==window)return;var sent=false;function post(){if(sent)return;sent=true;try{window.webkit.messageHandlers.webfrontFirstFrame.postMessage(0);}catch(e){}}function frames(){requestAnimationFrame(function(){requestAnimationFrame(post);});}if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",frames);else frames();})();)js", + 1, + 0, + nullptr, + nullptr); + a.scriptAdd(a.contentManager(view), script); + a.scriptUnref(script); + a.registerMessage(a.contentManager(view), name, nullptr); + messageHandler = a.connect(a.contentManager(view), "script-message-received::webfrontFirstFrame", reinterpret_cast(onFirstFrame), this, nullptr, 0); + } + void installViewAssociation() { const auto source = webfront::detail::viewSecretScript(launch.secret, launch.origin); if (source.empty()) @@ -778,8 +862,9 @@ struct Session : FailureState { if (closed) return; navigationTimer = a.timeoutAdd(30'000, onNavigationTimeout, this); - a.windowPresent(window); - startPortalExport(); + presentTimer = a.timeoutAdd(maximumPresentDelayMs, onPresentTimeout, this); + presentHidden(); + trace("load started"); a.load(view, url.c_str()); if (!closed) a.loopRun(loop); @@ -857,7 +942,10 @@ struct BasicWebKitGTKFrontend { static bool requestClose([[maybe_unused]] std::optional session = std::nullopt) noexcept { #if defined(WEBFRONT_EMBED_WEBKITGTK) && defined(__linux__) return detail::requestWindowClose(uiExecutor(), nativeWindow(), [](const NativeWindowHandle& window) { - detail::webkitgtk::api().windowClose(window.pointer); // emits close-request, as the window's button does + // gtk_window_close ignores a window that is not realized, and the window is presented only after the first frame: + // a request made before that must still end the session, so the close-request signal is emitted itself. + int handled = 0; + detail::webkitgtk::api().emitByName(window.pointer, "close-request", &handled); }, session); #else return false; diff --git a/include/webfront/frontend/Window.hpp b/include/webfront/frontend/Window.hpp index db5276fc..3e2a4897 100644 --- a/include/webfront/frontend/Window.hpp +++ b/include/webfront/frontend/Window.hpp @@ -1,8 +1,11 @@ #pragma once +#include #include #include +#include #include +#include #if defined(_WIN32) #include "../system/WindowsCompat.hpp" @@ -17,12 +20,15 @@ namespace webfront { * @brief Initial native window of the embedded frontends (the system browser ignores it). * * An empty title selects the executable's name. Sizes are in the toolkit's logical pixels; a - * non-positive size selects the default. + * non-positive size selects the default. `background` is a CSS hexadecimal colour ("#rgb", "#rrggbb" or "#rrggbbaa") painted + * under the page, so that the window is never black or white against a contrary theme before the first frame; empty keeps the + * toolkit's default and an invalid value is ignored. */ struct WindowOptions { std::string title{}; int width{1200}; int height{800}; + std::string background{}; }; namespace frontend::detail { @@ -49,6 +55,34 @@ inline std::string executableName() { } } +/// The components (0 to 1) of a "#rgb", "#rrggbb" or "#rrggbbaa" colour; nothing for any other text. +inline std::optional> parseBackground(std::string_view text) { + if (text.size() < 2 || text.front() != '#') + return std::nullopt; + text.remove_prefix(1); + if (text.size() != 3 && text.size() != 6 && text.size() != 8) + return std::nullopt; + const auto digit = [](char c) -> int { + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + return -1; + }; + std::array rgba{0, 0, 0, 1}; + const std::size_t width = text.size() == 3 ? 1 : 2; + for (std::size_t i = 0; i * width < text.size(); ++i) { + const int high = digit(text[i * width]); + const int low = width == 1 ? high : digit(text[i * width + 1]); + if (high < 0 || low < 0) + return std::nullopt; + rgba[i] = static_cast(high * 16 + low) / 255.0f; + } + return rgba; +} + /// The window's effective values: title from the application, else the executable's name, else "WebFront". inline WindowOptions resolveWindow(WindowOptions window) { if (window.title.empty()) diff --git a/include/webfront/system/DeveloperIndexHtmlData.hpp b/include/webfront/system/DeveloperIndexHtmlData.hpp index 10a5642c..a30acd4e 100644 --- a/include/webfront/system/DeveloperIndexHtmlData.hpp +++ b/include/webfront/system/DeveloperIndexHtmlData.hpp @@ -9,27 +9,27 @@ namespace webfront::fs::generated { struct DeveloperIndexHtmlData { static constexpr std::string_view encoding{}; - static constexpr std::size_t dataSize{758}; + static constexpr std::size_t dataSize{759}; static constexpr std::array data{ 0x3c21646f63747970, 0x652068746d6c3e0a, 0x3c68746d6c206c61, 0x6e673d22656e223e, 0x0a3c6d6574612063, 0x6861727365743d22, 0x7574662d38223e0a, 0x3c6d657461206e61, 0x6d653d2276696577, 0x706f72742220636f, 0x6e74656e743d2277, 0x696474683d646576, 0x6963652d77696474, 0x682c20696e697469, 0x616c2d7363616c65, 0x3d31223e0a3c7469, 0x746c653e57656246, 0x726f6e7420646576, 0x656c6f7065722062, 0x6f6f747374726170, 0x3c2f7469746c653e, 0x0a3c7374796c653e, 0x626f64797b6d6172, 0x67696e3a303b6261, 0x636b67726f756e64, - 0x3a23313431383231, 0x3b636f6c6f723a23, 0x6538656466343b66, 0x6f6e743a31357078, 0x2073797374656d2d, - 0x75697d6865616465, 0x727b70616464696e, 0x673a313670787d62, 0x7574746f6e7b6d61, 0x7267696e3a387078, - 0x7d237465726d696e, 0x616c7b6865696768, 0x743a343576683b70, 0x616464696e673a38, 0x70787d2370726576, - 0x6965777b77696474, 0x683a313030253b68, 0x65696768743a3435, 0x76683b626f726465, 0x723a303b6261636b, - 0x67726f756e643a77, 0x686974657d707265, 0x7b77686974652d73, 0x706163653a707265, 0x2d777261707d3c2f, - 0x7374796c653e0a3c, 0x6865616465723e3c, 0x7374726f6e673e57, 0x656246726f6e7420, 0x646576656c6f7065, - 0x723c2f7374726f6e, 0x673e3c7072652069, 0x643d227374617475, 0x73223e5374617274, 0x696e672074686520, - 0x646576656c6f7065, 0x7220656e7669726f, 0x6e6d656e74e280a6, 0x3c2f7072653e3c62, 0x7574746f6e206964, - 0x3d22726574727922, 0x2068696464656e3e, 0x52657472793c2f62, 0x7574746f6e3e3c2f, 0x6865616465723e0a, - 0x3c6469762069643d, 0x227465726d696e61, 0x6c223e3c2f646976, 0x3e3c696672616d65, 0x2069643d22707265, - 0x7669657722207469, 0x746c653d22417070, 0x6c69636174696f6e, 0x2070726576696577, 0x222068696464656e, - 0x3e3c2f696672616d, 0x653e0a3c73637269, 0x7074207372633d22, 0x2f57656246726f6e, 0x742e6a73223e3c2f, - 0x7363726970743e0a, 0x3c73637269707420, 0x747970653d226d6f, 0x64756c6522207372, 0x633d222f77656266, - 0x726f6e742d626f6f, 0x7473747261702e6d, 0x6a73223e3c2f7363, 0x726970743e0a3c2f, 0x68746d6c3e0a0000 + 0x3a23313431383231, 0x3b636f6c6f723a23, 0x6538656466343b66, 0x6f6e743a31357078, 0x2073616e732d7365, + 0x7269667d68656164, 0x65727b7061646469, 0x6e673a313670787d, 0x627574746f6e7b6d, 0x617267696e3a3870, + 0x787d237465726d69, 0x6e616c7b68656967, 0x68743a343576683b, 0x70616464696e673a, 0x3870787d23707265, + 0x766965777b776964, 0x74683a313030253b, 0x6865696768743a34, 0x3576683b626f7264, 0x65723a303b626163, + 0x6b67726f756e643a, 0x77686974657d7072, 0x657b77686974652d, 0x73706163653a7072, 0x652d777261707d3c, + 0x2f7374796c653e0a, 0x3c6865616465723e, 0x3c7374726f6e673e, 0x57656246726f6e74, 0x20646576656c6f70, + 0x65723c2f7374726f, 0x6e673e3c70726520, 0x69643d2273746174, 0x7573223e53746172, 0x74696e6720746865, + 0x20646576656c6f70, 0x657220656e766972, 0x6f6e6d656e74e280, 0xa63c2f7072653e3c, 0x627574746f6e2069, + 0x643d227265747279, 0x222068696464656e, 0x3e52657472793c2f, 0x627574746f6e3e3c, 0x2f6865616465723e, + 0x0a3c646976206964, 0x3d227465726d696e, 0x616c223e3c2f6469, 0x763e3c696672616d, 0x652069643d227072, + 0x6576696577222074, 0x69746c653d224170, 0x706c69636174696f, 0x6e20707265766965, 0x7722206869646465, + 0x6e3e3c2f69667261, 0x6d653e0a3c736372, 0x697074207372633d, 0x222f57656246726f, 0x6e742e6a73223e3c, + 0x2f7363726970743e, 0x0a3c736372697074, 0x20747970653d226d, 0x6f64756c65222073, 0x72633d222f776562, + 0x66726f6e742d626f, 0x6f7473747261702e, 0x6d6a73223e3c2f73, 0x63726970743e0a3c, 0x2f68746d6c3e0a00 }; }; diff --git a/include/webfront/system/FallbackIndexHtmlData.hpp b/include/webfront/system/FallbackIndexHtmlData.hpp index b4e517fd..c0702c64 100644 --- a/include/webfront/system/FallbackIndexHtmlData.hpp +++ b/include/webfront/system/FallbackIndexHtmlData.hpp @@ -9,8 +9,8 @@ namespace webfront::fs::generated { struct FallbackIndexHtmlData { static constexpr std::string_view encoding{}; - static constexpr std::size_t dataSize{1756}; - static constexpr std::array data{ + static constexpr std::size_t dataSize{1718}; + static constexpr std::array data{ 0x3c21444f43545950, 0x452068746d6c3e0a, 0x3c68746d6c206c61, 0x6e673d22656e223e, 0x0a3c686561643e0a, 0x3c6d657461206368, 0x61727365743d2275, 0x74662d38223e0a3c, 0x6d657461206e616d, 0x653d227669657770, 0x6f72742220636f6e, 0x74656e743d227769, 0x6474683d64657669, 0x63652d7769647468, 0x2c20696e69746961, @@ -25,36 +25,35 @@ struct FallbackIndexHtmlData { 0x696e2d6865696768, 0x743a203130307668, 0x3b0a202020206469, 0x73706c61793a2066, 0x6c65783b0a202020, 0x20666c65782d6469, 0x72656374696f6e3a, 0x20636f6c756d6e3b, 0x0a20202020616c69, 0x676e2d6974656d73, 0x3a2063656e746572, 0x3b0a202020206a75, 0x73746966792d636f, 0x6e74656e743a2063, 0x656e7465723b0a20, - 0x2020207061646469, 0x6e673a20312e3572, 0x656d3b0a20202020, 0x666f6e742d66616d, 0x696c793a20737973, - 0x74656d2d75692c20, 0x2d6170706c652d73, 0x797374656d2c2022, 0x5365676f65205549, 0x222c2073616e732d, - 0x73657269663b0a20, 0x202020636f6c6f72, 0x3a20766172282d2d, 0x6667293b0a202020, 0x206261636b67726f, - 0x756e643a20766172, 0x282d2d6267293b0a, 0x20207d0a20206d61, 0x696e207b0a202020, 0x206d61782d776964, - 0x74683a2033327265, 0x6d3b0a2020202077, 0x696474683a203130, 0x30253b0a20202020, 0x746578742d616c69, - 0x676e3a2063656e74, 0x65723b0a20207d0a, 0x20206831207b2066, 0x6f6e742d73697a65, 0x3a20312e37357265, - 0x6d3b206d61726769, 0x6e2d626f74746f6d, 0x3a20302e3572656d, 0x3b207d0a20207020, 0x7b206c696e652d68, - 0x65696768743a2031, 0x2e353b207d0a2020, 0x2373746174757320, 0x7b0a202020206469, 0x73706c61793a2069, - 0x6e6c696e652d626c, 0x6f636b3b0a202020, 0x206d617267696e2d, 0x746f703a20317265, 0x6d3b0a2020202070, - 0x616464696e673a20, 0x302e3572656d2031, 0x72656d3b0a202020, 0x20626f726465722d, 0x7261646975733a20, - 0x302e3572656d3b0a, 0x20202020666f6e74, 0x2d7765696768743a, 0x203630303b0a2020, 0x7d0a202023737461, - 0x7475735b64617461, 0x2d73746174653d22, 0x636f6e6e65637469, 0x6e67225d207b2062, 0x61636b67726f756e, - 0x643a20636f6c6f72, 0x2d6d697828696e20, 0x737267622c207661, 0x72282d2d61636365, 0x6e7429203135252c, - 0x207472616e737061, 0x72656e74293b207d, 0x0a20202373746174, 0x75735b646174612d, 0x73746174653d2263, - 0x6f6e6e6563746564, 0x225d207b20626163, 0x6b67726f756e643a, 0x20636f6c6f722d6d, 0x697828696e207372, - 0x67622c2076617228, 0x2d2d616363656e74, 0x29203235252c2074, 0x72616e7370617265, 0x6e74293b207d0a20, - 0x2023737461747573, 0x5b646174612d7374, 0x6174653d22657272, 0x6f72225d2c202373, 0x74617475735b6461, - 0x74612d7374617465, 0x3d22646f6d2d6572, 0x726f72225d207b20, 0x6261636b67726f75, 0x6e643a20636f6c6f, - 0x722d6d697828696e, 0x20737267622c2076, 0x6172282d2d657272, 0x6f7229203230252c, 0x207472616e737061, - 0x72656e74293b2063, 0x6f6c6f723a207661, 0x72282d2d6572726f, 0x72293b207d0a3c2f, 0x7374796c653e0a3c, - 0x2f686561643e0a3c, 0x626f64793e0a3c6d, 0x61696e3e0a20203c, 0x68313e48656c6c6f, 0x2c2057656246726f, - 0x6e74213c2f68313e, 0x0a20203c703e5468, 0x6973207061676520, 0x6973207365727665, 0x6420627920576562, - 0x46726f6e74277320, 0x656d626564646564, 0x2066616c6c626163, 0x6b2e204974206861, 0x73206e6f206c6f63, - 0x616c205549206669, 0x6c6573206f662069, 0x7473206f776e2e3c, 0x2f703e0a20203c70, 0x2069643d22737461, - 0x7475732220726f6c, 0x653d227374617475, 0x732220617269612d, 0x6c6976653d22706f, 0x6c69746522206461, - 0x74612d7374617465, 0x3d22636f6e6e6563, 0x74696e67223e436f, 0x6e6e656374696e67, 0x2668656c6c69703b, - 0x3c2f703e0a3c2f6d, 0x61696e3e0a3c6469, 0x762069643d227765, 0x6266726f6e742d72, 0x6f6f74223e3c2f64, - 0x69763e0a3c736372, 0x697074207372633d, 0x2257656246726f6e, 0x742e6a73223e3c2f, 0x7363726970743e0a, - 0x3c73637269707420, 0x747970653d226d6f, 0x64756c6522207372, 0x633d227765626672, 0x6f6e742d66616c6c, - 0x6261636b2e6d6a73, 0x223e3c2f73637269, 0x70743e0a3c2f626f, 0x64793e0a3c2f6874, 0x6d6c3e0a00000000 + 0x2020207061646469, 0x6e673a20312e3572, 0x656d3b0a20202020, 0x666f6e742d66616d, 0x696c793a2073616e, + 0x732d73657269663b, 0x0a20202020636f6c, 0x6f723a2076617228, 0x2d2d6667293b0a20, 0x2020206261636b67, + 0x726f756e643a2076, 0x6172282d2d626729, 0x3b0a20207d0a2020, 0x6d61696e207b0a20, 0x2020206d61782d77, + 0x696474683a203332, 0x72656d3b0a202020, 0x2077696474683a20, 0x313030253b0a2020, 0x2020746578742d61, + 0x6c69676e3a206365, 0x6e7465723b0a2020, 0x7d0a20206831207b, 0x20666f6e742d7369, 0x7a653a20312e3735, + 0x72656d3b206d6172, 0x67696e2d626f7474, 0x6f6d3a20302e3572, 0x656d3b207d0a2020, 0x70207b206c696e65, + 0x2d6865696768743a, 0x20312e353b207d0a, 0x2020237374617475, 0x73207b0a20202020, 0x646973706c61793a, + 0x20696e6c696e652d, 0x626c6f636b3b0a20, 0x2020206d61726769, 0x6e2d746f703a2031, 0x72656d3b0a202020, + 0x2070616464696e67, 0x3a20302e3572656d, 0x203172656d3b0a20, 0x202020626f726465, 0x722d726164697573, + 0x3a20302e3572656d, 0x3b0a20202020666f, 0x6e742d7765696768, 0x743a203630303b0a, 0x20207d0a20202373, + 0x74617475735b6461, 0x74612d7374617465, 0x3d22636f6e6e6563, 0x74696e67225d207b, 0x206261636b67726f, + 0x756e643a20636f6c, 0x6f722d6d69782869, 0x6e20737267622c20, 0x766172282d2d6163, 0x63656e7429203135, + 0x252c207472616e73, 0x706172656e74293b, 0x207d0a2020237374, 0x617475735b646174, 0x612d73746174653d, + 0x22636f6e6e656374, 0x6564225d207b2062, 0x61636b67726f756e, 0x643a20636f6c6f72, 0x2d6d697828696e20, + 0x737267622c207661, 0x72282d2d61636365, 0x6e7429203235252c, 0x207472616e737061, 0x72656e74293b207d, + 0x0a20202373746174, 0x75735b646174612d, 0x73746174653d2265, 0x72726f72225d2c20, 0x237374617475735b, + 0x646174612d737461, 0x74653d22646f6d2d, 0x6572726f72225d20, 0x7b206261636b6772, 0x6f756e643a20636f, + 0x6c6f722d6d697828, 0x696e20737267622c, 0x20766172282d2d65, 0x72726f7229203230, 0x252c207472616e73, + 0x706172656e74293b, 0x20636f6c6f723a20, 0x766172282d2d6572, 0x726f72293b207d0a, 0x3c2f7374796c653e, + 0x0a3c2f686561643e, 0x0a3c626f64793e0a, 0x3c6d61696e3e0a20, 0x203c68313e48656c, 0x6c6f2c2057656246, + 0x726f6e74213c2f68, 0x313e0a20203c703e, 0x5468697320706167, 0x6520697320736572, 0x7665642062792057, + 0x656246726f6e7427, 0x7320656d62656464, 0x65642066616c6c62, 0x61636b2e20497420, 0x686173206e6f206c, + 0x6f63616c20554920, 0x66696c6573206f66, 0x20697473206f776e, 0x2e3c2f703e0a2020, 0x3c702069643d2273, + 0x7461747573222072, 0x6f6c653d22737461, 0x7475732220617269, 0x612d6c6976653d22, 0x706f6c6974652220, + 0x646174612d737461, 0x74653d22636f6e6e, 0x656374696e67223e, 0x436f6e6e65637469, 0x6e672668656c6c69, + 0x703b3c2f703e0a3c, 0x2f6d61696e3e0a3c, 0x6469762069643d22, 0x77656266726f6e74, 0x2d726f6f74223e3c, + 0x2f6469763e0a3c73, 0x6372697074207372, 0x633d225765624672, 0x6f6e742e6a73223e, 0x3c2f736372697074, + 0x3e0a3c7363726970, 0x7420747970653d22, 0x6d6f64756c652220, 0x7372633d22776562, 0x66726f6e742d6661, + 0x6c6c6261636b2e6d, 0x6a73223e3c2f7363, 0x726970743e0a3c2f, 0x626f64793e0a3c2f, 0x68746d6c3e0a0000 }; }; diff --git a/js/core/bootstrap/index.html b/js/core/bootstrap/index.html index cc4dfb2d..4a814869 100644 --- a/js/core/bootstrap/index.html +++ b/js/core/bootstrap/index.html @@ -3,7 +3,7 @@ WebFront developer bootstrap - +
WebFront developer
Starting the developer environment…
diff --git a/js/core/fallback/index.html b/js/core/fallback/index.html index e7ff7639..571e6a95 100644 --- a/js/core/fallback/index.html +++ b/js/core/fallback/index.html @@ -24,7 +24,7 @@ align-items: center; justify-content: center; padding: 1.5rem; - font-family: system-ui, -apple-system, "Segoe UI", sans-serif; + font-family: sans-serif; color: var(--fg); background: var(--bg); } diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index a6954c10..99ca2231 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -41,10 +41,10 @@ "js/developer/environment/resolve.mjs": "8b96b850af215be51f5cb85cc9c69e057afa04dfb8a57e572620c07059c17fa3", "js/developer/environment/embed.mjs": "3d3b5036c34c23a1fa0512c1eea42f26d5f30e054545b61fe83a5c378b74e09e", "examples/life/ui/main.tsx": "7b1ff285d2a6b8f897ef12df872886e61ef4b24e2358a9423b76b38ab75c85d3", - "examples/life/ui/style.css": "9bb55eb0f0a3287e5b7dc78af9d69608b87ff42c4d9c8a653bc83a52fe293c44", + "examples/life/ui/style.css": "ac13886f0aea2adfdca21c487467a8f6e647feffb88c51d81766e628584ea5cd", "js/developer/starters/agent-guide.md": "a4ace796863308f9239825389cc3ddd0f29dcc6f45cd0b2af65767411fc723ce", "js/developer/starters/app/main.ts": "3bc27323c1170089c53dec4ffcc8632ed3db66c45e73d75fa6d2d9ff2752652e", - "js/developer/starters/app/style.css": "1d4dccf54c21d56cd99bf72de181be095e196263767848ac52721ea94520dc5d", + "js/developer/starters/app/style.css": "6a042eff15ee9b1603c95d3e4e974a03876e1c365389553e84eb7c472aded180", "js/developer/tools/distribution.json": "390a79e5523d1c54e7f388c34b47a715fee2c9c3b6dca351e1c91797bd5cb7f3", "js/developer/tools/archive.mjs": "da63bb9d796ddfd24ed945b15c53f66a0400eb177886fd4f1c8fd10cafb5a91b", "js/developer/tools/distribution.mjs": "43dfdccc912693db46fd095fd78ae79325abab672d99f89fd569914ef3499cad", diff --git a/js/developer/starters/app/style.css b/js/developer/starters/app/style.css index e462192a..6e00f66a 100644 --- a/js/developer/starters/app/style.css +++ b/js/developer/starters/app/style.css @@ -1,4 +1,4 @@ -:root { color-scheme: light dark; font: 16px/1.5 system-ui, sans-serif; } +:root { color-scheme: light dark; font: 16px/1.5 sans-serif; } body { margin: 0; } #root { max-width: 32rem; margin: 3rem auto; padding: 0 1rem; display: grid; gap: .75rem; } h1 { margin: 0; font-size: 1.5rem; } diff --git a/test/unit/FrontendContractTests.cpp b/test/unit/FrontendContractTests.cpp index 6b0229cc..3c6e2a4c 100644 --- a/test/unit/FrontendContractTests.cpp +++ b/test/unit/FrontendContractTests.cpp @@ -270,6 +270,35 @@ WindowOptions windowReceivedBy(WebFrontConfig config) { } } // namespace +const Scenario windowBackground{"The window background is a CSS hexadecimal colour that is never guessed", [] { + given("valid colours", [&] { + then("short, long and translucent forms are read", [&] { + const auto white = frontend::detail::parseBackground("#fff"); + const auto navy = frontend::detail::parseBackground("#101c1d"); + const auto clear = frontend::detail::parseBackground("#00000080"); + require(white && navy && clear); + check((*white)[0] == 1.0f && (*white)[3] == 1.0f); + check((*navy)[0] == 16.0f / 255.0f && (*navy)[1] == 28.0f / 255.0f && (*navy)[2] == 29.0f / 255.0f && (*navy)[3] == 1.0f); + check((*clear)[3] == 128.0f / 255.0f); + }); + }); + given("invalid or empty text", [&] { + then("nothing is returned, so the toolkit's default stays", [&] { + check(!frontend::detail::parseBackground("")); + check(!frontend::detail::parseBackground("red")); + check(!frontend::detail::parseBackground("#12")); + check(!frontend::detail::parseBackground("#12345")); + check(!frontend::detail::parseBackground("#ggg")); + }); + }); + given("a configuration with a background", [&] { + const auto window = windowReceivedBy({.window = {.background = "#101c1d"}}); + then("the frontend receives it unchanged", [&] { + check(window.background == "#101c1d"); + }); + }); +}}; + const Scenario applicationChooses{"The application chooses the title and the size of the embedded window", [] { given("a configuration with a window title and size", [&] { const auto window = windowReceivedBy({.window = {.title = "SiliconForge", .width = 640, .height = 480}}); From b18c064406c2f805092b14605c7c87b9931083aa Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:27:17 +0100 Subject: [PATCH 005/173] Initialize GStreamer only for applications with media; trace start-up since exec (#611) --- docs/CHANGELOG.md | 3 ++ docs/WEBKITGTK.md | 13 +++++- include/webfront/frontend/WebKitGTK.hpp | 43 +++++++++++++++++-- include/webfront/frontend/WebKitGTKPolicy.hpp | 32 ++++++++++++++ include/webfront/frontend/Window.hpp | 7 ++- test/unit/FrontendContractTests.cpp | 6 +++ 6 files changed, 99 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 7bf710d7..8390b2a7 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,9 @@ these entries stays in the GitHub releases and the Git history. ## Unreleased +### Breaking +- WebKitGTK no longer initializes GStreamer unless the application sets `WindowOptions::media = true`: a page's audio and video cannot play by default, which removes the plugin scan from the start of every page (#611, `docs/WEBKITGTK.md`). + ### Added - Choose the colour under the page with `WindowOptions::background`, and read the start-up milestones of a WebKitGTK view with `WEBFRONT_STARTUP_TRACE=1` (#611, `docs/WEBKITGTK.md`). diff --git a/docs/WEBKITGTK.md b/docs/WEBKITGTK.md index 3dd4e6aa..efff99af 100644 --- a/docs/WEBKITGTK.md +++ b/docs/WEBKITGTK.md @@ -105,9 +105,20 @@ the page loads. Without a compositing manager the opacity is ignored and the win page that never paints still shows the window after the delay, and the navigation timeout and its diagnostics are unchanged. `WindowOptions::background` (`"#rgb"`, `"#rrggbb"` or `"#rrggbbaa"`) paints the colour under the page, so a dark interface does not flash white. `WEBFRONT_STARTUP_TRACE=1` prints the view's milestones (load started, first frame, -window shown) on standard error. A close request (`requestClose()`) made before the window is shown still ends the +window shown) on standard error, in milliseconds since the process was executed. A close request (`requestClose()`) made before the window is shown still ends the session. +### Media is opt-in + +WebKitGTK initializes GStreamer in the page's process shortly after a page loads, even if it never plays anything, and +scans every plugin when the registry is cold (the first launch of a user, and after each update of the system's +plugins): up to 1.7 s during which the WebSocket handshake and the frames of the page are blocked. Disabling the media +settings of the view does not prevent it. `WindowOptions::media` is therefore `false` by default: WebKit's processes +are launched with an empty `GST_PLUGIN_SYSTEM_PATH_1_0` and `GST_PLUGIN_PATH_1_0` and a registry of the application's profile +(`no-media-registry.bin`, so that the user's own registry is never rewritten); the application's environment is restored +at once. The consequence is that `