@dasl/tile-loader 3.2.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -75,7 +75,15 @@ Four cooperating layers, all talking over `postMessage`:
75
75
  - `conf.namedOrigin` (`conf.tileHost` before 3.1, still accepted): a tile origin to run tiles on, by name
76
76
  (`notes.tiles.example`), instead of a fresh random one per load; for a
77
77
  deployment whose tiles share an origin or keep their storage. The tile server
78
- has to recognise the name.
78
+ has to take the name for a tile origin: list it in the `namedOrigins` of
79
+ [`@dasl/tile-server`](../tile-server). A tile on a name it does not take
80
+ does not start: the dock will not frame it. A name that is a tile's CID is
81
+ not one to give here, and throws: see `conf.cidOrigins`.
82
+ - `conf.cidOrigins`: `true` to run each tile on the origin its own content
83
+ names, the CID of its manifest. What the tile stores there goes as on an
84
+ origin made for the load: the origin is wiped when the tile is closed and
85
+ before it starts, and the frame is credentialless. `false` when left out.
86
+ See "Origins named by a tile's CID". Not with `namedOrigin` (it throws).
79
87
  - `conf.webrtcGuard`: `'exhaust'` (default) has the shuttle spend Chromium's
80
88
  per-process WebRTC budget before the tile loads (see Security model); `'none'`
