LayerFS's trajectory page is served by a loopback service the host starts once a store exists (no write into the install), keeps its view in location.hash across its 5 s reload, reports every skipped secret-shaped file in sorted order (#477), and drops the unloaded sample. By @Mola-maker. Run at dfa99f7e merged onto current main: - mote (macOS, Bun 1.4.2, temp HOME): bun test in packages/layerfs, 64 pass 0 fail, 2 of 2; bun scripts/check.mjs layerfs ok; the temp HOME held nothing from layerfs afterwards. - WSL2 Ubuntu 24.04 (temp HOME): 64 pass 0 fail, 2 of 2 (#477's item 3 was red here on f3633eaf8). - Broken by hand: dropping the `location.hash =` assignment in page/app.js turns the hash test red. Earlier rounds' breaks (Origin/Host checks, < escape, start gates, nosniff, sort, restore/settle/round, reload guard) each went red, see the 05:18 and 05:45 reviews. - Earlier round: the page in a magpie-shaped sandboxed frame with pagePolicy CSP, Chromium and WebKit. - PR checks: test and on-npm pass. Not tried: a real magpie window.
43 lines
1.8 KiB
JavaScript
43 lines
1.8 KiB
JavaScript
// The way in: this page's only job is to navigate its frame to the
|
|
// plugin host's own localhost service (page-service.mjs), the way
|
|
// page-chat's boot.js does it.
|
|
//
|
|
// It must jump directly, never probe first: the page's CSP is
|
|
// connect-src 'none', so no network probe of any kind is possible —
|
|
// even a no-cors probe is rejected, and a probe could never tell
|
|
// whether the service is up. The only network action a page like this
|
|
// has is navigating elsewhere.
|
|
//
|
|
// The port comes from the plugin's options (pagePort), falling back to
|
|
// the service's default (page-service.mjs's DEFAULT_PAGE_PORT — a
|
|
// static file cannot import it, so the number is repeated here and the
|
|
// two must match). A second host on the same machine fails to bind and
|
|
// leaves its page pointing at the first host's service, which serves
|
|
// the same store — the same behaviour page-chat relies on.
|
|
//
|
|
// The language rides along as a query: the served page is no longer
|
|
// inside magpie, so it cannot ask magpie.ready for it. The service
|
|
// hands it to the UI as LayerfsTheme; the theme itself stays with the
|
|
// system media query, which the served page's CSS already follows.
|
|
(async () => {
|
|
const DEFAULT_PORT = 43717
|
|
let port = DEFAULT_PORT
|
|
let lang = ""
|
|
|
|
try {
|
|
const t = await window.magpie?.ready
|
|
if (t && typeof t.lang === "string") lang = t.lang
|
|
} catch { /* no bridge: the service falls back to English */ }
|
|
|
|
try {
|
|
const o = await window.magpie?.options?.get?.()
|
|
const n = Number(o?.pagePort)
|
|
if (Number.isInteger(n) && n > 0 && n < 65536) port = n
|
|
} catch { /* no options: the default port */ }
|
|
|
|
const q = new URLSearchParams()
|
|
if (lang) q.set("lang", lang)
|
|
const qs = q.toString()
|
|
location.replace(`http://127.0.0.1:${port}/${qs ? `?${qs}` : ""}`)
|
|
})()
|