Skip to content

Commit 0764266

Browse files
committed
fix: a tab that only saves skips the check for a player it does not need; a frame with no origin and a tab off https get words of their own; no name placeholders beside the way on (#116)
1 parent f11fc3d commit 0764266

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

‎src/assets/site.css‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,8 @@ html[data-standalone] .play { padding: 1rem; }
11471147
.play-meta { color: var(--muted); font-size: 0.8125rem; line-height: 1.35; }
11481148
.play-title:empty, .play-meta:empty { border-radius: 4px; background: var(--border); }
11491149
.play-title:empty { width: 11rem; height: 0.9rem; margin: 0.2rem 0; }
1150-
/* A link that carried no activity has no name to wait for. */
1151-
.play[data-state="error"] :is(.play-title, .play-meta):empty { display: none; }
1150+
/* A link that carried no activity has no name to wait for, nor has an activity that plays elsewhere. */
1151+
.play:is([data-state="error"], [data-state="elsewhere"]) :is(.play-title, .play-meta):empty { display: none; }
11521152
.play-meta:empty { width: 6rem; height: 0.7rem; margin: 0.2rem 0; }
11531153
.play-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0; }
11541154
.play-actions [hidden] { display: none; }

‎src/h5p/play/play-page.ts‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,11 @@ function fail(heading: string, text: string, fixable = false): void {
220220
show('error', text ? `${heading}. ${text}` : `${heading}.`)
221221
}
222222

223-
/** Why the player cannot start where the page is: no secure context, or a browser that keeps it from starting. */
224-
type Why = 'insecure' | 'kept'
223+
/**
224+
* Why the player cannot start where the page is: no secure context; a frame sandboxed without an
225+
* origin, which is the chat's doing; or a browser that keeps the player from starting.
226+
*/
227+
type Why = 'insecure' | 'sandboxed' | 'kept'
225228

226229
/**
227230
* Why the player cannot start here, as the browser shows it before anything is built: a page
@@ -230,7 +233,7 @@ type Why = 'insecure' | 'kept'
230233
*/
231234
function cannotStart(): Why | null {
232235
if (!window.isSecureContext) return 'insecure'
233-
if (self.origin === 'null') return 'kept'
236+
if (self.origin === 'null') return 'sandboxed'
234237
try {
235238
return navigator.serviceWorker ? null : 'kept'
236239
} catch {
@@ -248,17 +251,27 @@ function cannotStart(): Why | null {
248251
*/
249252
function elsewhere(why: Why): void {
250253
const given = Object.fromEntries(links)
251-
const address = `${location.origin}${location.pathname}${Object.keys(given).length ? fragmentWithLinks(ownFragment, given, false) : ownFragment}`
254+
// The address's own origin, which is the page's URL's even in a frame with no origin of its own
255+
// (`self.origin` is "null" there, `location.origin` is not: Chromium, Firefox and WebKit,
256+
// 2026-11-25). A tab of its own off https is sent to https, where the player starts.
257+
const origin = framed ? location.origin : location.origin.replace(/^http:/, 'https:')
258+
const address = `${origin}${location.pathname}${Object.keys(given).length ? fragmentWithLinks(ownFragment, given, false) : ownFragment}`
252259
elsewhereAddress.value = address
253260
elsewhereOpen.href = address
254261
elsewhereOpen.hidden = !framed
255262
elsewhereCopy.textContent = 'Copy'
256263
if (framed) {
257264
elsewhereTitle.textContent = 'Open it in a new tab'
258-
elsewhereText.textContent = why === 'insecure'
259-
? 'This chat’s page is not on a secure connection, and the player starts only on one. In a tab of its own it plays, still built in your browser.'
260-
: 'Your browser does not let the player start inside this chat’s reply, as where it blocks third-party cookies. In a tab of its own it plays, still built in your browser.'
265+
elsewhereText.textContent = {
266+
insecure: 'This chat’s page is not on a secure connection, and the player starts only on one. In a tab of its own it plays, still built in your browser.',
267+
sandboxed: 'This chat does not let the player start inside its reply. In a tab of its own it plays, still built in your browser.',
268+
kept: 'Your browser does not let the player start inside this chat’s reply, as where it blocks third-party cookies. In a tab of its own it plays, still built in your browser.'
269+
}[why]
261270
elsewhereNote.textContent = 'If no tab opens, copy this address into your browser.'
271+
} else if (why === 'insecure') {
272+
elsewhereTitle.textContent = 'Open it on a secure connection'
273+
elsewhereText.textContent = 'This page is not on a secure connection, and the player starts only on one. Its https address is below.'
274+
elsewhereNote.textContent = 'Copy this address into your browser.'
262275
} else {
263276
elsewhereTitle.textContent = 'Open it in another browser'
264277
elsewhereText.textContent = 'The player needs a Service Worker, which this browser does not give, as an app’s built-in browser often does not. Chrome, Edge, Firefox and Safari give one.'
@@ -781,8 +794,9 @@ async function start(): Promise<void> {
781794
wanted = namedFiles(source)
782795
const written = source as { title?: unknown, type?: unknown }
783796
about(written.title, written.type)
784-
// Where the player cannot start here, nothing is built for it: the way on at once.
785-
const why = cannotStart()
797+
// Where the player cannot start here, nothing is built for it: the way on at once. Not in a tab
798+
// that only saves, which builds and downloads the package with no player.
799+
const why = savingOnly ? null : cannotStart()
786800
if (why) return elsewhere(why)
787801
// A tab that only saves fetches what the link gave addresses for first, and builds once.
788802
const { linked } = savingOnly ? linksFor(wanted) : { linked: {} }

0 commit comments

Comments
 (0)