81
89
  skips it, for hosts that block WebRTC themselves (an Electron app with the
@@ -130,11 +138,19 @@ Four cooperating layers, all talking over `postMessage`:
130
138
 
131
139
  - **`await renderCard(options?)`** — a DOM element showing the tile's card
132
140
  (metadata only; safe to render many at once). `options.contentHeight` presets the
133
- height used when the card is clicked to expand.
134
- - **`renderContent(height?)`** — the sandboxed iframe that runs the tile.
141
+ height used when the card is clicked to expand, and `options.frame` is what
142
+ you ask of the frame it then opens, as for `renderContent()`.
143
+ - **`renderContent(height?, options?)`** — the sandboxed iframe that runs the
144
+ tile. `options` say what else the frame is to be: see "The frame a tile
145
+ runs in".
135
146
  - **`await close()`** — you are done with the tile: its runtime tidies up, its
136
147
  frame is removed, and the tile forgets it (a `close` event says when). It can
137
148
  be rendered again afterwards. See "When a tile goes away".
149
+ - **`ephemeral`** — whether what the tile stores goes with each run of it:
150
+ the origin it runs on is wiped when it is closed, and holds nothing from
151
+ before when it starts. `true` on an origin made for the load and on the
152
+ origin a tile's CID names (see "Origins named by a tile's CID"), `false` on
153
+ a named origin.
138
154
  - The **`load`** event — the tile's runtime is up, and its root document is
139
155
  being fetched for it. It says that all went well so far, not that anything
140
156
  is on screen; and for a tile that cannot start it never comes, which is
@@ -174,6 +190,20 @@ Four cooperating layers, all talking over `postMessage`:
174
190
  the deadline (`timeout`, stage `content`); with no deadline, or a long
175
191
  one, the tile's worker gives up on it after a minute, and that is
176
192
  reported as `content`.
193
+ - `integrity`: the tile runs on the origin its CID names (`cidOrigins`),
194
+ and the runtime there refused the manifest it was handed: not the one
195
+ that CID names, or not one it reads (a .tile file whose header is not
196
+ written in DRISL's one form). Nothing of the tile is served.
197
+ - `wipe`: the tile runs on the origin its CID names, and that origin could
198
+ not be wiped before the tile started there, tried twice, three seconds
199
+ apart (the tile server said it was not, or did not answer within ten
200
+ seconds): what an earlier run left could still be there, so the tile is
201
+ not run. Render it again to try again.
202
+
203
+ For a tile on the origin its CID names, `version` also means that the
204
+ tile server's dock did not say that its runtime holds such an origin to
205
+ its tile (a server from before 4.0, or another that does not): the tile is
206
+ not run there, and nothing of it is handed down.
177
207
 
178
208
  A start (a frame the tile is attached to, each time it loads) fires one
179
209
  `error` at most, and none once `close()` is called: closing ends the start,
@@ -187,7 +217,8 @@ Four cooperating layers, all talking over `postMessage`:
187
217
  origin can have the start reported as failed, for any of these reasons.
188
218
  On an origin made for the one load, nothing of the tile's runs before it
189
219
  has started and no other tile is there; tiles that share a named origin
190
- can do it to one another.
220
+ can do it to one another, and so can the runs of a tile on the origin its
221
+ CID names.
191
222
 
192
223
  A tile from AT has one more `error`, before its runtime is told to load:
193
224
  its content could not be had, and `ev.error` is the `TileLoadError` that
@@ -278,6 +309,300 @@ Each is a subpath export; add the ones you need:
278
309
  the HTTP-fetching loaders extend. The `TileLoader` and `TilePathLoader` interfaces
279
310
  are exported from the package root for writing your own.
280
311
 
312
+ ## The frame a tile runs in
313
+
314
+ `renderContent(height?, options?)` makes the frame, and `renderCard({ frame })`
315
+ hands the same options to the frame its card opens. Each option is checked,
316
+ and one the loader cannot honour throws (a card is refused when it is made),
317
+ so that you are never left believing in a frame you do not have.
318
+
319
+ | Option | When left out | What it is |
320
+ | --- | --- | --- |
321
+ | `sandbox` | `'allow-scripts allow-same-origin allow-forms'` | the frame's sandbox attribute in full |
322
+ | `credentialless` | `true`, unless the tile runs on a named origin (`tile.ephemeral`) | whether the frame is credentialless |
323
+ | `tabindex` | none: the frame is in the tab order, unless the focus guard is on it | the frame's tabindex, `-1` to have Tab pass over the tile |
324
+ | `refuse` | `['sync-xhr']` | features of the browser to take from the tile, the list in full |
325
+
326
+ A frame of your own making (`attachIframe()`) gets none of these: give it the
327
+ attributes yourself (`sandbox`, `credentialless`, `tabindex`, `allow`), before
328
+ the frame goes in the document. `allow="sync-xhr 'none'"` is what the loader
329
+ writes when nothing is said of `refuse`.
330
+
331
+ ### `sandbox`
332
+
333
+ The runtime the frame loads has a sandbox of its own (`tileSandbox` in
334
+ `@dasl/tile-lexicon`: `allow-downloads allow-forms allow-modals
335
+ allow-same-origin allow-scripts`), and a frame's sandbox only ever takes
336
+ away: a tile gets what both grant. The frame leaves out dialogs and
337
+ downloads, so a tile in your page:
338
+
339
+ - raises no dialog: `alert()` returns at once, `confirm()` false, `prompt()`
340
+ null, `print()` does nothing, and a page that asks to hold the user when
341
+ they leave (`beforeunload`) is not heard. The same through the runtime's
342
+ page above the tile, which the tile can script;
343
+ - starts no download, by itself or on a press: not from a link with
344
+ `download`, a `blob:` or `data:` address, or a file served as an
345
+ attachment.
346
+
347
+ It keeps what it runs on: scripts, its own origin and so its worker and its
348
+ storage (`localStorage`, IndexedDB, the Cache API), forms it submits to
349
+ itself, the link, size and data protocols, closing and the wipe. And what the
350
+ sandbox has no say in stays as it was: on a press, a tile can still open a
351
+ file picker, play sound and video, and write to the clipboard with
352
+ `execCommand('copy')`; it gets no fullscreen and no reading of the clipboard
353
+ unless your frame's `allow` attribute gives them, and no pointer lock, popups
354
+ or navigation of your page, which the runtime's own sandbox refuses.
355
+
356
+ A page where someone runs one tile on purpose, a workbench, may want dialogs
357
+ and downloads back (Blastile's preview asks for them):
358
+
359
+ ```js
360
+ tile.renderContent(300, { sandbox: 'allow-scripts allow-same-origin allow-forms allow-modals allow-downloads' });
361
+ ```
362
+
363
+ `allow-scripts` and `allow-same-origin` have to be in it: without them the
364
+ runtime's service worker cannot run and no tile loads. `allow-forms` is yours
365
+ to leave out, and then a tile's forms do nothing. A token the runtime does
366
+ not grant would do nothing under it, so the loader refuses it.
367
+
368
+ ### `credentialless`
369
+
370
+ A tile's origin is a subdomain of the loading server's site
371
+ (`<random>.example.site`), and cookies go by site, not by origin: in a plain
372
+ frame a tile reads the cookies that site keeps for its whole domain, and
373
+ sets cookies there. In a credentialless frame Chromium gives everything
374
+ inside cookies and storage of their own, empty to begin with and gone with
375
+ the page: the tile sees none of the site's cookies, what it sets stays in that
376
+ jar, and the browser's password manager keeps out of the frame. Firefox and
377
+ Safari ignore the attribute: there it protects nothing.
378
+
379
+ So the frame is credentialless, unless the tile runs on a named origin
380
+ (below). A host that wants it otherwise says so, either way:
381
+
382
+ ```js
383
+ tile.renderContent(300, { credentialless: false });
384
+ ```
385
+
386
+ `true` or `false`; anything else throws, the empty text of an attribute that
387
+ is there included. What to know of it:
388
+
389
+ - The tiles of one page share that jar, about 11 kB in Chrome, and all of it
390
+ goes to the loading server with every request a tile there makes. Over
391
+ HTTP/2 Chrome sends each cookie as a field of its own, and a server counts
392
+ that as about 19 kB of headers. A loading server that refuses a request of
393
+ that size, or a front before it that does (Node reads 16 kB by default,
394
+ Caddy 16 KiB from 2.11.6 on, some fronts 8 kB to a line), leaves one tile
395
+ able to keep the next ones on its page from loading, until the page is
396
+ loaded again. `@dasl/tile-server`'s command reads 1 MiB; its README says
397
+ what a front has to take.
398
+ - A tile on a named origin (`namedOrigin`) is there to find its storage
399
+ again, and a credentialless frame loses it with every page: its frame is a
400
+ plain one unless you ask. In Chrome a plain frame has the cookies of the
401
+ loading server's domain, which Chrome does not keep apart by site unless its
402
+ user blocks third-party cookies. A tile on the origin its CID names
403
+ (`cidOrigins`) keeps nothing from one run to the next, and its frame is
404
+ credentialless, as on an origin made for the load.
405
+
406
+ Closing a tile in such a frame wipes its origin from a credentialless frame
407
+ too, since that is where what it stored is.
408
+
409
+ ### `tabindex`
410
+
411
+ Whoever has the focus in a tile types into the tile. Every key goes to it,
412
+ Tab and Escape with the rest, and your page hears none of them, so a tile
413
+ that will not let Tab go keeps the keyboard; and each key pressed there
414
+ counts as its user having acted in the tile. On a page with more on it than
415
+ tiles, someone tabbing down it should end up in neither position: `-1` has
416
+ the Tab key pass over the tile. A click in the tile gives it the keyboard as
417
+ before.
418
+
419
+ Then nobody reaches the tile with the keyboard alone unless you give them the
420
+ means, so do: a control of your own that puts the keyboard in the frame
421
+ through its window (`frame.contentWindow.focus()`).
422
+
423
+ The focus guard (see "The keyboard" below) does all of this itself: a frame
424
+ it guards is out of the tab order whatever its `tabindex` says, and in its
425
+ place in the tab order the guard puts a stop of its own, which is the way
426
+ in. Where you would rather have your own, tell the guard (`tabOrder:
427
+ 'out'`) and let it put the keyboard in, or it takes that focus for a
428
+ script's and gives it back:
429
+
430
+ ```js
431
+ import { guardFocus } from '@dasl/tile-loader/guard';
432
+
433
+ const frame = tile.renderContent(300);
434
+ const guard = guardFocus(tile, frame, { tabOrder: 'out' });
435
+ const enter = document.createElement('button');
436
+ enter.textContent = `Use the keyboard in ${tile.manifest.name || 'this tile'}`;
437
+ enter.addEventListener('click', () => guard.focus());
438
+ document.body.append(enter, frame);
439
+ ```
440
+
441
+ After that the next Tab goes to the first thing in the tile that takes it.
442
+ Tab past the last, or Shift+Tab before the first, comes back to your page if
443
+ the tile lets it: from inside, only the tile and the browser's own shortcuts
444
+ let the keyboard out. `engage()` has a way in of its own, its layer.
445
+
446
+ With the guard, a user who goes in with a press (a click or a tap on your
447
+ control) has the keyboard put on into the tile itself by its dock, so that
448
+ what they type next reaches the tile at once: its document, and a field of
449
+ it once they press or Tab into one, or the tile puts the keyboard there. A
450
+ Tab from there goes on from wherever they were in the tile last, if they
451
+ had been in it. One who goes in from the keyboard (Enter or Space on your
452
+ control) has it left where the next Tab goes to the first thing in the
453
+ tile, and what they type before that Tab reaches nothing. Call
454
+ `guard.focus()` from your control's own handler: called from anywhere else
455
+ (after an `await`, say), the guard cannot tell a press from a key, and
456
+ takes it for a key.
457
+
458
+ From the keyboard, that works in Chrome alone. In answer to a key, Firefox
459
+ and WebKit (Safari, and every WebView on iOS) do not let a page put the
460
+ keyboard into a frame: Enter or Space on your control leaves the keyboard on
461
+ your control, and a user with only a keyboard has no way in. (Measured in
462
+ Firefox 160, headless, where a press does go in, and in the WebKit of macOS
463
+ 15.7, in a WKWebView kept off screen, which was sent keys and no press.) The
464
+ guard's own stop does not go in that way, and works in all three: keep it
465
+ (the default) unless you need a way in of your own.
466
+
467
+ This is about the Tab key and no more: a tile's script can still put the
468
+ focus in the tile itself, with no click and no key, and `tabindex` does
469
+ nothing about that (the focus guard does). The option takes a whole number
470
+ from -32767 to 32767; anything else throws, since a browser would read it as
471
+ no tabindex at all.
472
+
473
+ ### `refuse`
474
+
475
+ A browser hands some features to every frame unasked. In Chrome 157 a tile
476
+ has fifteen of them unless they are refused: picture-in-picture and the
477
+ gamepad among them, so that it can put a window of its own over whatever its
478
+ user is doing, or read a game controller, and synchronous requests, unload
479
+ handlers and the client hints that say which browser and device this is.
480
+ Refuse a feature, and it is refused to everything in the frame, the frames
481
+ the tile makes included, whatever those ask for.
482
+
483
+ `refuse` is the list in full, as `sandbox` is the attribute in full. When
484
+ nothing is said it is `['sync-xhr']`: a synchronous request holds up the
485
+ thread the tile shares with its runtime, and never brings a tile its own
486
+ files (Chrome and Safari do not hand it to the tile's worker, so the
487
+ loading server answers it with a 404; Firefox hands it to a worker whose
488
+ answer has to come through the very thread it holds, so it fails a minute
489
+ later). What a tile loses is a synchronous request for a `blob:` or `data:`
490
+ address; and one for its own files, which had the loading server's 404, now
491
+ throws a `NetworkError` at once, which stops a script that does not catch
492
+ it. A list of your own takes the place of that one, so name `sync-xhr`
493
+ in it to keep it refused; `[]` refuses nothing, and the frame then has no
494
+ `allow` attribute:
495
+
496
+ ```js
497
+ import { REFUSABLE } from '@dasl/tile-loader';
498
+
499
+ tile.renderContent(300, { refuse: ['sync-xhr', 'picture-in-picture', 'gamepad'] });
500
+ tile.renderContent(300, { refuse: REFUSABLE }); // everything the loader knows
501
+ tile.renderContent(300, { refuse: [] }); // nothing: synchronous requests given back
502
+ ```
503
+
504
+ Each name goes into the frame's `allow` attribute as `'none'`. It only takes
505
+ away: nothing given here grants a feature. The names the loader knows are
506
+ those of `REFUSABLE` (from `refusableFeatures` in `@dasl/tile-lexicon`), and
507
+ a name it does not know throws. An `allow` attribute you set on the frame
508
+ yourself replaces the one the loader wrote, its default with it.
509
+
510
+ A browser goes by the names it knows and passes over the others, so the same
511
+ list takes away less outside Chrome. What each name does, as of 22 November
512
+ 2026: "refused" where that was seen in Chrome 157, Firefox 160 or the WebKit
513
+ of Safari 26.4 (in a WKWebView on macOS 15.7), as said below the table;
514
+ "refused (source)" where the browser's own code says so and nothing was run;
515
+ "not refused" where the browser has the feature and no policy for it, so
516
+ that the name does nothing there; "none" where the browser has no such
517
+ feature. Below "unasked" are the features a frame has in Chrome without
518
+ being given them; in Chrome a tile has the others only where your own
519
+ frame's `allow` attribute gives them. Firefox 160 gives a frame four of them
520
+ unasked: `aria-notify`, `gamepad`, `picture-in-picture` and
521
+ `storage-access`.
522
+
523
+ | Name | What it is | Chrome | Firefox | Safari |
524
+ | --- | --- | --- | --- | --- |
525
+ | `accelerometer` | motion sensors | refused | none | refused (source) |
526
+ | `gyroscope` | | refused | none | refused (source) |
527
+ | `magnetometer` | | refused | none | refused (source) |
528
+ | `autoplay` | sound and video without a press | refused | not refused | not refused |
529
+ | `camera` | | refused | refused | refused (source) |
530
+ | `microphone` | | refused | refused | refused (source) |
531
+ | `clipboard-read` | reading the clipboard | refused | not refused | not refused |
532
+ | `clipboard-write` | writing to it | refused | not refused | not refused |
533
+ | `display-capture` | sharing the screen | refused | refused | refused (source) |
534
+ | `encrypted-media` | DRM | refused | not refused | not refused |
535
+ | `fullscreen` | | refused | refused | refused (source) |
536
+ | `geolocation` | | refused | refused | refused (source) |
537
+ | `midi` | MIDI devices | refused | not refused | none |
538
+ | `screen-wake-lock` | keeping the screen on | refused | refused | refused (source) |
539
+ | `web-share` | the system's share sheet | refused | refused | refused (source) |
540
+ | `xr-spatial-tracking` | WebXR | refused | none | refused (source), where Safari has it |
541
+ | **unasked:** | | | | |
542
+ | `gamepad` | game controllers | refused | refused | refused |
543
+ | `picture-in-picture` | a video in a window of its own | refused | refused | not refused |
544
+ | `sync-xhr` | synchronous requests; refused when nothing is said | refused | not refused | refused |
545
+ | `media-playback-while-not-visible` | playing on while out of view | refused | not refused | not refused |
546
+ | `unload` | unload handlers | refused | not refused | not refused |
547
+ | `storage-access` | asking for the site's cookies (the sandbox refuses it anyway) | refused | refused | refused (source) |
548
+ | `aria-notify` | announcements to a screen reader | refused | refused | none |
549
+ | `deferred-fetch-minimal` | requests put off until the page has gone (`fetchLater`) | refused | none | none |
550
+ | `private-state-token-issuance` | private state tokens | refused | none | none |
551
+ | `private-state-token-redemption` | | refused | none | none |
552
+ | `ch-ua` | client hints: which browser, in a request's headers | refused | none | none |
553
+ | `ch-ua-mobile` | whether it is a phone | refused | none | none |
554
+ | `ch-ua-platform` | which system | refused | none | none |
555
+ | `ch-ua-high-entropy-values` | the details: versions, model, architecture | refused | none | none |
556
+ | `ch-save-data` | whether the user saves data | refused | none | none |
557
+
558
+ Seen: every name refused in Chrome (with `refuse: REFUSABLE`,
559
+ `document.featurePolicy.allowedFeatures()` is empty in the tile, in a frame
560
+ it makes asking for every feature with `*`, and in its runtime's page above
561
+ it); the same in Firefox, which shows a page what it allows once a
562
+ preference says so (`dom.security.permissionsPolicy.webidl.enabled`, which
563
+ changes nothing it enforces): the names it knows are those it refuses in the
564
+ table, and with `refuse: REFUSABLE` its `allowedFeatures()` is empty in the
565
+ same three places, `navigator.getGamepads()` throws and
566
+ `document.pictureInPictureEnabled` is false, as `picture-in-picture` alone
567
+ makes it; a synchronous request there still holds the tile for a minute. In
568
+ Safari's WebKit the gamepad and synchronous requests are refused,
569
+ `document.pictureInPictureEnabled` stays true, and there is no `ariaNotify`
570
+ and no `fetchLater` yet. Refusing the client hints leaves
571
+ `navigator.userAgentData.brands` as it was, which the runtime reads to tell
572
+ Chromium, and `getHighEntropyValues()` then gives the brands, the platform
573
+ and whether it is a phone, and nothing more. Read in the browsers' code:
574
+ Chromium's `permissions_policy_features.json5` and WebKit's
575
+ `Source/WebCore/html/PermissionsPolicy.cpp`; and MDN's pages on
576
+ `Permissions-Policy`, with its compatibility data. Neither Firefox nor Safari
577
+ reads a `Permissions-Policy` header (both were seen to pass over one; Firefox
578
+ bug 1531012): the `allow` attribute is the one setting that every engine
579
+ takes. Browsers move, and Firefox only lately came to picture-in-picture:
580
+ check again before you count on a row.
581
+
582
+ #### What `refuse` cannot take away
583
+
584
+ Outside Chrome, some of what a tile has unasked no setting of a page
585
+ reaches. A host that cannot live with it there has no way but not to show
586
+ tiles in that browser, or, in an app, the WebView's own settings:
587
+
588
+ - **Safari, and every WebView on iOS:** picture-in-picture (a tile can pop a
589
+ video of its own out over everything, on a press), unload handlers, sound
590
+ and video by the browser's own rules, encrypted media, and the clipboard
591
+ on a press: writing to it, and reading it once the user picks the
592
+ browser's "Paste".
593
+ - **Firefox:** synchronous requests (one holds the tile's thread for a
594
+ minute, and then fails), unload handlers, sound and video by the browser's
595
+ own rules, encrypted media, and the clipboard on a press, as in Safari.
596
+ - **Every browser:** copying on a press with `execCommand('copy')`, and what
597
+ a live region of the tile's own announces to a screen reader, which no
598
+ policy governs.
599
+ - **In an app's WebView:** on iOS, `allowsPictureInPictureMediaPlayback =
600
+ false` and `mediaTypesRequiringUserActionForPlayback = .all` on the
601
+ `WKWebViewConfiguration`; on Android, deny in
602
+ `WebChromeClient.onPermissionRequest()` and
603
+ `onGeolocationPermissionsShowPrompt()`, and
604
+ `setMediaPlaybackRequiresUserGesture(true)`.
605
+
281
606
  ## Keeping a tile from steering the user
282
607
 
283
608
  A tile cannot reach your page, but it runs in the middle of it, and the person
@@ -312,6 +637,9 @@ It still does not mean "the user asked for this link": any press or key inside
312
637
  the tile makes its requests activated for a few seconds, and the tile picks
313
638
  which address to send. Show the user where a link goes, and let them decide.
314
639
 
640
+ The focus guard asks the dock something more of the keyboard (see "The
641
+ keyboard"); `activated` is the same for that.
642
+
315
643
  A loading server from before its dock said this (`@dasl/tile-server` 3.1 and
316
644
  earlier) leaves `activated` with the meaning it had: the user did something on
317
645
  the page, somewhere. Nothing that arrives in the dock's name is ever used to
@@ -439,9 +767,17 @@ double click on its buttons.
439
767
  ### The keyboard
440
768
 
441
769
  A tile's script can call `focus()` on a field of its own with nobody having
442
- touched anything. What the user types next, meaning it for a field of yours,
443
- goes to the tile. Nothing in a frame's sandbox governs that. If your page has
444
- fields of its own, turn the guard on when you render the tile:
770
+ touched anything. Where that takes the keyboard, what the user types next,
771
+ meaning it for a field of yours, goes to the tile; in Firefox nothing in a
772
+ frame's sandbox governs that. Chrome, from 158 on, refuses a sandboxed frame
773
+ `focus-without-user-activation` unless its `allow` attribute names it. A
774
+ tile's document is in a frame of the shuttle's, in one of the dock's, in the
775
+ loader's, all of them sandboxed, and none of them names it: there such a
776
+ `focus()` leaves the keyboard where it was, and naming it on the loader's
777
+ frame alone changes nothing (measured in Chrome 158, headless). In WebKit a
778
+ frame of another origin did not take the keyboard that way either, sandboxed
779
+ or not (measured in a WKWebView on macOS 15.7, not in Safari). If your page
780
+ has fields of its own, turn the guard on when you render the tile:
445
781
 
446
782
  ```js
447
783
  import { guardFocus } from '@dasl/tile-loader/guard';
@@ -449,17 +785,212 @@ const frame = tile.renderContent();
449
785
  guardFocus(tile, frame);
450
786
  ```
451
787
 
452
- Focus arriving in the tile's frame stays there when the user tabbed into it or
453
- pressed in it. Your page sees the Tab key, and where it took the user: one
454
- that took them to another field of yours is not one into the tile. It cannot
455
- see the press, so the guard asks the tile's dock, which knows whether the
456
- user pressed or typed inside that tile (see "What `activated` means"). In
457
- every other case focus goes back to the element that had it: when the user
458
- was typing in a field of yours a moment ago, when a mouse is somewhere else
459
- on the page, and when the dock says the user did not act in the tile. That
460
- holds each time the keyboard arrives, also when it comes from another frame
461
- of your page: a tile the user went into once does not get to take the
462
- keyboard back from the next one they go into.
788
+ A guarded tile is out of the tab order: someone tabbing down your page
789
+ passes over its frame, and never ends up typing into the tile, or handing it
790
+ their keys, by chance. In the frame's place in the tab order the guard puts
791
+ a stop of its own, right before the frame: a button of your page's (the
792
+ class `tile-enter`, `ENTER_CLASS`) that takes no room and cannot be seen
793
+ until it has the keyboard. Then it lies over the tile, with a ring round it
794
+ as the guard's layer has (below), and says "Use the keyboard in" and the
795
+ tile's name (its first 60 characters), or "this tile" for a tile with none,
796
+ which is also its name for assistive technology; `enterLabel` gives your
797
+ own words. It takes no press while it shows: a press or a tap where it lies
798
+ goes into the tile, to what is under it, as it would with no stop.
799
+
800
+ Enter or Space on the stop lets the frame into the tab order for the user's
801
+ next Tab, and the stop then says "Press Tab to go in" (`tabLabel` gives your
802
+ own words). That Tab goes from the stop into the tile, as a Tab into any
803
+ frame in the tab order does, and your page sees it. So does a press that the
804
+ browser aims at the stop itself, as it does for a screen reader, which also
805
+ puts the keyboard on the stop where it was not. It is the same in Chrome,
806
+ Firefox and WebKit, which is why the stop does not put the keyboard in the
807
+ frame itself (see "`tabindex`" above). The frame is out of
808
+ the tab order again as soon as the keyboard has left the stop, into the
809
+ tile or anywhere else, ten seconds after the stop was pressed, or once
810
+ another layer lies over the tile (below), and the stop then says what it
811
+ said before. While it
812
+ is in, only a Tab forward from the stop counts as the user going into it,
813
+ and once that Tab has taken them in it counts for nothing more: should the
814
+ keyboard go on into another frame and the tile take it back, that is judged
815
+ afresh. So it is where the keyboard went anywhere else before the tile had
816
+ it (another tile taking it on the way, say).
817
+
818
+ While another layer lies over the tile (the guard's own after a refusal, or
819
+ `engage`'s over a tile that is not picked), that layer is where Tab stops,
820
+ and the guard's stop is out of the tab order. The stop goes into the shadow
821
+ tree the frame is in, is put right before the frame once the frame is in
822
+ your page (and again if anything comes between them), leaves your page with
823
+ the frame and comes back with it, and goes when the guard stops. Its look is
824
+ the layer's, a sheet whose rules weigh nothing: your rules for `.tile-enter`
825
+ and `.tile-pick-label` win.
826
+
827
+ What that costs keyboard users: two keys more to start typing in a tile,
828
+ Enter on the stop and then Tab, where Tab alone took them in before, and
829
+ what they type before that Tab reaches nothing. In Chrome and Firefox that
830
+ Tab lands on the first field of the tile. In WebKit it lands on the tile's
831
+ page, where what is typed reaches the tile but no field of it, and the next
832
+ Tab goes to the first field. Tab out of a tile's last field goes on to the
833
+ next tile's stop, or to what comes after the tile on your page. Shift+Tab
834
+ out of a tile's first field lands on that tile's own stop, which shows over
835
+ the tile again: one more Shift+Tab goes on back, and Enter and Tab there go
836
+ back in. (Measured in Chrome 157 and Firefox 160, headless, and in the
837
+ WebKit of macOS 15.7 in a WKWebView kept off screen and sent keys: the same
838
+ keys in all three.) Nothing typed on the way in lands in a page of the
839
+ dock's, so a press into another guarded tile just after is judged as any
840
+ other: in Chrome, one 0.8 s after was the user's. After your own way in from
841
+ the keyboard it is refused for a few seconds (see below).
842
+
843
+ What it costs mouse and touch users: nothing, unless they press Tab. One who
844
+ presses Tab out of a tile, or Shift+Tab, has the keyboard on a stop, which
845
+ shows over its tile and takes no press: their next press or tap goes where
846
+ they aim it, into that tile as anywhere else, and what they type before it
847
+ is lost.
848
+
849
+ What it costs screen reader users: one more button for each tile, and on a
850
+ phone a swipe through the page stops on it. Reading what is in a tile works
851
+ as before, but one whose screen reader takes the keyboard into the tile by
852
+ its own means has it given back (below): the stop is their way in, activated
853
+ and then followed by Tab. What was measured is Chrome's accessibility tree,
854
+ which has a button for each stop, named for its tile, focusable (also while
855
+ it takes no press), focused where the keyboard is, and named "Press Tab to
856
+ go in" once pressed. No screen reader was run: whether one reads out the new
857
+ name, and how a press of one on the stop goes, were not tried (the loader's
858
+ own tests, which run without a browser, hold that a press aimed at the stop
859
+ lets the frame in as a key does). A checker of accessibility may flag the
860
+ frame (a frame out of the tab order with things in it that take the
861
+ keyboard), though the stop is a way in. And the stop is an element of yours
862
+ in the box that holds the frame: a framework that owns that box may take it
863
+ away, and the guard puts it back when it next looks.
864
+
865
+ Firefox and WebKit do not let a page put the keyboard into a frame in answer
866
+ to a key: there `focus()` called from a key leaves the keyboard where it
867
+ was (measured in Firefox 160, headless, driven over WebDriver BiDi, where it
868
+ goes in when called from a press, and in the WebKit of macOS 15.7 in a
869
+ WKWebView, which was sent keys and no press; neither in a window of its
870
+ own). The guard's stop does not depend on it, and works there. What still
871
+ goes in that way does nothing there from the keyboard: Enter or Space on a
872
+ control of yours that calls `focus()` (with `tabOrder: 'out'`), and a pick
873
+ by Enter or Space on `engage`'s layer or on the guard's own layer after a
874
+ refusal (below). A press or a tap on any of them works in Firefox.
875
+
876
+ So say otherwise if you have to: `tabOrder: 'out'` keeps the frame out of
877
+ the tab order with no stop of the guard's, for a page that has its own way
878
+ in (it calls `focus()` on what `guardFocus` returned); `tabOrder: 'keep'`
879
+ leaves the frame in the tab order as you made it, as the guard did in
880
+ `@dasl/tile-loader` 3 and earlier. A `tabindex` you give the frame through
881
+ `renderContent()` does not keep it in: only `tabOrder: 'keep'` does.
882
+
883
+ Focus arriving in the tile's frame stays there when the user went in by your
884
+ way in, tabbed into it (from the guard's stop, or into a frame you keep in
885
+ the tab order), or pressed in it. Your page sees the Tab key, and where it
886
+ took the user: one that took them to another field of yours is not one into
887
+ the tile, and nor is one while the frame is out of the tab order, which
888
+ cannot have taken them there. It cannot see the press, so the guard asks the
889
+ tile's dock, which knows whether the user pressed or typed inside that tile
890
+ (see "What `activated` means"). In every other case focus goes back to the
891
+ element that had it: when the user was typing in a field of yours a moment
892
+ ago, when a mouse is somewhere else on the page, and when the dock says the
893
+ user did not act in the tile. Where nothing of yours had it then (the user
894
+ had pressed on the plain text of the page, say, or gone on into another
895
+ tile), it goes back to the page and to no element: not to a button they used
896
+ a while ago, which their next Space or Enter would press. That holds each
897
+ time the keyboard arrives, also when it comes from another frame of your
898
+ page: a tile the user went into once does not get to take the keyboard back
899
+ from the next one they go into.
900
+
901
+ Your page sees nothing of the keyboard going from one frame of yours into the
902
+ tile, and the guard finds it there only when it next looks (`pollMs`). So
903
+ while the keyboard is in a frame of your page, the guard has the tile's dock
904
+ watch it come in. Each time it comes in, the dock notes whether the user had
905
+ just pressed or typed in the tile. Where they had not, the dock says so at
906
+ once, without waiting to be asked, and the keyboard is given back as for the
907
+ dock's no. Keys the user typed into the tile before it was given back would
908
+ make them look as if they had acted there afterwards, so that no stands: the
909
+ dock goes on saying no each time the keyboard comes into the tile, until
910
+ those keys no longer count (about five seconds after the last of them), and
911
+ goes on watching for that long after the guard has stopped asking. A Tab on
912
+ your page into the tile, or your own way in, is the user going in, and ends
913
+ it at once. All of this only ever refuses: where the dock says the user had
914
+ acted, or cannot say, the guard goes by what it did before. The dock looks
915
+ every few milliseconds while it watches, which costs a little (in Chrome on a
916
+ laptop, under one percent of a core for each tile watching), and only while
917
+ the keyboard is in a frame of your page and for those few seconds after; a
918
+ loading server whose dock does not watch (`@dasl/tile-server` 3.2 and
919
+ earlier) leaves the guard with the dock's word as it stands when the guard
920
+ asks.
921
+
922
+ What that costs: a press or a tap of the user's into the tile is refused,
923
+ and the keyboard given back, in the few seconds after a key of theirs reached
924
+ the tile before it was given back, or after a press of theirs into it was
925
+ refused: the dock cannot tell such a press from keys typed into the tile. It
926
+ is refused too in the few seconds after the user went into any tile of the
927
+ page by your way in from the keyboard, and pressed Tab or typed (those keys
928
+ land in a page of the dock's own), as it was before; when the docks of the
929
+ page were kept busy for a moment as it came
930
+ (on a slow phone, a page adding another tile does that for a few hundred
931
+ milliseconds); and after a press into the tile that did not bring the
932
+ keyboard along, at such a moment. The dock's word comes within a few
933
+ milliseconds, so a key reaches the tile only when it is typed that quickly,
934
+ or when the dock is slow to answer.
935
+
936
+ Each of those refusals is only the dock's best guess: someone did act in the
937
+ tile, and it may have been the user. The dock says so, and the guard does
938
+ not count such a refusal against the tile. Instead a layer of your page's
939
+ lies over the tile until the user picks it: a press or a tap on it, or Enter
940
+ or Space while it has the keyboard, puts the keyboard in the tile as your
941
+ way in does, and ends the dock's no. Picked with a press or a tap, the
942
+ keyboard goes on into the tile, where what they type next reaches it; picked
943
+ with Enter or Space, it is where their Tab goes on into the tile (in Chrome:
944
+ in Firefox and WebKit a pick from the keyboard leaves the keyboard outside
945
+ the tile, see above). So a user who presses again picks the tile, what they
946
+ type then reaches it, and their next press goes where they aim. Until it is
947
+ picked, the keyboard coming into that tile is never taken for the user's
948
+ doing: it is given back and counted, so the layer spares the tile at most
949
+ one giving back. Neither the tile nor anything but the user lifts it: only a
950
+ press, a tap or a key the browser says is theirs, or your own way in
951
+ (`focus()`); or the dock, once its no is over. The guard asks it now and
952
+ then (every half second at most) while the keyboard is out of the tile, and
953
+ the layer lifts on its own when the dock says that what its no went by has
954
+ run out with the keyboard elsewhere: about five seconds after the user's
955
+ last press into the tile, unless they are on the layer itself. Then the next
956
+ press into the tile is judged as any other. Such a refusal in the minute
957
+ after a layer lifted on its own (`spareMs`) is counted all the same, with a
958
+ layer as well: a tile that could have its dock's nos taken for guesses, and
959
+ waited each time for the layer to go, is held to the same count as before. A
960
+ pick of the user's, or your way in, spares the next one again. The layer is
961
+ right after the frame, in the element that holds it, which is made a
962
+ positioned box (`position: relative`) while the layer is there if it is not
963
+ one already; the layer is where Tab stops meanwhile, in place of the guard's
964
+ stop (and of the frame, which is out of the tab order then even with
965
+ `tabOrder: 'keep'`). It is the same kind of layer as `engage`'s (see "Press
966
+ to use"), with the class `tile-engage` and its own, `tile-pick`
967
+ (`PICK_CLASS`). It shows that the tile waits for the user: a ring round the
968
+ tile, and in the middle a label (`tile-pick-label`, `PICK_LABEL_CLASS`) that
969
+ says "Tap or click to use", which is also its name for assistive technology;
970
+ `pickLabel` gives your own words. That look is a style sheet the guard gives
971
+ your page once, whose rules weigh nothing (`:where`), so that any rule of
972
+ yours for `.tile-pick` or `.tile-pick-label` wins; it is an adopted sheet
973
+ where the browser has those, which a policy that refuses inline style does
974
+ not refuse, and a style element first in the head otherwise. A frame in a
975
+ shadow tree has its layer there, and the sheet is given to that tree once as
976
+ well, where your rules for it go too. The faint background the layer needs
977
+ to take a press over a frame is set on the element itself. With `pick:
978
+ false` such a refusal is counted like any other, and three in ten seconds
979
+ stop the tile. A loading server whose dock does not say whether it was sure
980
+ (`@dasl/tile-server` 3.2 and earlier) has every refusal counted, as before.
981
+
982
+ A way in of your own goes through the guard: a control of yours calls
983
+ `focus()` on what `guardFocus` returned, not on the frame, and the keyboard
984
+ it puts in the tile is the user's, as if they had tabbed in (see "The frame
985
+ a tile runs in"). Give the guard `tabOrder: 'out'` then, unless you want its
986
+ stop as well. From the keyboard it goes in in Chrome alone (see
987
+ "`tabindex`").
988
+
989
+ Whatever the frame, do not put the keyboard in it by calling `focus()` on the
990
+ frame itself while a guard is on a tile of your page: in Chrome the page then
991
+ goes on naming that frame as the one with the keyboard after it has gone to
992
+ another, and a guard goes by what the page names. Where a frame has no guard
993
+ to ask, go in through its window: `frame.contentWindow.focus()`.
463
994
 
464
995
  What it costs a tile that means no harm: its own `focus()` with no press in
465
996
  it (an `autofocus`) does not stick. And a click into the tile within a second
@@ -470,6 +1001,20 @@ the tile by its own means, with no Tab and no press that your page or the
470
1001
  dock sees, has it given back as a script's would be, each time. That has not
471
1002
  been tried with a screen reader; try it with yours before you turn this on.
472
1003
 
1004
+ Nor does your page see a Tab pressed inside another frame. A guarded tile
1005
+ is out of the tab order, so nobody tabs out of one tile straight into it.
1006
+ Where you keep it in (`tabOrder: 'keep'`), a user who does has the keyboard
1007
+ given back, and counted, as a script's would be: three times in ten seconds
1008
+ stops the tile.
1009
+
1010
+ On a screen that takes fingers as well as a mouse (a touch laptop), your page
1011
+ sees nothing of a finger in a frame. Before the guard has seen any pointer, a
1012
+ tap into a guarded tile from your page itself is asked about. One from another
1013
+ frame of your page is given back and counted in the same way, and so is any
1014
+ tap into the tile once the guard last saw the mouse elsewhere: it cannot tell
1015
+ them from the tile's script taking the keyboard. The way in serves these users
1016
+ too.
1017
+
473
1018
  What it does not do:
474
1019
 
475
1020
  - Giving focus back does not win against a tile that takes it again at once:
@@ -477,16 +1022,20 @@ What it does not do:
477
1022
  keyboard three times in ten seconds is reported (`onAbuse('focus', count)`)
478
1023
  and stopped (see "A tile that keeps at it is stopped").
479
1024
  - For about five seconds after a real press or key in the tile, the tile can
480
- take the keyboard back and keep it.
481
- - In the few milliseconds the dock takes to answer, a key the user types goes
482
- to the tile, and counts as their having acted in it. The dock gets `dockMs`
483
- to answer; one that has answered before and now does not is taken to say
484
- no, so keeping it busy gains a tile nothing.
1025
+ take the keyboard back and keep it, where nothing was refused in between.
1026
+ - Until the guard has heard from the dock, a key the user types goes to the
1027
+ tile: a few milliseconds where the dock watches, up to `pollMs` where it
1028
+ does not and the keyboard came from another frame. A key typed in the few
1029
+ milliseconds before the dock first finds the keyboard in the tile counts as
1030
+ their having acted in it, and so does any key, where the dock does not
1031
+ watch. The dock gets `dockMs` to answer; one that has answered before and
1032
+ now does not is taken to say no, so keeping it busy gains a tile nothing.
485
1033
  - With a loading server whose dock does not answer (`@dasl/tile-server` 3.1
486
1034
  and earlier), the guard has only what your page can see. A mouse resting on
487
1035
  the tile, and any touch screen, cannot be told from a press there, and the
488
1036
  tile keeps the keyboard.
489
- - A user who tabs out of one tile straight into the next, with nothing of
1037
+ - Where you keep guarded tiles in the tab order (`tabOrder: 'keep'`), a
1038
+ user who tabs out of one tile straight into the next, with nothing of
490
1039
  yours to stop at between them, has the keyboard given back: your page saw
491
1040
  no Tab, and the second tile's dock no key. Put something of yours that
492
1041
  takes focus between two tiles.
@@ -496,7 +1045,11 @@ A guard listens to your page, so it does not go with the tile the way
496
1045
  you call `stop()` on what it returned. Turn it on when you render the tile,
497
1046
  before the tile runs. Its numbers are first guesses: `FOCUS_GUARD` has them,
498
1047
  and the options override any (`tabMs`, `typingMs`, `grabs`, `withinMs`,
499
- `dockMs`, `pollMs`).
1048
+ `dockMs`, `pollMs`, `spareMs`). `pick: false` turns off the layer the user
1049
+ picks a tile on after a refusal the dock was not sure of, and `pickLabel`
1050
+ gives it your own words. `tabOrder` says where the frame is in the tab
1051
+ order (`'stop'`, the default, `'out'` or `'keep'`), `enterLabel` gives
1052
+ the guard's stop your own words, and `tabLabel` what it says once pressed.
500
1053
 
501
1054
  ### Scrolling
502
1055
 
@@ -664,9 +1217,13 @@ layer back; so does `release()`.
664
1217
 
665
1218
  Tab does not go into a tile that is not picked (its frame has
666
1219
  `tabindex="-1"` meanwhile, and gets back what it had when it is picked). It
667
- stops at the layer, which comes right after the frame: Enter or Space there
668
- picks the tile and puts the keyboard in its frame, and the next Tab goes to
669
- the first thing in the tile.
1220
+ stops at the layer, which comes after the frame in its box: Enter or Space
1221
+ there picks the tile and puts the keyboard in its frame, and the next Tab
1222
+ goes to the first thing in the tile (in Chrome: Firefox and WebKit do not
1223
+ let the keyboard in that way, see "The keyboard"; a press works there). With
1224
+ the focus guard on as well, the frame stays out of the tab order once the
1225
+ tile is picked: the guard's stop is the way back in to a picked tile, and
1226
+ the layer to one that is not.
670
1227
 
671
1228
  Start a tile the user has just started themselves with `start: 'engaged'`;
672
1229
  one that starts by itself, in a feed, not picked.
@@ -679,6 +1236,12 @@ What it does not do: once picked, a tile can hold a finger, take the
679
1236
  keyboard and be scrolled through again, until the user presses elsewhere.
680
1237
  The other guards still apply then.
681
1238
 
1239
+ The focus guard puts a layer of the same kind over a tile after a refusal
1240
+ its dock was not sure of (see "The keyboard"). On a tile that waits to be
1241
+ picked, that layer is under `engage`'s: where `engage`'s is back over the
1242
+ tile, the user picks the tile there, and then once more on the guard's,
1243
+ which puts the keyboard in.
1244
+
682
1245
  The layer is an element of your page's (`tile-engage`, also `layer` on what
683
1246
  `engage` returns), a button to assistive technology, named by `label`. It
684
1247
  paints, too faintly to see, and has to: a block that paints nothing does not
@@ -730,10 +1293,178 @@ it, can only be wiped while it is still in the document.
730
1293
 
731
1294
  A host that never calls `close()` is not left with nothing: on its way out the
732
1295
  runtime lets its worker's registration go, best effort. What the tile stored
733
- stays until the browser evicts it.
1296
+ stays until the browser evicts it (on the origin a tile's CID names, until the
1297
+ tile next starts there, which wipes it first).
734
1298
 
735
1299
  A tile on a named origin (`namedOrigin`) is the exception throughout: that origin
736
- is kept on purpose, so `close()` wipes nothing there.
1300
+ is kept on purpose, so `close()` wipes nothing there; `tile.ephemeral` says which
1301
+ a tile is. A tile on the origin its CID names (`cidOrigins`) is wiped as one on
1302
+ an origin made for the load is, but that origin is the same for every run of
1303
+ the tile: it is also wiped before the tile starts, and the same tile shown twice
1304
+ on a page shares it (see "Origins named by a tile's CID").
1305
+
1306
+ ## Origins named by a tile's CID
1307
+
1308
+ ```js
1309
+ const mothership = new TileMothership({ loadDomain: 'load.webtil.es', cidOrigins: true });
1310
+ ```
1311
+
1312
+ With `cidOrigins`, a tile runs on the origin its own content names,
1313
+ `<cid>.<base>`, where `<cid>` is the CID of its manifest as this loader
1314
+ computed it from the bytes it loaded: the DRISL of the record's `tile` on AT
1315
+ (`tile.manifestCid`), the header of a .tile file as the file has it
1316
+ (`tile.cid`). No option takes a CID, and no address names one: a host cannot
1317
+ point a tile at another tile's origin. `tile.getLoadSource()` and the frames
1318
+ `renderContent()` makes name that origin, every time, and so does every page
1319
+ that runs the same tile.
1320
+
1321
+ What changes is the name, and only the name: the origin says which tile runs
1322
+ there, the same wherever and whenever the tile runs, and the tile server's
1323
+ runtime holds it to that tile. What the tile stores there goes with each run
1324
+ of it, as on an origin made for the load. A tile that has something to keep
1325
+ gives it to its host over a protocol (tp-data).
1326
+
1327
+ - **Wiped when the tile is closed**, as an origin made for the load is:
1328
+ `close()` has it wiped, and once more a few seconds later, and resolves to
1329
+ whether it was.
1330
+ - **Wiped before the tile starts.** The origin is the same for every run, so
1331
+ what one run left there the next would find, and a run that was never
1332
+ closed (a page that went without calling `close()`, one that crashed)
1333
+ leaves all of it. So before the first tile of the page starts there, the
1334
+ loader has the origin wiped, as `close()` does, and tells the tile's
1335
+ runtime to load it once that is done. A tile started there again within a
1336
+ few seconds of its close waits for the second wipe of that close instead
1337
+ (three seconds after the first, at most). A wipe that does not go through
1338
+ is tried once more three seconds later (something of a run that was never
1339
+ closed, a worker the browser has not stopped yet, can still be writing
1340
+ there: measured in Chrome with a tile whose worker never gives its thread
1341
+ back, shown again at once after its frame was removed); where that one
1342
+ does not either, the tile is not run: `error`, with `wipe`.
1343
+ - **In a credentialless frame**, unless you ask otherwise, as on an origin
1344
+ made for the load: nothing is lost by its storage going with the page, and
1345
+ in Chrome the tile has none of the cookies of the loading server's domain.
1346
+ - **The same tile twice on a page shares it**: one origin, one store, one
1347
+ worker. So neither wipe is done under a tile of the page that still runs
1348
+ there. Closed, a tile there has the origin wiped only if it was the last
1349
+ (the others' `close()` resolves `false`), and only the first to start
1350
+ there has it wiped. A frame that is taken out of the document and put
1351
+ back counts as one that starts there again, once the others there went on
1352
+ without it. That holds for every mothership of the page made by the same
1353
+ copy of the loader. In Chrome, a frame of the tile that is credentialless
1354
+ and one that is not (`credentialless: false`) are on two stores, each
1355
+ wiped as its own, from a frame of its kind. Two copies of the loader on
1356
+ one page (two bundles, each with its own) know nothing of each other's
1357
+ tiles, and neither does a page in another tab: what keeps their wipes off
1358
+ each other's runs is the runtime's lock (see "Beyond the page").
1359
+
1360
+ What it takes:
1361
+
1362
+ - **The tile server's runtime holds the origin to its tile.** Anyone can name
1363
+ such an origin, and every byte served there comes from the page's loader,
1364
+ so the runtime on the origin checks what it is handed against its own name:
1365
+ the manifest's bytes against the CID, each resource against the CID the
1366
+ manifest lists for it, and serves the headers the manifest lists, never the
1367
+ loader's (a `hardenResponse()` of yours adds nothing there). The loader
1368
+ hands it the manifest, and runs a tile there only once the dock has said
1369
+ that its runtime does this (`@dasl/tile-server` 4.0 and later): otherwise
1370
+ the tile fires `error` with `version`, and a refusal from the runtime is
1371
+ `integrity`. The loading server has to be at `load.<base>`.
1372
+ - **A tile with nothing to be named by** runs on an origin made for the load,
1373
+ as without the option: a webxdc tile, one in memory, and one whose loader
1374
+ has no manifest bytes to give.
1375
+
1376
+ A new version of a tile has another manifest, another CID, and another
1377
+ origin. The same tile as a .tile file and on AT has two CIDs, and two origins.
1378
+
1379
+ **Beyond the page.** A browser keeps a frame's storage and its worker by its
1380
+ origin and by the site at the top, and, for a credentialless frame, by the
1381
+ page. The same tile shown at once in two tabs of one site is on one origin
1382
+ in both, and, where the browser keeps one store for the site, on one store:
1383
+ what one run stores there the other finds, and wiping it for one would take
1384
+ it from the other. So the tile server's runtime holds each run of a tile
1385
+ there to a lock, from before anything of the run is set up until the run
1386
+ ends, and wipes nothing while a run holds it: a wipe asked for before a
1387
+ start or at a close, by the loader of another tab or by another copy of the
1388
+ loader on the page, is held off, and the loader is told so. A tile that
1389
+ starts beside a run of another page starts on what that run has, as the
1390
+ second tile of a page does, and the last of them to be closed has the origin
1391
+ wiped (`close()` resolves `false` for the others, with no warning). The
1392
+ lock is a Web Lock, which the runtime's dock holds on the loading server's
1393
+ own origin: the browser keeps locks for each storage partition, as it keeps
1394
+ the stores, so the dock's are kept as the tile origin's store is, and lets
1395
+ a page's locks go when the page goes, however it goes (its frame removed,
1396
+ its tab closed or navigated, a crash), within 30 ms in every browser
1397
+ measured. (Not on the tile's origin, which is wiped: in Chrome a lock asked
1398
+ for there before a wipe is not seen by one asked for after it, and two runs
1399
+ that start at the same moment were measured wiping under each other.) The
1400
+ loader takes the runtime's word that a run holds a
1401
+ wipe off only where the loading server's dock says that its runtime holds
1402
+ runs to the lock (`@dasl/tile-server` after 4.0.0).
1403
+
1404
+ Measured with two tabs (two web views on one data store, for WebKit), each
1405
+ showing the tile, the second started once the first had stored something
1406
+ (and the same with the two started at the same moment, and with one started
1407
+ as the other is closed):
1408
+
1409
+ | | What the second tab's tile does to the first's |
1410
+ | --- | --- |
1411
+ | Chrome, in the credentialless frame the loader makes | nothing: each page has a store of its own, empty to begin with and gone with the page, which each tab's start and close wipe as its own |
1412
+ | Chrome, in a plain frame (`credentialless: false`) | nothing: it starts beside the first, on what the first stored (its start waits a second for the lock, then goes on), and its close wipes nothing. The first's tile keeps what it stored, its worker and its files, through the second's start and its close; the first's close, the last, wipes the origin |
1413
+ | Firefox | the same as a plain frame in Chrome, whatever the frame (Firefox ignores the attribute) |
1414
+ | Safari, and a WKWebView | the same (measured in macOS's WKWebView) |
1415
+ | Android's WebView | not known |
1416
+
1417
+ Two copies of the loader on one page do the same to each other, in every
1418
+ browser (in Chrome's credentialless frames as well: one page is one store).
1419
+ A page in the back/forward cache keeps its locks, and its run of the tile
1420
+ with them: in WebKit (Safari, a WKWebView) it holds the wipes of other pages
1421
+ off until it is shown again, with what it stored, or let go; Chrome lets
1422
+ such a page go as soon as another asks for a lock it holds, which ends that
1423
+ run; Firefox does not keep such a page. The tile has no hand in the lock:
1424
+ it has no page on the loading server's origin, and a lock it takes on its
1425
+ own holds nothing off. Nor does a worker of the tile's outlive its pages
1426
+ there, with what it holds in memory, which no wipe reaches: the runtime
1427
+ starts no shared worker on such an origin, from any file, and the tile
1428
+ policy none from a blob or a `data:` URL (see "Origins named by a tile's
1429
+ CID" in tile-server's README). Behind a runtime from before that
1430
+ (`@dasl/tile-server` 4.0.0), one made with `extendedLifetime` lives five
1431
+ minutes past them in Chrome, carries what it holds to the tile's next run,
1432
+ and can write it back after a wipe.
1433
+
1434
+ Behind a loading server whose runtime takes no lock (`@dasl/tile-server`
1435
+ 4.0.0, and what is built from it), nothing holds a wipe off: where the
1436
+ browser keeps one store for the site (Firefox, Safari, Chrome in a plain
1437
+ frame), the second tab's start wipes the origin under the first's tile, and
1438
+ its close does the same: what it stored and its worker are gone, and it is
1439
+ refused its own files from then on; two copies of the loader on one page
1440
+ wipe under each other's tiles the same way.
1441
+
1442
+ And what it costs:
1443
+
1444
+ - **The host name says which tile is shown**, to DNS resolvers, to the
1445
+ network unless the browser hides it (Encrypted Client Hello), and to the
1446
+ tile server and whatever is in front of it. A minted name says nothing.
1447
+ - **A wipe before each start.** The first tile of the page to start there
1448
+ waits for its origin to be wiped: a frame of the loader's own that loads
1449
+ the dock and the runtime for that origin, and the tile server's wipe. One
1450
+ that a run of another page holds off is given a second to come first.
1451
+ Measured on loopback in Chrome, Firefox and WebKit (the median of five
1452
+ starts, in two runs), that wipe took 30 to 65 ms, and the tile was up 20 to
1453
+ 100 ms later than one on an origin made for the load; over a network it is
1454
+ a few round trips to the tile server more.
1455
+ - **Pages of the same site, and every frame in them, can reach a run of the
1456
+ tile.** Any page of the site the tile is shown under can run the genuine
1457
+ tile on its origin and feed it whatever it likes over the tile protocols,
1458
+ or answer none of its requests; and where the browser keeps one store for
1459
+ the site (above), its run of the tile starts on what a run of the tile in
1460
+ another of its pages has, and says to it whatever the tile says to its
1461
+ host. (Behind a loading server whose runtime takes no lock, it can also
1462
+ have the origin wiped under that run, by starting or closing its own.)
1463
+ So can any frame in such a page,
1464
+ whatever site the frame is from: an ad, an embedded player, a widget, and
1465
+ whatever they frame in turn. None can run any other tile there, nor other
1466
+ bytes or headers. Run tiles on the origins their CIDs name only on pages
1467
+ whose frames you would let do this.
737
1468
 
738
1469
  ## Loading a tile
739
1470
 
@@ -927,15 +1658,15 @@ A tile's origin is a dead end, by three layers that all read one policy
927
1658
  whose runtime tries to leave (the `stopped` event). A `frame-src` of your
928
1659
  own that only allows the tile server's host is a second lock on the same
929
1660
  door.
930
- - **Your frame can take more away.** The frame `renderContent()` returns is
931
- an element of your page, and takes a `sandbox` attribute of yours, set
932
- before the frame goes in the document. A frame's sandbox only takes away
933
- from what runs under it, so two things have to stay in it, `allow-scripts`
934
- and `allow-same-origin`: without them the runtime's service worker cannot
935
- run, and no tile loads. Leave out `allow-modals` and `allow-downloads` and
936
- a tile raises no dialog and starts no download, which is what a page that
937
- shows tiles among other things wants, a feed above all. Leave out
938
- `allow-forms` as well and a tile's forms do nothing.
1661
+ - **Your frame takes more away.** The frame `renderContent()` returns is
1662
+ sandboxed without dialogs and downloads, so a tile raises no dialog and
1663
+ starts no download in your page, and refuses a tile synchronous requests;
1664
+ it can be credentialless, out of the tab order, and refuse a tile more
1665
+ features of the browser, fewer of which other browsers than Chrome know.
1666
+ See "The frame a tile runs in". A frame's sandbox only takes away from
1667
+ what runs under it, so two things have to stay in it, `allow-scripts` and
1668
+ `allow-same-origin`: without them the runtime's service worker cannot
1669
+ run, and no tile loads.
939
1670
  - **A tile opens nothing.** No popups in the sandbox, so no window to send
940
1671
  anywhere. A link out is a request over the link protocol, and your page
941
1672
  decides (`tileLinks`), opening it somewhere of its own.
@@ -979,8 +1710,9 @@ for (const post of document.querySelectorAll('.post')) {
979
1710
  is left alone, and its tile is not even loaded.
980
1711
  - It is **closed** when its place has been out of view for a while
981
1712
  (`closeAfter`, ten seconds), with `tile.close()`: the frame goes and the
982
- origin is wiped. Shown again, it starts afresh on another origin, so this is
983
- for tiles whose state you do not mean to keep.
1713
+ origin is wiped. Shown again, it starts afresh, on another origin (or on
1714
+ the one its CID names, wiped), so this is for tiles whose state you do not
1715
+ mean to keep.
984
1716
  - No more than `maxLive` (six) are **live at once**. When another tile needs
985
1717
  the room, the live one that has been out of view longest is closed for it.
986
1718
  A tile in view is never closed for another: the other waits.