@dasl/tile-loader 4.0.0 → 5.1.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
@@ -80,9 +80,10 @@ Four cooperating layers, all talking over `postMessage`:
80
80
  does not start: the dock will not frame it. A name that is a tile's CID is
81
81
  not one to give here, and throws: see `conf.cidOrigins`.
82
82
  - `conf.cidOrigins`: `true` to run each tile on the origin its own content
83
- names, the CID of its manifest, which is kept: what the tile stores there it
84
- finds again the next time it runs. `false` when left out. See "Origins named
85
- by a tile's CID". Not with `namedOrigin` (it throws).
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).
86
87
  - `conf.webrtcGuard`: `'exhaust'` (default) has the shuttle spend Chromium's
87
88
  per-process WebRTC budget before the tile loads (see Security model); `'none'`
88
89
  skips it, for hosts that block WebRTC themselves (an Electron app with the
@@ -145,9 +146,11 @@ Four cooperating layers, all talking over `postMessage`:
145
146
  - **`await close()`** — you are done with the tile: its runtime tidies up, its
146
147
  frame is removed, and the tile forgets it (a `close` event says when). It can
147
148
  be rendered again afterwards. See "When a tile goes away".
148
- - **`ephemeral`** — whether the origin the tile runs on is made for one load,
149
- and wiped when it is closed: `false` on a named origin, and on the origin a
150
- tile's CID names (see "Origins named by a tile's CID").
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.
151
154
  - The **`load`** event — the tile's runtime is up, and its root document is
152
155
  being fetched for it. It says that all went well so far, not that anything
153
156
  is on screen; and for a tile that cannot start it never comes, which is
@@ -182,6 +185,13 @@ Four cooperating layers, all talking over `postMessage`:
182
185
  cross-site storage (Firefox's "cross-site cookies").
183
186
  - `unsupported`: the browser lacks what the runtime needs (service workers
184
187
  and `Promise.withResolvers`: Chrome 119, Firefox 121, Safari 17.4).
188
+ - `frame`: the tile's frame was not handed the tile: the browser did not
189
+ ask the tile's worker for its root document, or the worker refused it,
190
+ and a second try did no better. The runtime hides what the frame holds
191
+ (a browser's own error page), so the tile's place is empty. Loading the
192
+ page again is the cure to offer. (Firefox loads the frames of a page
193
+ that was reloaded past its cache, with shift, past service workers; the
194
+ runtime gets round that, and this is what is left if it could not.)
185
195
  - `content`: the tile's root document is not to be had: its loader failed,
186
196
  or said there is none. One that its loader never answers is reported by
187
197
  the deadline (`timeout`, stage `content`); with no deadline, or a long
@@ -191,6 +201,11 @@ Four cooperating layers, all talking over `postMessage`:
191
201
  and the runtime there refused the manifest it was handed: not the one
192
202
  that CID names, or not one it reads (a .tile file whose header is not
193
203
  written in DRISL's one form). Nothing of the tile is served.
204
+ - `wipe`: the tile runs on the origin its CID names, and that origin could
205
+ not be wiped before the tile started there, tried twice, three seconds
206
+ apart (the tile server said it was not, or did not answer within ten
207
+ seconds): what an earlier run left could still be there, so the tile is
208
+ not run. Render it again to try again.
194
209
 
195
210
  For a tile on the origin its CID names, `version` also means that the
196
211
  tile server's dock did not say that its runtime holds such an origin to
@@ -201,7 +216,7 @@ Four cooperating layers, all talking over `postMessage`:
201
216
  `error` at most, and none once `close()` is called: closing ends the start,
202
217
  however far it got. The frame is left as it is: show something in its
203
218
  place, offer to try again (`close()`, then render the tile once more), or
204
- wait. `worker` and `unsupported` are the runtime's own account, as is a
219
+ wait. `worker`, `unsupported` and `frame` are the runtime's own account, as is a
205
220
  root document that was never answered: they take a tile server recent
206
221
  enough to give it, and with an older one those starts end in `timeout`.
207
222
  That account passes through the tile's origin on its way to your page, and
@@ -209,7 +224,8 @@ Four cooperating layers, all talking over `postMessage`:
209
224
  origin can have the start reported as failed, for any of these reasons.
210
225
  On an origin made for the one load, nothing of the tile's runs before it
211
226
  has started and no other tile is there; tiles that share a named origin
212
- can do it to one another.
227
+ can do it to one another, and so can the runs of a tile on the origin its
228
+ CID names.
213
229
 
214
230
  A tile from AT has one more `error`, before its runtime is told to load:
215
231
  its content could not be had, and `ev.error` is the `TileLoadError` that
@@ -310,7 +326,7 @@ so that you are never left believing in a frame you do not have.
310
326
  | Option | When left out | What it is |
311
327
  | --- | --- | --- |
312
328
  | `sandbox` | `'allow-scripts allow-same-origin allow-forms'` | the frame's sandbox attribute in full |
313
- | `credentialless` | `true` on an origin made for the load, `false` on a named origin and on the origin a tile's CID names (`tile.ephemeral`) | whether the frame is credentialless |
329
+ | `credentialless` | `true`, unless the tile runs on a named origin (`tile.ephemeral`) | whether the frame is credentialless |
314
330
  | `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 |
315
331
  | `refuse` | `['sync-xhr']` | features of the browser to take from the tile, the list in full |
316
332
 
@@ -386,12 +402,13 @@ is there included. What to know of it:
386
402
  able to keep the next ones on its page from loading, until the page is
387
403
  loaded again. `@dasl/tile-server`'s command reads 1 MiB; its README says
388
404
  what a front has to take.
389
- - A tile on a named origin (`namedOrigin`), or on the origin its CID names
390
- (`cidOrigins`), is there to find its storage again, and a credentialless
391
- frame loses it with every page: its frame is a plain one unless you ask.
392
- In Chrome a plain frame has the cookies of the loading server's domain,
393
- which Chrome does not keep apart by site unless its user blocks third-party
394
- cookies: see "Origins named by a tile's CID".
405
+ - A tile on a named origin (`namedOrigin`) is there to find its storage
406
+ again, and a credentialless frame loses it with every page: its frame is a
407
+ plain one unless you ask. In Chrome a plain frame has the cookies of the
408
+ loading server's domain, which Chrome does not keep apart by site unless its
409
+ user blocks third-party cookies. A tile on the origin its CID names
410
+ (`cidOrigins`) keeps nothing from one run to the next, and its frame is
411
+ credentialless, as on an origin made for the load.
395
412
 
396
413
  Closing a tile in such a frame wipes its origin from a credentialless frame
397
414
  too, since that is where what it stored is.
@@ -1283,11 +1300,15 @@ it, can only be wiped while it is still in the document.
1283
1300
 
1284
1301
  A host that never calls `close()` is not left with nothing: on its way out the
1285
1302
  runtime lets its worker's registration go, best effort. What the tile stored
1286
- stays until the browser evicts it.
1303
+ stays until the browser evicts it (on the origin a tile's CID names, until the
1304
+ tile next starts there, which wipes it first).
1287
1305
 
1288
1306
  A tile on a named origin (`namedOrigin`) is the exception throughout: that origin
1289
- is kept on purpose, so `close()` wipes nothing there. So is a tile on the origin
1290
- its CID names (`cidOrigins`); `tile.ephemeral` says which a tile is.
1307
+ is kept on purpose, so `close()` wipes nothing there; `tile.ephemeral` says which
1308
+ a tile is. A tile on the origin its CID names (`cidOrigins`) is wiped as one on
1309
+ an origin made for the load is, but that origin is the same for every run of
1310
+ the tile: it is also wiped before the tile starts, and the same tile shown twice
1311
+ on a page shares it (see "Origins named by a tile's CID").
1291
1312
 
1292
1313
  ## Origins named by a tile's CID
1293
1314
 
@@ -1304,10 +1325,44 @@ point a tile at another tile's origin. `tile.getLoadSource()` and the frames
1304
1325
  `renderContent()` makes name that origin, every time, and so does every page
1305
1326
  that runs the same tile.
1306
1327
 
1307
- What is that for: a tile that keeps what it stores, for as long as it is that
1308
- tile. A game's saves, a document's notes, its preferences, a tile in a feed
1309
- that keeps its state when it is scrolled away and back. Its worker stays
1310
- registered there too.
1328
+ What changes is the name, and only the name: the origin says which tile runs
1329
+ there, the same wherever and whenever the tile runs, and the tile server's
1330
+ runtime holds it to that tile. What the tile stores there goes with each run
1331
+ of it, as on an origin made for the load. A tile that has something to keep
1332
+ gives it to its host over a protocol (tp-data).
1333
+
1334
+ - **Wiped when the tile is closed**, as an origin made for the load is:
1335
+ `close()` has it wiped, and once more a few seconds later, and resolves to
1336
+ whether it was.
1337
+ - **Wiped before the tile starts.** The origin is the same for every run, so
1338
+ what one run left there the next would find, and a run that was never
1339
+ closed (a page that went without calling `close()`, one that crashed)
1340
+ leaves all of it. So before the first tile of the page starts there, the
1341
+ loader has the origin wiped, as `close()` does, and tells the tile's
1342
+ runtime to load it once that is done. A tile started there again within a
1343
+ few seconds of its close waits for the second wipe of that close instead
1344
+ (three seconds after the first, at most). A wipe that does not go through
1345
+ is tried once more three seconds later (something of a run that was never
1346
+ closed, a worker the browser has not stopped yet, can still be writing
1347
+ there: measured in Chrome with a tile whose worker never gives its thread
1348
+ back, shown again at once after its frame was removed); where that one
1349
+ does not either, the tile is not run: `error`, with `wipe`.
1350
+ - **In a credentialless frame**, unless you ask otherwise, as on an origin
1351
+ made for the load: nothing is lost by its storage going with the page, and
1352
+ in Chrome the tile has none of the cookies of the loading server's domain.
1353
+ - **The same tile twice on a page shares it**: one origin, one store, one
1354
+ worker. So neither wipe is done under a tile of the page that still runs
1355
+ there. Closed, a tile there has the origin wiped only if it was the last
1356
+ (the others' `close()` resolves `false`), and only the first to start
1357
+ there has it wiped. A frame that is taken out of the document and put
1358
+ back counts as one that starts there again, once the others there went on
1359
+ without it. That holds for every mothership of the page made by the same
1360
+ copy of the loader. In Chrome, a frame of the tile that is credentialless
1361
+ and one that is not (`credentialless: false`) are on two stores, each
1362
+ wiped as its own, from a frame of its kind. Two copies of the loader on
1363
+ one page (two bundles, each with its own) know nothing of each other's
1364
+ tiles, and neither does a page in another tab: what keeps their wipes off
1365
+ each other's runs is the runtime's lock (see "Beyond the page").
1311
1366
 
1312
1367
  What it takes:
1313
1368
 
@@ -1323,60 +1378,100 @@ What it takes:
1323
1378
  `integrity`. The loading server has to be at `load.<base>`.
1324
1379
  - **A tile with nothing to be named by** runs on an origin made for the load,
1325
1380
  as without the option: a webxdc tile, one in memory, and one whose loader
1326
- has no manifest bytes to give. `tile.ephemeral` is `false` for a tile on the
1327
- origin its CID names, `true` otherwise.
1328
- - **It is kept**: `close()` wipes nothing and resolves `false`, and the frame
1329
- is plain unless you ask for `credentialless: true`, which keeps nothing past
1330
- the page in Chromium.
1331
-
1332
- What a tile keeps there, it keeps per tile content, per top-level site and per
1333
- browser profile, and for as long as the browser keeps it:
1334
-
1335
- - **A new version starts with nothing.** Another manifest has another CID,
1336
- and another origin. Nothing carries data from one version to the next: a
1337
- tile that must gives it to its host over a protocol (tp-data). The old
1338
- version's origin stays in the browser until it is cleared. The same tile as
1339
- a .tile file and on AT has two CIDs, and two origins.
1340
- - **Every run of the tile on one site shares it**: its storage, its worker,
1341
- and on one page each other's documents. What one run is given, all can have.
1342
- Do not run on such an origin a tile whose runs must be kept apart (one tile
1343
- shown across private conversations, say).
1344
- - **Each site that shows it has its own.** Where the browser keeps storage
1345
- apart by the top-level site:
1346
-
1347
- | | Storage and the worker | Cookies of the loading server's domain, in a plain frame |
1348
- | --- | --- | --- |
1349
- | Chrome | per top-level site (and per whether an ancestor is of another site) | the same jar on every site, unless its user blocks third-party cookies: a channel between tiles across sites |
1350
- | Firefox | per top-level site | per top-level site |
1351
- | Safari | per top-level site; what script wrote may be deleted after seven days of use without a visit to the site | blocked |
1352
- | A WKWebView | the app's own store | the app's |
1353
- | Android's WebView | not known | not known |
1354
-
1355
- Where the page that shows tiles is on the tile server's own site (as
1356
- webtil.es and its tiles are), every frame is of the same site and a tile's
1357
- store is that site's own: every page of the site shares it, a link to one
1358
- included. So are the cookies of that site, in every browser: where it is
1359
- your site too (as `t.mu.social` is under `mu.social`), a tile in a plain
1360
- frame there reads the cookies of yours that a script can read, and sets
1361
- cookies your site then receives. Keep such origins off there.
1362
- - **Best effort.** Storage is cleared under pressure and by its user.
1381
+ has no manifest bytes to give.
1382
+
1383
+ A new version of a tile has another manifest, another CID, and another
1384
+ origin. The same tile as a .tile file and on AT has two CIDs, and two origins.
1385
+
1386
+ **Beyond the page.** A browser keeps a frame's storage and its worker by its
1387
+ origin and by the site at the top, and, for a credentialless frame, by the
1388
+ page. The same tile shown at once in two tabs of one site is on one origin
1389
+ in both, and, where the browser keeps one store for the site, on one store:
1390
+ what one run stores there the other finds, and wiping it for one would take
1391
+ it from the other. So the tile server's runtime holds each run of a tile
1392
+ there to a lock, from before anything of the run is set up until the run
1393
+ ends, and wipes nothing while a run holds it: a wipe asked for before a
1394
+ start or at a close, by the loader of another tab or by another copy of the
1395
+ loader on the page, is held off, and the loader is told so. A tile that
1396
+ starts beside a run of another page starts on what that run has, as the
1397
+ second tile of a page does, and the last of them to be closed has the origin
1398
+ wiped (`close()` resolves `false` for the others, with no warning). The
1399
+ lock is a Web Lock, which the runtime's dock holds on the loading server's
1400
+ own origin: the browser keeps locks for each storage partition, as it keeps
1401
+ the stores, so the dock's are kept as the tile origin's store is, and lets
1402
+ a page's locks go when the page goes, however it goes (its frame removed,
1403
+ its tab closed or navigated, a crash), within 30 ms in every browser
1404
+ measured. (Not on the tile's origin, which is wiped: in Chrome a lock asked
1405
+ for there before a wipe is not seen by one asked for after it, and two runs
1406
+ that start at the same moment were measured wiping under each other.) The
1407
+ loader takes the runtime's word that a run holds a
1408
+ wipe off only where the loading server's dock says that its runtime holds
1409
+ runs to the lock (`@dasl/tile-server` after 4.0.0).
1410
+
1411
+ Measured with two tabs (two web views on one data store, for WebKit), each
1412
+ showing the tile, the second started once the first had stored something
1413
+ (and the same with the two started at the same moment, and with one started
1414
+ as the other is closed):
1415
+
1416
+ | | What the second tab's tile does to the first's |
1417
+ | --- | --- |
1418
+ | 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 |
1419
+ | 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 |
1420
+ | Firefox | the same as a plain frame in Chrome, whatever the frame (Firefox ignores the attribute) |
1421
+ | Safari, and a WKWebView | the same (measured in macOS's WKWebView) |
1422
+ | Android's WebView | not known |
1423
+
1424
+ Two copies of the loader on one page do the same to each other, in every
1425
+ browser (in Chrome's credentialless frames as well: one page is one store).
1426
+ A page in the back/forward cache keeps its locks, and its run of the tile
1427
+ with them: in WebKit (Safari, a WKWebView) it holds the wipes of other pages
1428
+ off until it is shown again, with what it stored, or let go; Chrome lets
1429
+ such a page go as soon as another asks for a lock it holds, which ends that
1430
+ run; Firefox does not keep such a page. The tile has no hand in the lock:
1431
+ it has no page on the loading server's origin, and a lock it takes on its
1432
+ own holds nothing off. Nor does a worker of the tile's outlive its pages
1433
+ there, with what it holds in memory, which no wipe reaches: the runtime
1434
+ starts no shared worker on such an origin, nor on any other tile origin,
1435
+ from any file, and the tile policy none from a blob or a `data:` URL (see
1436
+ "Origins named by a tile's CID" in tile-server's README). Behind a runtime from before that
1437
+ (`@dasl/tile-server` 4.0.0), one made with `extendedLifetime` lives five
1438
+ minutes past them in Chrome, carries what it holds to the tile's next run,
1439
+ and can write it back after a wipe.
1440
+
1441
+ Behind a loading server whose runtime takes no lock (`@dasl/tile-server`
1442
+ 4.0.0, and what is built from it), nothing holds a wipe off: where the
1443
+ browser keeps one store for the site (Firefox, Safari, Chrome in a plain
1444
+ frame), the second tab's start wipes the origin under the first's tile, and
1445
+ its close does the same: what it stored and its worker are gone, and it is
1446
+ refused its own files from then on; two copies of the loader on one page
1447
+ wipe under each other's tiles the same way.
1363
1448
 
1364
1449
  And what it costs:
1365
1450
 
1366
1451
  - **The host name says which tile is shown**, to DNS resolvers, to the
1367
1452
  network unless the browser hides it (Encrypted Client Hello), and to the
1368
1453
  tile server and whatever is in front of it. A minted name says nothing.
1369
- - **Pages of the same site, and every frame in them, can use what the tile
1370
- kept.** Any page of the site the tile is shown under can run the genuine
1371
- tile on its origin, with what it kept there, and feed it whatever it likes
1372
- over the tile protocols, or answer none of its requests, or have its origin
1373
- wiped. So can any frame in such a page, whatever site the frame is from: an
1374
- ad, an embedded player, a widget, and whatever they frame in turn. The
1375
- browser keeps the tile's store by the site at the top, and not by who
1376
- frames the tile (measured in Chrome and Firefox). None can run any other
1377
- tile there, nor other bytes or headers. Treat what a tile kept as the
1378
- tile's, not as yours to trust, and run tiles on the origins their CIDs name
1379
- only on pages whose frames you would let do this.
1454
+ - **A wipe before each start.** The first tile of the page to start there
1455
+ waits for its origin to be wiped: a frame of the loader's own that loads
1456
+ the dock and the runtime for that origin, and the tile server's wipe. One
1457
+ that a run of another page holds off is given a second to come first.
1458
+ Measured on loopback in Chrome, Firefox and WebKit (the median of five
1459
+ starts, in two runs), that wipe took 30 to 65 ms, and the tile was up 20 to
1460
+ 100 ms later than one on an origin made for the load; over a network it is
1461
+ a few round trips to the tile server more.
1462
+ - **Pages of the same site, and every frame in them, can reach a run of the
1463
+ tile.** Any page of the site the tile is shown under can run the genuine
1464
+ tile on its origin and feed it whatever it likes over the tile protocols,
1465
+ or answer none of its requests; and where the browser keeps one store for
1466
+ the site (above), its run of the tile starts on what a run of the tile in
1467
+ another of its pages has, and says to it whatever the tile says to its
1468
+ host. (Behind a loading server whose runtime takes no lock, it can also
1469
+ have the origin wiped under that run, by starting or closing its own.)
1470
+ So can any frame in such a page,
1471
+ whatever site the frame is from: an ad, an embedded player, a widget, and
1472
+ whatever they frame in turn. None can run any other tile there, nor other
1473
+ bytes or headers. Run tiles on the origins their CIDs name only on pages
1474
+ whose frames you would let do this.
1380
1475
 
1381
1476
  ## Loading a tile
1382
1477
 
@@ -1622,8 +1717,9 @@ for (const post of document.querySelectorAll('.post')) {
1622
1717
  is left alone, and its tile is not even loaded.
1623
1718
  - It is **closed** when its place has been out of view for a while
1624
1719
  (`closeAfter`, ten seconds), with `tile.close()`: the frame goes and the
1625
- origin is wiped. Shown again, it starts afresh on another origin, so this is
1626
- for tiles whose state you do not mean to keep.
1720
+ origin is wiped. Shown again, it starts afresh, on another origin (or on
1721
+ the one its CID names, wiped), so this is for tiles whose state you do not
1722
+ mean to keep.
1627
1723
  - No more than `maxLive` (six) are **live at once**. When another tile needs
1628
1724
  the room, the live one that has been out of view longest is closed for it.
1629
1725
  A tile in view is never closed for another: the other waits.
package/dist/index.d.ts CHANGED
@@ -20,17 +20,26 @@ export interface MothershipConfig {
20
20
  * Whether a tile runs on the origin its own content names: `<cid>.<base>`,
21
21
  * where `<cid>` is the CID of the tile's manifest, as its loader computed
22
22
  * it from the bytes it loaded (the record's `tile` on AT, the header of a
23
- * .tile file). Such an origin is kept: what the tile stores there it finds
24
- * again the next time it runs, on any page of the same site. It is shared
25
- * by every run of that tile on that site, and a new version of the tile,
26
- * which has another manifest, starts on another origin, with nothing.
23
+ * .tile file). The name says which tile runs there, and nothing more: what
24
+ * the tile stores there goes as it does on an origin made for one load.
25
+ * The origin is wiped when the tile is closed, and before it starts, so a
26
+ * run never finds what an earlier one left, closed or not; and its frame
27
+ * is credentialless. The one difference is that the same tile shown twice
28
+ * on a page is on the same origin twice, with one store: its wipes wait
29
+ * for the last of them to be closed, and the first to start. So does a
30
+ * run of it in another page of the site, where the browser keeps one
31
+ * store for the site (another tab, in Firefox or Safari, or with a plain
32
+ * frame in Chrome), or from another copy of the loader on this page,
33
+ * when the loading server's runtime holds each run there to a lock its
34
+ * wipes wait for (its dock says so): a tile that starts beside such a run
35
+ * shares what it has, and the last of them to be closed has it wiped.
27
36
  *
28
37
  * Anyone can name such an origin, so the loading server's runtime holds it
29
38
  * to the one tile whose manifest it is named by, and the loader runs a
30
39
  * tile there only when the loading server says that its runtime does. A
31
40
  * tile its loader has no manifest bytes for (a webxdc tile, one in memory)
32
- * runs on an origin made for the load, as without this; `tile.ephemeral`
33
- * says which. False when left out. Not with `namedOrigin`.
41
+ * runs on an origin made for the load, as without this. False when left
42
+ * out. Not with `namedOrigin`.
34
43
  */
35
44
  cidOrigins?: boolean;
36
45
  /**
@@ -164,7 +173,12 @@ export interface StoppedEvent extends Event {
164
173
  * - `worker`: the runtime could not start the tile's service worker. Some
165
174
  * browsers refuse one to a frame of another site once the user blocks
166
175
  * cross-site storage.
167
- * - `unsupported`: the browser lacks what the runtime needs.
176
+ * - `unsupported`: the browser lacks what the runtime needs (on the origin
177
+ * named by the tile's CID, Web Locks with the rest).
178
+ * - `frame`: the tile's frame was not handed the tile, tried twice: the
179
+ * browser did not ask the tile's worker for its root, or the worker
180
+ * refused it. The runtime shows nothing in its place. Loading the page
181
+ * again may do it.
168
182
  * - `content`: the tile's root document is not to be had: resolving it
169
183
  * failed, or the tile's worker gave up waiting for it (after a minute: a
170
184
  * deadline shorter than that has reported it first, as `timeout`).
@@ -172,17 +186,26 @@ export interface StoppedEvent extends Event {
172
186
  * the manifest it was handed: it is not the one that CID names, or not
173
187
  * one it could read (a .tile file whose header is not in DRISL's one
174
188
  * form). Nothing is served there.
189
+ * - `wipe`: the origin named by the tile's CID could not be wiped before the
190
+ * tile started there, twice, a few seconds apart (the loading server said
191
+ * it was not, or did not answer in time): what an earlier run left could
192
+ * still be there, so the tile is not run. Rendered again, it is tried
193
+ * again. A wipe that a run of the tile in another page there holds off
194
+ * is not one: the tile starts beside that run. (Only a runtime whose dock
195
+ * says that it holds runs to a lock holds a wipe off, and only its word
196
+ * that it did is taken.)
175
197
  *
176
198
  * A start (a frame the tile is attached to, each time it loads) fires one at
177
- * most. `worker` and `unsupported` are the runtime's own account, which
199
+ * most. `worker`, `unsupported` and `frame` are the runtime's own account, which
178
200
  * passes through the tile's origin on its way here, and a dock passes on what
179
201
  * its frame says under any name: what runs on that origin can have the start
180
202
  * reported as failed, for any of these reasons. On an origin made for the
181
203
  * one load nothing of the tile's runs before it has started, and no other
182
- * tile is there; tiles that share a named origin can do it to one another.
204
+ * tile is there; tiles that share a named origin can do it to one another,
205
+ * and so can the runs of one tile on the origin its CID names.
183
206
  */
184
207
  export interface TileErrorEvent extends Event {
185
- reason: 'timeout' | 'version' | 'worker' | 'unsupported' | 'content' | 'integrity';
208
+ reason: 'timeout' | 'version' | 'worker' | 'unsupported' | 'frame' | 'content' | 'integrity' | 'wipe';
186
209
  /** With `timeout`: what the tile was still waiting for. */
187
210
  stage?: 'dock' | 'shuttle' | 'worker' | 'content';
188
211
  /** With `version`: the generation the dock named, when it named a number. */
@@ -196,7 +219,7 @@ export interface TileErrorEvent extends Event {
196
219
  export interface FrameOptions {
197
220
  /** The frame's sandbox attribute in full: `allow-scripts allow-same-origin allow-forms` when left out. */
198
221
  sandbox?: string;
199
- /** Whether the frame is credentialless: `true` or `false`; when left out, it is on an origin made for the load, and not on a named origin or the origin named by the tile's CID (`tile.ephemeral`). */
222
+ /** Whether the frame is credentialless: `true` or `false`; when left out, it is unless the tile runs on a named origin (`tile.ephemeral`). */
200
223
  credentialless?: boolean;
201
224
  /** The frame's tabindex, a whole number from -32767 to 32767: `-1` has the Tab key pass over the tile. None when left out. The focus guard takes a frame it guards out of the tab order whatever this says (see `tabOrder` in @dasl/tile-loader/guard). */
202
225
  tabindex?: number;
@@ -257,14 +280,17 @@ export declare class TileMothership {
257
280
  * `sizing` goes along: the shuttle measures the content of a tile that
258
281
  * declares `fit` (see @dasl/tile-loader/size). So does whether its origin
259
282
  * is its own, made for this load: one that is can be thrown away with it.
283
+ * The origin named by a tile's CID is wiped too, but by us, and not under
284
+ * another run of the tile there, which needs its worker: it is not this
285
+ * run's to throw away on its own.
260
286
  */
261
287
  loadPayload(tile: Tile): Record<string, unknown>;
262
288
  /** @internal How long a tile gets to start, in milliseconds; 0 for no deadline. */
263
289
  get startDeadline(): number;
264
290
  /**
265
- * Whether tiles get an origin of their own for every load (no
266
- * `namedOrigin`). With `cidOrigins`, those that have a CID to be named by
267
- * do not: see `tile.ephemeral`.
291
+ * Whether what tiles store goes with each run, their origins wiped (no
292
+ * `namedOrigin`): an origin of their own for every load, or, with
293
+ * `cidOrigins`, the one their CID names. See `tile.ephemeral`.
268
294
  */
269
295
  get ephemeral(): boolean;
270
296
  /**
@@ -280,7 +306,8 @@ export declare class TileMothership {
280
306
  originNamedIn(src: unknown): string | undefined;
281
307
  /**
282
308
  * @internal Has a tile origin wiped, from a frame of our own making: what
283
- * closing a tile comes down to once its frame is out of the document.
309
+ * closing a tile comes down to once its frame is out of the document, and
310
+ * what a tile on the origin named by its CID starts after.
284
311
  *
285
312
  * The wipe answers a page of the origin it empties and no one else, and
286
313
  * this page is not one. So a frame is made, out of sight, that loads the
@@ -301,6 +328,23 @@ export declare class TileMothership {
301
328
  * false when it says not, or says nothing for WIPE_MS.
302
329
  */
303
330
  wipeOrigin(origin: string, credentialless?: boolean): Promise<boolean>;
331
+ /**
332
+ * @internal Has a tile origin wiped, as wipeOrigin() does, and says how it
333
+ * went: `wiped`; `held`, not wiped because a run of the tile there holds
334
+ * the run's lock; or `failed`, not wiped, or not as far as can be told.
335
+ *
336
+ * On an origin named by a tile's CID the runs of that tile share one store
337
+ * with whatever other page of the site runs it, where the browser keeps
338
+ * one store for the site: another tab, another copy of the loader on this
339
+ * page. Each holds the run's lock for as long as it runs, and the runtime
340
+ * wipes nothing while one does (see the run's lock in @dasl/tile-server's
341
+ * dock/dock.js): the last of them to be closed has it wiped. Only a runtime
342
+ * whose dock says that it holds runs to the lock (`lock` in its ready
343
+ * message, which that of @dasl/tile-server 4.0.0 does not say) is taken
344
+ * at its word that one does: from any other, a wipe that was not done is
345
+ * one that failed.
346
+ */
347
+ clearOrigin(origin: string, credentialless?: boolean): Promise<'wiped' | 'held' | 'failed'>;
304
348
  addLoader(loader: TileLoader): void;
305
349
  removeLoader(loader: TileLoader): void;
306
350
  /** The origin of the loading server: where the dock is, and so who we talk to. */
@@ -331,6 +375,13 @@ export declare class TileMothership {
331
375
  */
332
376
  loadTile(url: string, options?: TileLoadOptions): Promise<Tile | false>;
333
377
  }
378
+ interface SharedOrigin {
379
+ origin: string;
380
+ credentialless: boolean;
381
+ tiles: Set<WeakRef<Tile>>;
382
+ ready: Promise<boolean>;
383
+ again: boolean;
384
+ }
334
385
  export declare class Tile extends EventTarget {
335
386
  #private;
336
387
  constructor(mothership: TileMothership, url: string, manifest: AnyMasl, pathLoader: TilePathLoader, identity?: TileIdentity);
@@ -349,13 +400,18 @@ export declare class Tile extends EventTarget {
349
400
  /** @internal The bytes of its manifest, and their CID, where its loader has them. */
350
401
  get manifestBytes(): TileIdentity['manifestBytes'];
351
402
  /**
352
- * Whether the origin this tile runs on is made for one load and wiped when
353
- * it is closed. It is unless its mothership names an origin for its tiles
354
- * (`namedOrigin`), or runs them on the origin named by their CID
355
- * (`cidOrigins`) and this tile has a CID to be named by: such an origin is
356
- * kept, for the tile to find what it stored there again.
403
+ * Whether what this tile stores goes with each run of it: the origin it
404
+ * runs on is wiped when it is closed, and holds nothing from before when
405
+ * it starts. It is, on an origin made for one load and on the origin named
406
+ * by its CID (`cidOrigins`), unless its mothership names an origin for its
407
+ * tiles (`namedOrigin`): that one is kept, for a tile to find what it
408
+ * stored there again.
357
409
  */
358
410
  get ephemeral(): boolean;
411
+ /** @internal The origin named by a CID this run of the tile shares with the page's other tiles there, if it has started there. */
412
+ get sharedOrigin(): string | undefined;
413
+ /** @internal Whether this tile runs on that store now: it has started there, in a frame that is in the document. */
414
+ runsOn(shared: SharedOrigin): boolean;
359
415
  /**
360
416
  * @internal The bytes of the manifest that names this tile's origin, when
361
417
  * it runs on the origin named by its CID: what that origin's runtime is
@@ -384,7 +440,8 @@ export declare class Tile extends EventTarget {
384
440
  * this one run of the tile. It is the same address every time it is asked
385
441
  * for, so that it can sit in a template that is rendered again and again,
386
442
  * until the tile is closed: after that it is another run, on another
387
- * origin.
443
+ * origin. (With `cidOrigins`, the origin its CID names, every run: the
444
+ * next one finds it wiped.)
388
445
  */
389
446
  getLoadSource(): string;
390
447
  /**
@@ -421,7 +478,20 @@ export declare class Tile extends EventTarget {
421
478
  * one.
422
479
  */
423
480
  failed(reason: TileErrorEvent['reason'], detail?: Pick<TileErrorEvent, 'stage' | 'generation'>): void;
424
- /** @internal Tells the runtime in the frame to load the tile. */
481
+ /**
482
+ * @internal Tells the runtime in the frame to load the tile. On an origin
483
+ * named by a CID, the first tile of the page to start there has it wiped
484
+ * first, whatever an earlier run left there, closed or not (a page that
485
+ * went without closing it, one that crashed): the runtime is told once
486
+ * that is done, and is not told at all if it was not, the second time it
487
+ * was tried either (`wipe`). A tile that starts there while another of
488
+ * the page runs there finds what that one has: they share the origin, and
489
+ * wiping it would take it from that one.
490
+ * A frame that loads again goes on with the run it is in, unless it was
491
+ * out of the document while the others there went on without it (they
492
+ * may have had the origin wiped meanwhile, or be about to): then it
493
+ * starts there as any other tile does.
494
+ */
425
495
  start(): void;
426
496
  /** @internal The runtime says it has cleaned up. */
427
497
  runtimeClosed(): void;
@@ -442,8 +512,11 @@ export declare class Tile extends EventTarget {
442
512
  * reach is what the tile left in the browser. Every tile runs on an origin
443
513
  * made for that one load, and its worker's registration, and anything the
444
514
  * tile stored, would stay there for good. `close()` has that origin wiped
445
- * (not a named origin, `namedOrigin`, nor the origin named by the tile's
446
- * CID, `cidOrigins`: both are kept on purpose, see `tile.ephemeral`).
515
+ * (not a named origin, `namedOrigin`, which is kept on purpose: see
516
+ * `tile.ephemeral`). So it does the origin named by the tile's CID
517
+ * (`cidOrigins`), but only once the last tile of the page there is
518
+ * closed: the same tile shown twice on a page is on it twice, and the
519
+ * other still needs what is there.
447
520
  *
448
521
  * It does not matter what became of the frame first, nor what the tile
449
522
  * did. The frame's address names the origin (getLoadSource() does, and so
@@ -461,8 +534,11 @@ export declare class Tile extends EventTarget {
461
534
  * CLOSE_MS to answer. Out of the document, there is no one to ask.
462
535
  *
463
536
  * What it resolves to: true when the origin was wiped, and when the tile
464
- * never started (there was nothing to wipe); false for a named origin and
465
- * for the origin named by the tile's CID, which are kept, and when the
537
+ * never started (there was nothing to wipe); false for a named origin,
538
+ * which is kept; for the origin named by the tile's CID while another tile
539
+ * of the page still runs there, whose close has it wiped, or a run of
540
+ * another page (another tab of the site, another copy of the loader)
541
+ * holds it to its lock, which the runtime does not wipe under; and when the
466
542
  * wipe could not be done or was not confirmed, which is also logged as a
467
543
  * warning.
468
544
  */
@@ -492,11 +568,11 @@ export declare class Tile extends EventTarget {
492
568
  * everything inside cookies and storage of its own, empty to begin with
493
569
  * and gone with the page, and keeps its password manager out. Other
494
570
  * browsers ignore the attribute. When nothing is said, the frame is
495
- * credentialless if the tile's origin was made for this one load
496
- * (`tile.ephemeral`): nothing is lost by its storage going with the page.
497
- * A named origin, or the origin named by the tile's CID, is there for a
498
- * tile to find its storage again, which such a frame loses with every
499
- * page, so its frame is a plain one. `true` or
571
+ * credentialless if what the tile stores goes with its run
572
+ * (`tile.ephemeral`), on an origin made for this one load or on the one
573
+ * its CID names: nothing is lost by its storage going with the page. A
574
+ * named origin is there for a tile to find its storage again, which such
575
+ * a frame loses with every page, so its frame is a plain one. `true` or
500
576
  * `false` for a host that wants it otherwise, either way, and anything
501
577
  * else throws.
502
578
  *