Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
loader: the unsupported-browser notice names the app the file belongs to (#741)
nyblnet6c01d23ad05f
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 9fb04d12..af1c6b8c 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -2373,6 +2373,11 @@ jobs:# opens only its URL in a new tab with no opener, and says it needs# the network.run: node scripts/test-slides-import-link-browser.mjs+ - name: The unsupported-browser notice names the app in Chromium+ # Each app's shell, built with the flags its own build:single passes,+ # says what it is ("a bento/slides presentation", …) — it said "a+ # bento/dash spreadsheet" in every app.+ run: node scripts/test-shell-unsupported-notice-browser.mjs- name: Under-specified documents boot in Chromium# parseDoc fills required fields only where absent and drops elements# that cannot render; unknown keys and element types survive (additivity).diff --git a/scripts/postbuild-compress.mjs b/scripts/postbuild-compress.mjsindex cca056c0..fdd0eeb0 100644--- a/scripts/postbuild-compress.mjs+++ b/scripts/postbuild-compress.mjs@@ -114,6 +114,12 @@ const flag = (name, fallback) => {}const generator = flag('generator', 'bento-slides')const titleFallback = flag('title', 'bento/slides')+// What the file IS, for the one message the loader writes before any app runs+// (the unsupported-browser notice). It said "bento/dash spreadsheet" in every+// app's shell — a slides deck told its reader it was a spreadsheet.+const KIND = { 'bento-slides': 'presentation', 'bento-dash': 'spreadsheet', 'bento-spaces': 'space', 'bento-type': 'document' }+if (!/^[\w/ .-]+$/.test(titleFallback)) throw new Error(`--title must be plain words, got ${JSON.stringify(titleFallback)}`)+const fileKind = `${titleFallback} ${KIND[generator] ?? 'file'}`// How the inflated runtime is started. `cascade` (the default since 1.1.1):// see below. `blob` (the 1.1.0 loader): a module import from a blob: URL. `inline`: an inline <script type="module"> whose// textContent is the inflated bundle — no blob: URL at all, so it runs where a@@ -468,7 +474,7 @@ const loader = `// never said what kind of file this is, and never mentioned that the data// is plain readable JSON in this same file, which is the one route out that// works with no capable browser at all.- fail('<b>This is a bento/dash spreadsheet.</b><br>Opening it needs a browser released in 2023 or later \\u2014 Safari 16.4+, Firefox 113+, or a current Chrome or Edge.<br><br>Nothing is lost: your data is stored as plain readable JSON inside this same file. Open it in a newer browser, or open it in a text editor and look for the block marked "bento-doc".')+ fail('<b>This is a ${fileKind}.</b><br>Opening it needs a browser released in 2023 or later \\u2014 Safari 16.4+, Firefox 113+, or a current Chrome or Edge.<br><br>Nothing is lost: your data is stored as plain readable JSON inside this same file. Open it in a newer browser, or open it in a text editor and look for the block marked "bento-doc".')return}${INFLATE_JS}${codec ? codec.LOADER_DECODER : ''}diff --git a/scripts/test-shell-unsupported-notice-browser.mjs b/scripts/test-shell-unsupported-notice-browser.mjsnew file mode 100644index 00000000..cd4992d9--- /dev/null+++ b/scripts/test-shell-unsupported-notice-browser.mjs@@ -0,0 +1,78 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+// The unsupported-browser notice names the app the file belongs to.+//+// node scripts/test-shell-unsupported-notice-browser.mjs+//+// WHAT THIS PROVES. The loader's one message written before any app runs — a+// browser too old to unpack the shell — said "This is a bento/dash spreadsheet"+// in EVERY app's shell, so a slides deck told its reader it was a spreadsheet.+// For each app, a shell is built by the real scripts/postbuild-compress.mjs+// with the exact --generator/--title flags that app's own build:single passes+// (read from its package.json, so the rig cannot drift from the builds), and+// opened in Chromium with TextDecoder taken away, which is what the loader+// tests for. The notice must name that app and its kind of file, and no other.+// When the real slides shell is built, it is checked the same way.+import { readFileSync, writeFileSync, mkdtempSync, existsSync } from 'node:fs'+import { join, dirname } from 'node:path'+import { tmpdir } from 'node:os'+import { fileURLToPath } from 'node:url'+import { execFileSync } from 'node:child_process'+const { chromium } = await import(process.env.PLAYWRIGHT_MODULE || 'playwright')++let checks = 0+let failures = 0+function ok(cond, msg) {+ checks+++ if (!cond) { failures++; console.log(` FAIL ${msg}`) } else console.log(` ok ${msg}`)+}+const root = join(dirname(fileURLToPath(import.meta.url)), '..')+const dir = mkdtempSync(join(tmpdir(), 'loader-notice-'))+const WANT = { slides: 'This is a bento/slides presentation.', dash: 'This is a bento/dash spreadsheet.', spaces: 'This is a bento/spaces space.', type: 'This is a bento/type document.' }++// the flags each app's build:single hands postbuild-compress, verbatim+function flagsOf(app) {+ const script = JSON.parse(readFileSync(join(root, app, 'package.json'), 'utf8')).scripts['build:single']+ const tail = script.slice(script.indexOf('postbuild-compress.mjs') + 'postbuild-compress.mjs'.length).trim().split(/\s+/).slice(1).join(' ')+ const args = []+ for (const m of tail.matchAll(/(--\w+)\s+(?:"([^"]*)"|(\S+))/g)) args.push(m[1], m[2] ?? m[3])+ return args+}+const NO_DECODER = () => { delete window.TextDecoder }++const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH, headless: true })+async function notice(file) {+ const ctx = await browser.newContext()+ await ctx.addInitScript(NO_DECODER)+ const p = await ctx.newPage()+ await p.goto('file://' + file)+ await p.waitForFunction(() => /needs a browser released/.test(document.body.innerText), null, { timeout: 8000 }).catch(() => {})+ const text = await p.evaluate(() => document.body.innerText)+ await ctx.close()+ return text+}+try {+ for (const app of Object.keys(WANT)) {+ const args = flagsOf(app)+ const file = join(dir, `${app}.html`)+ writeFileSync(file, `<!DOCTYPE html><html><head><meta charset="UTF-8"><title>t</title>+<script type="module" crossorigin>window.bento = { doc: {} }</script>+<style rel="stylesheet" crossorigin>#app{color:red}</style>+<script type="application/bento+json" id="bento-doc"></script></head>+<body><style>#bento-splash{opacity:.5}</style><div id="bento-splash"><div>splash</div></div><div id="app"></div></body></html>`)+ execFileSync(process.execPath, [join(root, 'scripts/postbuild-compress.mjs'), file, ...args], { cwd: join(root, 'slides'), encoding: 'utf8', env: { ...process.env, ZOPFLI: '0' } })+ const text = await notice(file)+ const others = Object.entries(WANT).filter(([a]) => a !== app).filter(([, w]) => text.includes(w))+ ok(text.includes(WANT[app]) && others.length === 0,+ `${app} (flags: ${args.join(' ') || 'none'}): "${WANT[app]}"${text.includes(WANT[app]) ? '' : ` — got "${(text.match(/This is a[^.]*\./) || ['nothing'])[0]}"`}`)+ }+ const real = join(root, 'slides/dist-single/Bento_Slides.bento.html')+ if (existsSync(real)) {+ const text = await notice(real)+ ok(text.includes(WANT.slides) && !/spreadsheet/.test(text), `the built slides shell says "${WANT.slides}"`)+ } else console.log(' skip the built slides shell (not built)')+} finally {+ await browser.close()+}+console.log(`\n${checks - failures}/${checks} checks passed`)+if (failures) process.exit(1)