@@ -57,12 +57,24 @@ import { baseName, compactSource, fragmentFromSource, fragmentWithLinks, kindOf,
5757 * the activity can then be played there. Such a tab builds from files only, never from an
5858 * address: what it fetched, or what the person chose in its place.
5959 *
60- * What is seen is one stage, in one of six states (`data-state` on `main`): `building`, a loader
60+ * The player may not start where the page is, for the frame's sake or the browser's, not the
61+ * activity's (#116): a browser that blocks third-party cookies lets no framed page of another site
62+ * register a worker (Chrome's setting, which Incognito turns on, and Firefox's, 2026-11-25); WebKit
63+ * framed by another site could not read the archive the page had just built; a frame sandboxed
64+ * without an origin, or under a page on plain http, has no worker at all; nor has an app's built-in
65+ * browser. A tab of the page's own plays in each of the frame's cases: it is first-party, with its
66+ * own storage and worker, on https. So where the page knows from the browser that the player cannot
67+ * start, before anything is built, or the player says it could not register, read or store what the
68+ * page gave it, the page says so and offers the tab, or, in a tab already, another browser, with the
69+ * address to copy where no tab opens. Not a player without the worker: some activities would play
70+ * in part, which confuses more than it helps (the owner, 2026-11-25).
71+ *
72+ * What is seen is one stage, in one of seven states (`data-state` on `main`): `building`, a loader
6173 * over the place the player takes; `fetching`, the loader with how much of a file has come so far,
6274 * from the parent or from its address; `asking`, for the person's files; `error`, with the one
63- * thing to do about it; `ready `, the player; `saved`, in a tab that only saves, the package saved
64- * and the tab about to close. The parent is told each as a `status`, in words a screen reader is
65- * told too.
75+ * thing to do about it; `elsewhere `, the way to a tab or another browser where the player cannot
76+ * start here; `ready`, the player; `saved`, in a tab that only saves, the package saved and the tab
77+ * about to close. The parent is told each as a `status`, in words a screen reader is told too.
6678 */
6779
6880const $ = < T extends HTMLElement > ( id : string ) : T => document . getElementById ( id ) as T
@@ -84,6 +96,13 @@ const savedBox = $('saved')
8496const savedText = $ ( 'saved-text' )
8597const savedStay = $ < HTMLButtonElement > ( 'saved-stay' )
8698const savedPlay = $ < HTMLButtonElement > ( 'saved-play' )
99+ const elsewhereBox = $ ( 'elsewhere' )
100+ const elsewhereTitle = $ ( 'elsewhere-title' )
101+ const elsewhereText = $ ( 'elsewhere-text' )
102+ const elsewhereOpen = $ < HTMLAnchorElement > ( 'elsewhere-open' )
103+ const elsewhereNote = $ ( 'elsewhere-note' )
104+ const elsewhereAddress = $ < HTMLInputElement > ( 'elsewhere-address' )
105+ const elsewhereCopy = $ < HTMLButtonElement > ( 'elsewhere-copy' )
87106const errorTitle = $ ( 'error-title' )
88107const errorText = $ ( 'error-text' )
89108const fix = $ < HTMLAnchorElement > ( 'fix' )
@@ -102,7 +121,7 @@ const edit = $<HTMLAnchorElement>('edit')
102121const player = $ ( 'player' ) as HTMLElementTagNameMap [ 'h5p-player' ]
103122player . runtime = runtime
104123
105- type State = 'building' | 'fetching' | 'asking' | 'ready' | 'error' | 'saved'
124+ type State = 'building' | 'fetching' | 'asking' | 'ready' | 'error' | 'elsewhere' | ' saved'
106125type Opened = Awaited < ReturnType < typeof openPack > >
107126/** The pack, opened at the first build and kept for the next, which a file chosen later starts. */
108127let opened : Promise < Opened > | null = null
@@ -172,6 +191,7 @@ function show(state: State, text: string): void {
172191 loader . hidden = state !== 'building' && state !== 'fetching'
173192 filesBox . hidden = state !== 'asking'
174193 errorBox . hidden = state !== 'error'
194+ elsewhereBox . hidden = state !== 'elsewhere'
175195 savedBox . hidden = state !== 'saved'
176196 // The way to the build page is the problem's own button where it has one.
177197 edit . hidden = state === 'error' && ! fix . hidden
@@ -200,6 +220,67 @@ function fail(heading: string, text: string, fixable = false): void {
200220 show ( 'error' , text ? `${ heading } . ${ text } ` : `${ heading } .` )
201221}
202222
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'
228+
229+ /**
230+ * Why the player cannot start here, as the browser shows it before anything is built: a page
231+ * outside a secure context, or with no origin, has no Service Worker, as one whose browser gives
232+ * none. `null` where it may start; the player says the rest.
233+ */
234+ function cannotStart ( ) : Why | null {
235+ if ( ! window . isSecureContext ) return 'insecure'
236+ if ( self . origin === 'null' ) return 'sandboxed'
237+ try {
238+ return navigator . serviceWorker ? null : 'kept'
239+ } catch {
240+ return 'kept'
241+ }
242+ }
243+
244+ /**
245+ * The way on where the player cannot start here (#116). Framed: a tab of this page's own, which
246+ * the parent opens where it opens links (the click handler below hands it the address) and the
247+ * link opens otherwise, where the frame lets it. In a tab: another browser. The address is there
248+ * to copy in both, since whether a tab opened is not this page's to see. It carries the addresses
249+ * the parent gave for the person's files, so a tab plays them from there, and not the wish to
250+ * save. Download stays where a package was built: it is the person's even where it does not play.
251+ */
252+ function elsewhere ( why : Why ) : void {
253+ const given = Object . fromEntries ( links )
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 ( / ^ h t t p : / , 'https:' )
258+ const address = `${ origin } ${ location . pathname } ${ Object . keys ( given ) . length ? fragmentWithLinks ( ownFragment , given , false ) : ownFragment } `
259+ elsewhereAddress . value = address
260+ elsewhereOpen . href = address
261+ elsewhereOpen . hidden = ! framed
262+ elsewhereCopy . textContent = 'Copy'
263+ if ( framed ) {
264+ elsewhereTitle . textContent = 'Open it in a new tab'
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 ]
270+ 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.'
275+ } else {
276+ elsewhereTitle . textContent = 'Open it in another browser'
277+ 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.'
278+ elsewhereNote . textContent = 'Copy this address into another browser.'
279+ }
280+ playerBox . hidden = true
281+ show ( 'elsewhere' , `${ elsewhereTitle . textContent } . ${ elsewhereText . textContent } ` )
282+ }
283+
203284/** What the activity is, under the stage: its title, and its type with the package's size once built. */
204285function about ( name : unknown , type : unknown , size ?: number | string ) : void {
205286 if ( typeof name === 'string' && name . trim ( ) ) title . textContent = name
@@ -401,16 +482,23 @@ function tooBig(size: number): void {
401482 saying ( `This .h5p is ${ sized ( size ) } , more than the chat saves with one press. ${ BY_HAND } ` )
402483}
403484
404- /** The package handed to a parent that saves files itself, which says how that went; no word in a minute is taken as no. */
485+ /**
486+ * The package handed to a parent that saves files itself, which says how that went. No word in a
487+ * few seconds is said with the way by hand (#116): a parent that never answers left the person
488+ * waiting a minute, and one that asks the person first still has its yes said when it comes.
489+ */
405490function handOver ( file : File ) : void {
406491 handed = true
407492 saying ( 'The chat is saving the .h5p…' , { busy : true } )
408493 toParent ( { type : 'save' , id : ++ handedId , file } )
409494 clearTimeout ( handedTimer )
410- handedTimer = setTimeout ( ( ) => saveDone ( false ) , 60_000 )
495+ handedTimer = setTimeout ( ( ) => {
496+ handed = false
497+ saying ( `Nothing saved yet? ${ BY_HAND_TOO } ` )
498+ } , 10_000 )
411499}
412500
413- /** How the parent's save of the last package handed went. A yes that comes after the minute is still said. */
501+ /** How the parent's save of the last package handed went. A yes that comes after the wait is still said. */
414502function saveDone ( ok : boolean ) : void {
415503 clearTimeout ( handedTimer )
416504 handed = false
@@ -706,6 +794,10 @@ async function start(): Promise<void> {
706794 wanted = namedFiles ( source )
707795 const written = source as { title ?: unknown , type ?: unknown }
708796 about ( written . title , written . type )
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 ( )
800+ if ( why ) return elsewhere ( why )
709801 // A tab that only saves fetches what the link gave addresses for first, and builds once.
710802 const { linked } = savingOnly ? linksFor ( wanted ) : { linked : { } }
711803 if ( Object . keys ( linked ) . length ) return fetchThenBuild ( linked )
@@ -723,9 +815,27 @@ player.addEventListener('ready', () => {
723815} )
724816player . addEventListener ( 'error' , ( event ) => {
725817 if ( player . state === 'ready' ) return
726- fail ( 'It was built, but does not play' , ( event as unknown as CustomEvent < { message : string } > ) . detail . message , true )
818+ const { code, message } = ( event as unknown as CustomEvent < { code ?: string , message : string } > ) . detail
819+ // Not the activity's: a worker that could not register is the browser's. Framed, so is an
820+ // archive the player could not read or store, which the page built a moment ago and which plays
821+ // in a tab (WebKit framed by another site, 2026-11-25).
822+ if ( code === 'no-worker' || ( framed && ( code === 'bad-archive' || code === 'quota' ) ) ) return elsewhere ( 'kept' )
823+ fail ( 'It was built, but does not play' , message , true )
727824} )
728825
826+ // The address of the way on, copied, or left selected for the person's own keys where no clipboard is let.
827+ elsewhereAddress . addEventListener ( 'focus' , ( ) => elsewhereAddress . select ( ) )
828+ elsewhereCopy . addEventListener ( 'click' , async ( ) => {
829+ let copied = false
830+ try {
831+ await navigator . clipboard . writeText ( elsewhereAddress . value )
832+ copied = true
833+ } catch {
834+ elsewhereAddress . select ( )
835+ try { copied = document . execCommand ( 'copy' ) } catch { /* selected, at least */ }
836+ }
837+ if ( copied ) elsewhereCopy . textContent = 'Copied'
838+ } )
729839savedStay . addEventListener ( 'click' , stay )
730840// The package that was saved, played in the tab that was kept open.
731841savedPlay . addEventListener ( 'click' , ( ) => {
0 commit comments