@botiverse/porthole 0.7.0 → 0.9.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.
Files changed (166) hide show
  1. package/README.md +9 -2
  2. package/THIRD_PARTY_NOTICES.md +421 -0
  3. package/dist/annotate/types.d.ts +40 -4
  4. package/dist/annotate/types.js +6 -1
  5. package/dist/annotate/validate.d.ts +10 -0
  6. package/dist/annotate/validate.js +24 -1
  7. package/dist/bridge/bounded-text.d.ts +34 -0
  8. package/dist/bridge/bounded-text.js +188 -0
  9. package/dist/bridge/bridge.d.ts +25 -5
  10. package/dist/bridge/bridge.js +311 -73
  11. package/dist/bridge/json-data.d.ts +28 -0
  12. package/dist/bridge/json-data.js +86 -0
  13. package/dist/bridge/navigation.d.ts +5 -0
  14. package/dist/bridge/navigation.js +7 -0
  15. package/dist/bridge/refusal.js +1 -0
  16. package/dist/bridge/types.d.ts +32 -1
  17. package/dist/check/page-source.js +1 -1
  18. package/dist/check/page.js +2 -0
  19. package/dist/compile/compile.d.ts +6 -0
  20. package/dist/compile/compile.js +3 -1
  21. package/dist/compile/policy.d.ts +38 -2
  22. package/dist/compile/policy.js +122 -7
  23. package/dist/config/capabilities.d.ts +23 -4
  24. package/dist/config/capabilities.js +12 -2
  25. package/dist/config/schema.d.ts +11 -0
  26. package/dist/config/validate.d.ts +8 -2
  27. package/dist/config/validate.js +28 -6
  28. package/dist/config/warnings.d.ts +20 -0
  29. package/dist/config/warnings.js +25 -0
  30. package/dist/conformance/behavior.js +46 -1
  31. package/dist/conformance/cookies.d.ts +15 -0
  32. package/dist/conformance/cookies.js +80 -0
  33. package/dist/conformance/harness/page.d.ts +1 -0
  34. package/dist/conformance/harness/page.js +9 -2
  35. package/dist/conformance/harness-source.js +1 -1
  36. package/dist/conformance/host-kit.js +5 -1
  37. package/dist/conformance/index.d.ts +10 -0
  38. package/dist/conformance/limits.js +38 -1
  39. package/dist/conformance/runtime.js +10 -0
  40. package/dist/conformance/served.d.ts +2 -0
  41. package/dist/conformance/served.js +737 -4
  42. package/dist/files/paths.js +4 -0
  43. package/dist/guide/gates.d.ts +7 -1
  44. package/dist/guide/gates.js +12 -0
  45. package/dist/guide/guide.js +2 -2
  46. package/dist/guide/runtime.js +11 -3
  47. package/dist/host/create-host.js +81 -39
  48. package/dist/host/pages-of-set.d.ts +43 -0
  49. package/dist/host/pages-of-set.js +196 -0
  50. package/dist/host/types.d.ts +8 -1
  51. package/dist/index.d.ts +5 -4
  52. package/dist/index.js +3 -2
  53. package/dist/mcp/adapter.js +11 -15
  54. package/dist/node/index.d.ts +36 -4
  55. package/dist/node/index.js +402 -101
  56. package/dist/platform/types.d.ts +9 -0
  57. package/dist/platform/web.js +8 -0
  58. package/dist/presets/presets.d.ts +16 -8
  59. package/dist/presets/presets.js +39 -8
  60. package/dist/protocol/live-data.d.ts +6 -2
  61. package/dist/protocol/live-data.js +20 -1
  62. package/dist/protocol/mcp-apps.d.ts +13 -2
  63. package/dist/protocol/mcp-apps.js +10 -2
  64. package/dist/protocol/message-text.d.ts +8 -0
  65. package/dist/protocol/message-text.js +29 -0
  66. package/dist/protocol/runtime-calls.js +3 -0
  67. package/dist/protocol/shell-adapter.js +16 -22
  68. package/dist/react/context-notice.d.ts +32 -0
  69. package/dist/react/context-notice.js +28 -0
  70. package/dist/react/dialog.js +62 -18
  71. package/dist/react/frame.d.ts +18 -3
  72. package/dist/react/frame.js +79 -2
  73. package/dist/react/index.d.ts +2 -1
  74. package/dist/react/index.js +2 -1
  75. package/dist/runtime/contract.d.ts +9 -1
  76. package/dist/runtime/contract.js +31 -2
  77. package/dist/runtime/db.d.ts +41 -6
  78. package/dist/runtime/db.js +120 -16
  79. package/dist/runtime/declaration.d.ts +15 -1
  80. package/dist/runtime/declaration.js +184 -87
  81. package/dist/runtime/requests.js +27 -11
  82. package/dist/runtime/types.generated.js +1 -1
  83. package/dist/server/files.d.ts +5 -0
  84. package/dist/server/files.js +22 -7
  85. package/dist/server/host.d.ts +18 -1
  86. package/dist/server/host.js +132 -2
  87. package/dist/server/index.d.ts +1 -1
  88. package/dist/server/index.js +1 -1
  89. package/dist/server/peer.d.ts +4 -0
  90. package/dist/server/peer.js +19 -0
  91. package/dist/server/proxy.d.ts +6 -0
  92. package/dist/server/proxy.js +12 -3
  93. package/dist/server/server.js +113 -26
  94. package/dist/server/types.d.ts +6 -3
  95. package/dist/shell/annotate.d.ts +7 -2
  96. package/dist/shell/annotate.js +233 -15
  97. package/dist/shell/document.d.ts +8 -0
  98. package/dist/shell/document.js +3 -0
  99. package/dist/shell/runtime.js +361 -14
  100. package/docs/ADOPTING.md +119 -14
  101. package/docs/ARCHITECTURE.md +15 -4
  102. package/docs/DECISIONS.md +1610 -9
  103. package/docs/DESIGN.md +114 -30
  104. package/docs/THREAT_MODEL.md +652 -0
  105. package/package.json +14 -3
  106. package/src/annotate/types.ts +37 -5
  107. package/src/annotate/validate.ts +30 -1
  108. package/src/bridge/bounded-text.ts +240 -0
  109. package/src/bridge/bridge.ts +373 -84
  110. package/src/bridge/json-data.ts +95 -0
  111. package/src/bridge/navigation.ts +10 -0
  112. package/src/bridge/refusal.ts +1 -0
  113. package/src/bridge/types.ts +30 -1
  114. package/src/check/page.ts +2 -0
  115. package/src/compile/compile.ts +9 -1
  116. package/src/compile/policy.ts +130 -7
  117. package/src/config/capabilities.ts +22 -3
  118. package/src/config/schema.ts +11 -0
  119. package/src/config/validate.ts +43 -5
  120. package/src/config/warnings.ts +42 -0
  121. package/src/conformance/behavior.ts +54 -1
  122. package/src/conformance/cookies.ts +93 -0
  123. package/src/conformance/harness/page.ts +11 -2
  124. package/src/conformance/host-kit.ts +10 -1
  125. package/src/conformance/index.ts +10 -0
  126. package/src/conformance/limits.ts +39 -1
  127. package/src/conformance/runtime.ts +21 -0
  128. package/src/conformance/served.ts +888 -4
  129. package/src/files/paths.ts +4 -0
  130. package/src/guide/gates.ts +13 -1
  131. package/src/guide/guide.ts +3 -3
  132. package/src/guide/runtime.ts +12 -3
  133. package/src/host/create-host.ts +88 -38
  134. package/src/host/pages-of-set.ts +226 -0
  135. package/src/host/types.ts +15 -1
  136. package/src/index.ts +5 -0
  137. package/src/mcp/adapter.ts +16 -20
  138. package/src/node/index.ts +507 -116
  139. package/src/platform/types.ts +6 -0
  140. package/src/platform/web.ts +10 -0
  141. package/src/presets/presets.ts +60 -17
  142. package/src/protocol/live-data.ts +31 -3
  143. package/src/protocol/mcp-apps.ts +11 -2
  144. package/src/protocol/message-text.ts +36 -0
  145. package/src/protocol/runtime-calls.ts +3 -0
  146. package/src/protocol/shell-adapter.ts +27 -23
  147. package/src/react/context-notice.tsx +95 -0
  148. package/src/react/dialog.tsx +77 -17
  149. package/src/react/frame.tsx +107 -2
  150. package/src/react/index.ts +8 -1
  151. package/src/runtime/contract.ts +36 -2
  152. package/src/runtime/db.ts +140 -20
  153. package/src/runtime/declaration.ts +227 -89
  154. package/src/runtime/requests.ts +27 -11
  155. package/src/runtime/types.generated.ts +1 -1
  156. package/src/server/files.ts +29 -11
  157. package/src/server/host.ts +158 -3
  158. package/src/server/index.ts +1 -0
  159. package/src/server/peer.ts +21 -0
  160. package/src/server/proxy.ts +13 -3
  161. package/src/server/server.ts +139 -36
  162. package/src/server/types.ts +6 -3
  163. package/src/shell/annotate.ts +233 -15
  164. package/src/shell/document.ts +8 -0
  165. package/src/shell/runtime.ts +361 -14
  166. package/types/runtime/v1/context.d.ts +13 -2
@@ -16,6 +16,7 @@ import type { ConformanceTest } from "./probes.ts";
16
16
  import type { EgressConfig } from "../config/schema.ts";
17
17
  import type { FrameLocation, InstanceRef } from "../isolation/types.ts";
18
18
  import { MCP_APPS_METHODS } from "../protocol/mcp-apps.ts";
19
+ import { keepsFramedCookies } from "./cookies.ts";
19
20
 
20
21
  /** One served display, as the host shows it. */
21
22
  export interface ServedDisplay {
@@ -81,6 +82,17 @@ export interface ServedSuiteOptions {
81
82
 
82
83
  type Fixtures = { page: Page; browserName: string };
83
84
 
85
+ /** The cases of a served page on a tab of its own (P099), one per wall. */
86
+ export const TAB_CASES: readonly string[] = [
87
+ "served.domain.tab-window-open",
88
+ "served.domain.tab-escapes",
89
+ "served.domain.tab-opener",
90
+ "served.domain.tab-navigation",
91
+ "served.domain.tab-links",
92
+ "served.domain.tab-devices",
93
+ "served.domain.tab-prompts",
94
+ ];
95
+
84
96
  const SETTLE_MS = 800;
85
97
 
86
98
  /** What a served shell is given to draw (`ServedConformanceHost.show`'s `content`). */
@@ -379,6 +391,808 @@ export function servedTests(
379
391
  },
380
392
  );
381
393
 
394
+ define(
395
+ "served.domain.self-navigation",
396
+ "a served frame can't navigate itself away, to an outside site or another content origin, even after a click",
397
+ async ({ page }) => {
398
+ // Data in the address of a navigation the frame starts itself (P079). Another content
399
+ // origin first: the embedding page's frame-src must let content origins in, so the shell's
400
+ // guard is the only wall there, and the frame's document must stay. Then an outside site,
401
+ // which frame-src stops too (where it does, an engine may show its error page in the
402
+ // frame): no request may reach it.
403
+ const display = await host.show(page, await host.shell("self-navigation"), {
404
+ content: SHELL_CONTENT,
405
+ });
406
+ const frame = await display.frame();
407
+ const sibling = `${(await host.locate(await host.shell("self-navigation-sibling"))).origin}/?d=secret`;
408
+ const outside = `${await host.canary("self-navigation")}?d=secret`;
409
+ const away = async (url: string): Promise<void> => {
410
+ await frame.evaluate((target) => {
411
+ (window as unknown as { portholeProbeStays?: boolean }).portholeProbeStays = true;
412
+ document.getElementById("porthole-probe-self")?.remove();
413
+ const button = document.createElement("button");
414
+ button.id = "porthole-probe-self";
415
+ button.textContent = "go";
416
+ button.addEventListener("click", () => {
417
+ location.href = target;
418
+ });
419
+ document.body.append(button);
420
+ }, url);
421
+ await frame.click("#porthole-probe-self");
422
+ await page.waitForTimeout(SETTLE_MS);
423
+ };
424
+ await away(sibling);
425
+ const stays = await frame
426
+ .evaluate(
427
+ () =>
428
+ (window as unknown as { portholeProbeStays?: boolean }).portholeProbeStays === true,
429
+ )
430
+ .catch(() => false);
431
+ expect(stays, "another content origin: the frame's document stays").toBe(true);
432
+ expect(new URL(frame.url()).origin, "another content origin").toBe(display.origin);
433
+ await away(outside);
434
+ expect(await host.canaryHits("self-navigation"), "the outside site").toBe(0);
435
+ },
436
+ );
437
+
438
+ // A served page on a tab of its own (P099, the review's S4): a public link, "open in a new
439
+ // tab", a bookmark. No frame's sandbox is there: the page's own (its CSP's `sandbox`) must
440
+ // hold what the frame's holds, and a click (a visitor's, after typing into the page) must open
441
+ // nothing either. One case per wall, so each negative control fails its own.
442
+ const onTab = async (page: Page, scope: string): Promise<void> => {
443
+ const location = await host.locate(await host.shell(scope));
444
+ const answer = await page.goto(location.url);
445
+ expect(answer?.status()).toBe(200);
446
+ expect(new URL(page.url()).origin).toBe(location.origin);
447
+ };
448
+ /**
449
+ * Clicks `selector` with raw input: a person's click (user activation), and an action that
450
+ * doesn't wait on what the click starts (a navigation refused, a popup that never commits).
451
+ */
452
+ const press = async (page: Page, selector: string): Promise<void> => {
453
+ const box = await page.locator(selector).boundingBox();
454
+ expect(box, selector).not.toBeNull();
455
+ await page.mouse.click(
456
+ (box?.x ?? 0) + (box?.width ?? 0) / 2,
457
+ (box?.y ?? 0) + (box?.height ?? 0) / 2,
458
+ );
459
+ };
460
+ /** Windows, downloads and browser dialogs the page's context starts from now on. */
461
+ const watchWindows = (page: Page) => {
462
+ const opened: string[] = [];
463
+ const downloads: string[] = [];
464
+ const dialogs: string[] = [];
465
+ page.context().on("page", (each) => opened.push(each.url()));
466
+ page.on("download", (each) => downloads.push(each.url()));
467
+ page.on("dialog", (each) => {
468
+ dialogs.push(`${each.type()}: ${each.message()}`);
469
+ void each.dismiss();
470
+ });
471
+ return { opened, downloads, dialogs };
472
+ };
473
+
474
+ define(
475
+ "served.domain.tab-window-open",
476
+ "a page on a tab of its own can't open a window (window.open, a picture-in-picture document), even after a click",
477
+ async ({ page }) => {
478
+ await onTab(page, "tab-window-open");
479
+ const target = await host.canary("tab-window-open");
480
+ const { opened } = watchWindows(page);
481
+ const programmatic = await page.evaluate((url) => {
482
+ // Chromium and WebKit answer null, Firefox throws: either way nothing opens.
483
+ const open = () => {
484
+ try {
485
+ return window.open(`${url}?d=secret`) !== null;
486
+ } catch {
487
+ return false;
488
+ }
489
+ };
490
+ // A picture-in-picture document (Chromium, Firefox) is a window of this origin, in a
491
+ // fresh realm the shell never hardened: measured, on a tab it opened with WebRTC there.
492
+ const pip = (
493
+ window as unknown as {
494
+ documentPictureInPicture?: { requestWindow(options?: object): Promise<Window> };
495
+ }
496
+ ).documentPictureInPicture;
497
+ const button = document.createElement("button");
498
+ button.id = "porthole-probe-open";
499
+ button.textContent = "send";
500
+ button.addEventListener("click", () => {
501
+ document.body.dataset.popup = String(open());
502
+ if (pip === undefined) {
503
+ document.body.dataset.pip = "absent";
504
+ return;
505
+ }
506
+ pip.requestWindow({ width: 120, height: 120 }).then(
507
+ (shown) => {
508
+ document.body.dataset.pip = "opened";
509
+ shown.close();
510
+ },
511
+ () => {
512
+ document.body.dataset.pip = "refused";
513
+ },
514
+ );
515
+ });
516
+ document.body.append(button);
517
+ return open();
518
+ }, target);
519
+ await press(page, "#porthole-probe-open");
520
+ await page.waitForTimeout(SETTLE_MS);
521
+ expect(programmatic, "on load").toBe(false);
522
+ expect(await page.evaluate(() => document.body.dataset.popup), "after a click").toBe(
523
+ "false",
524
+ );
525
+ expect(["absent", "refused"], "picture-in-picture").toContain(
526
+ await page.evaluate(() => document.body.dataset.pip),
527
+ );
528
+ expect(opened, "a window opened").toEqual([]);
529
+ expect(await host.canaryHits("tab-window-open")).toBe(0);
530
+ },
531
+ );
532
+
533
+ define(
534
+ "served.domain.tab-escapes",
535
+ "a page on a tab of its own can't open a link in a new window, submit a form, start a download or ask in a browser dialog, even after a click",
536
+ async ({ page }) => {
537
+ await onTab(page, "tab-escapes");
538
+ const kinds = ["link", "form", "blank-form"] as const;
539
+ const urls = Object.fromEntries(
540
+ await Promise.all(kinds.map(async (kind) => [kind, await host.canary(`tab-${kind}`)])),
541
+ ) as Record<(typeof kinds)[number], string>;
542
+ const { opened, downloads, dialogs } = watchWindows(page);
543
+ await page.evaluate((each) => {
544
+ const box = document.createElement("div");
545
+ box.innerHTML = `<a id="porthole-probe-blank" href="${each.link}?d=secret" target="_blank">blank</a>
546
+ <form id="porthole-probe-form" action="${each.form}" method="get"><input name="d" value="secret"></form>
547
+ <form id="porthole-probe-blank-form" action="${each["blank-form"]}" target="_blank"><input name="d" value="secret"></form>`;
548
+ document.body.append(box);
549
+ // Links clicked past the shell's own click handling, as content may click them.
550
+ window.addEventListener(
551
+ "click",
552
+ (event) => {
553
+ if (event.target instanceof Element && event.target.closest("a") !== null) {
554
+ event.stopImmediatePropagation();
555
+ }
556
+ },
557
+ true,
558
+ );
559
+ const button = document.createElement("button");
560
+ button.id = "porthole-probe-escape";
561
+ button.textContent = "send";
562
+ button.addEventListener("click", () => {
563
+ document.getElementById("porthole-probe-blank")?.click();
564
+ for (const id of ["porthole-probe-form", "porthole-probe-blank-form"]) {
565
+ try {
566
+ (document.getElementById(id) as HTMLFormElement).submit();
567
+ } catch {
568
+ // Refused: what we want.
569
+ }
570
+ }
571
+ const save = document.createElement("a");
572
+ save.href = URL.createObjectURL(new Blob(["secret"]));
573
+ save.download = "secret.txt";
574
+ document.body.append(save);
575
+ save.click();
576
+ // The browser's own dialog, asking for what a phishing page wants (no allow-modals).
577
+ window.prompt("Your password, to go on");
578
+ });
579
+ document.body.append(button);
580
+ }, urls);
581
+ await press(page, "#porthole-probe-escape");
582
+ await page.waitForTimeout(SETTLE_MS);
583
+ expect(opened, "a window opened").toEqual([]);
584
+ expect(downloads, "a download started").toEqual([]);
585
+ expect(dialogs, "a browser dialog showed").toEqual([]);
586
+ expect(new URL(page.url()).pathname, "the page stays").not.toMatch(/canary/u);
587
+ for (const kind of kinds) {
588
+ expect(await host.canaryHits(`tab-${kind}`), kind).toBe(0);
589
+ }
590
+ },
591
+ );
592
+
593
+ /** A served shell on a tab opened by another page that keeps a reference to it. */
594
+ const fromOpener = async (page: Page, scope: string): Promise<Page> => {
595
+ const location = await host.locate(await host.shell(scope));
596
+ await page.goto("about:blank");
597
+ await page.setContent('<button id="porthole-probe-opener" type="button">open</button>');
598
+ await page.evaluate((url) => {
599
+ document
600
+ .getElementById("porthole-probe-opener")
601
+ ?.addEventListener("click", () => void window.open(url));
602
+ }, location.url);
603
+ const [tab] = await Promise.all([
604
+ page.waitForEvent("popup"),
605
+ press(page, "#porthole-probe-opener"),
606
+ ]);
607
+ await tab.waitForURL((url) => url.origin === location.origin);
608
+ await tab.waitForLoadState("load");
609
+ return tab;
610
+ };
611
+ /** Adds a button to `page` that sends itself or its opener to `url` when clicked; clicks it. */
612
+ const clickAway = async (page: Page, url: string, which: "self" | "opener") => {
613
+ await page.evaluate(
614
+ ([target, whose]) => {
615
+ const button = document.createElement("button");
616
+ button.id = "porthole-probe-away";
617
+ button.textContent = "go";
618
+ button.addEventListener("click", () => {
619
+ try {
620
+ (whose === "opener" ? (window.opener as Window) : window).location.href = target;
621
+ } catch {
622
+ // Refused: what we want.
623
+ }
624
+ });
625
+ document.body.append(button);
626
+ },
627
+ [url, which] as const,
628
+ );
629
+ await press(page, "#porthole-probe-away");
630
+ };
631
+
632
+ define(
633
+ "served.domain.tab-opener",
634
+ "a page on a tab of its own can't navigate the page that opened it, even after a click",
635
+ async ({ page }) => {
636
+ // `window.open` without noopener: the opener keeps a reference to the tab, and the tab to
637
+ // it, which an unsandboxed page may send elsewhere (reverse tabnabbing).
638
+ const tab = await fromOpener(page, "tab-opener");
639
+ const away = await host.canary("tab-opener");
640
+ await clickAway(tab, `${away}?d=secret`, "opener");
641
+ await page.waitForTimeout(SETTLE_MS);
642
+ expect(page.url(), "the opener stays").toBe("about:blank");
643
+ expect(await host.canaryHits("tab-opener")).toBe(0);
644
+ },
645
+ );
646
+
647
+ define(
648
+ "served.domain.tab-navigation",
649
+ 'a page on a tab of its own can\'t navigate itself away, to a blob: document of its own or an outside site, by location, a link, navigation.navigate() or open(…, "_self"), however the address is given',
650
+ async ({ page, browserName }) => {
651
+ const located = await host.locate(await host.shell("tab-navigation"));
652
+ // Location granted by the browser, so a document the shell never ran in would get it.
653
+ await page
654
+ .context()
655
+ .grantPermissions(["geolocation"], { origin: located.origin })
656
+ .catch(() => {});
657
+ await page.context().setGeolocation({ latitude: 48.8566, longitude: 2.3522 });
658
+ // A document it wrote itself (its own origin and CSP, sandbox included, no shell), then an
659
+ // outside site; each by `location`, by `navigation.navigate()` (WebKit sent its request though
660
+ // the navigate event cancelled it: measured) and by `open(…, "_self")`.
661
+ // Every way a page starts its own navigation: `location` (set, assign, replace), a
662
+ // target=_self link clicked past the shell, `navigation.navigate()`, `open(…, "_self")`,
663
+ // and the last two given an object whose address is a page of its own the first time it
664
+ // is read and the outside site after, and both again with String.prototype, URL, closest
665
+ // and an event's target replaced by liars that say the address is the page's own. Each
666
+ // outside one has a canary of its own: WebKit was measured sending the request of
667
+ // navigation.navigate() and of a link though the navigate event cancelled them.
668
+ info?.setTimeout(90_000);
669
+ const ways = [
670
+ "location",
671
+ "assign",
672
+ "replace",
673
+ "link",
674
+ "navigate",
675
+ "open",
676
+ "navigate-twice",
677
+ "open-twice",
678
+ "navigate-lying",
679
+ "link-lying",
680
+ ];
681
+ const canaries = Object.fromEntries(
682
+ await Promise.all(ways.map(async (how) => [how, await host.canary(`tab-nav-${how}`)])),
683
+ ) as Record<string, string>;
684
+ /** The tab, loaded again (its session cookie serves it), with one button armed. */
685
+ const arm = (tab: Page, kind: string, way: string) =>
686
+ tab.evaluate(
687
+ ([outside, name, how]) => {
688
+ const html = `<!doctype html><title>blob</title><script>
689
+ const said = { rtc: typeof RTCPeerConnection };
690
+ const done = () => { document.title = JSON.stringify(said); };
691
+ navigator.geolocation.getCurrentPosition(() => { said.location = "granted"; done(); }, (e) => { said.location = "denied " + e.code; done(); });
692
+ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).then(() => { said.media = "granted"; done(); }, (e) => { said.media = "rejected " + e.name; done(); });
693
+ </script>`;
694
+ const blob = URL.createObjectURL(new Blob([html], { type: "text/html" }));
695
+ const navigation = (
696
+ window as unknown as { navigation?: { navigate(url: unknown): unknown } }
697
+ ).navigation;
698
+ // Links clicked past the shell's own click handling, as content may click them.
699
+ window.addEventListener(
700
+ "click",
701
+ (event) => {
702
+ if (event.target instanceof Element && event.target.closest("a") !== null) {
703
+ event.stopImmediatePropagation();
704
+ }
705
+ },
706
+ true,
707
+ );
708
+ const twoFaced = (url: string) => {
709
+ let reads = 0;
710
+ return {
711
+ toString: () => {
712
+ reads += 1;
713
+ return reads === 1 ? location.href : url;
714
+ },
715
+ };
716
+ };
717
+ // Built-ins replaced for the length of one call, each lying in the page's favour.
718
+ const lying = (run: () => void) => {
719
+ const here = location.href;
720
+ const liars: [object, string, unknown][] = [
721
+ [String.prototype, "indexOf", () => 0],
722
+ [String.prototype, "split", () => [here]],
723
+ [
724
+ window,
725
+ "URL",
726
+ function () {
727
+ return { href: here };
728
+ },
729
+ ],
730
+ [Element.prototype, "closest", () => null],
731
+ ];
732
+ const kept = liars.map(
733
+ ([owner, key]) =>
734
+ [owner, key, Object.getOwnPropertyDescriptor(owner, key)] as const,
735
+ );
736
+ const target = Object.getOwnPropertyDescriptor(Event.prototype, "target");
737
+ for (const [owner, key, value] of liars) {
738
+ Object.defineProperty(owner, key, { configurable: true, writable: true, value });
739
+ }
740
+ Object.defineProperty(Event.prototype, "target", {
741
+ configurable: true,
742
+ get: () => document.body,
743
+ });
744
+ try {
745
+ run();
746
+ } finally {
747
+ for (const [owner, key, descriptor] of kept) {
748
+ if (descriptor !== undefined) {
749
+ Object.defineProperty(owner, key, descriptor);
750
+ }
751
+ }
752
+ if (target !== undefined) {
753
+ Object.defineProperty(Event.prototype, "target", target);
754
+ }
755
+ }
756
+ };
757
+ const quiet = (result: unknown) => {
758
+ const started = result as {
759
+ committed?: Promise<unknown>;
760
+ finished?: Promise<unknown>;
761
+ } | null;
762
+ started?.committed?.catch(() => {});
763
+ started?.finished?.catch(() => {});
764
+ };
765
+ {
766
+ {
767
+ const url = name === "blob" ? blob : `${outside[how]}?d=secret`;
768
+ const button = document.createElement("button");
769
+ button.id = `porthole-probe-${name}-${how}`;
770
+ button.textContent = `${name} by ${how}`;
771
+ button.addEventListener("click", () => {
772
+ try {
773
+ if (how === "location") {
774
+ location.href = url;
775
+ } else if (how === "assign") {
776
+ location.assign(url);
777
+ } else if (how === "replace") {
778
+ location.replace(url);
779
+ } else if (how === "link" || how === "link-lying") {
780
+ const link = document.createElement("a");
781
+ link.href = url;
782
+ link.target = "_self";
783
+ document.body.append(link);
784
+ if (how === "link") {
785
+ link.click();
786
+ } else {
787
+ lying(() => link.click());
788
+ }
789
+ } else if (how === "navigate-lying") {
790
+ lying(() => quiet(navigation?.navigate(url)));
791
+ } else if (how === "open") {
792
+ window.open(url, "_self");
793
+ } else if (how === "open-twice") {
794
+ window.open(twoFaced(url) as unknown as string, "_self");
795
+ } else if (navigation !== undefined) {
796
+ quiet(navigation.navigate(how === "navigate" ? url : twoFaced(url)));
797
+ }
798
+ } catch {
799
+ // Refused: what we want.
800
+ }
801
+ });
802
+ document.body.append(button);
803
+ }
804
+ }
805
+ },
806
+ [canaries, kind, way] as const,
807
+ );
808
+ for (const name of ["blob", "outside"]) {
809
+ for (const how of ways) {
810
+ // A tab of its own each time, from a fresh ticket: WebKit was measured sending a
811
+ // cancelled navigation's request from a tab's first, and not from one after another.
812
+ const fresh = await host.locate(await host.shell("tab-navigation"));
813
+ const tab = await page.context().newPage();
814
+ expect((await tab.goto(fresh.url))?.status()).toBe(200);
815
+ const here = tab.url();
816
+ await arm(tab, name, how);
817
+ const id = `porthole-probe-${name}-${how}`;
818
+ // Clicked by the page itself, after the evaluation returns: none of these needs a
819
+ // person's click, and a Playwright action may wait on a navigation the engine started
820
+ // and dropped (measured: WebKit, a mouse click after these, never returned).
821
+ await tab.evaluate((each) => {
822
+ setTimeout(() => document.getElementById(each)?.click(), 0);
823
+ }, id);
824
+ await tab.waitForTimeout(SETTLE_MS);
825
+ if (tab.url().startsWith("blob:")) {
826
+ // What such a document gets, where nothing stopped it (P099's accepted limit).
827
+ info?.annotations.push({
828
+ type: "measured",
829
+ description: `${browserName}: a blob: document of its own, by ${how}, got ${await tab.title()}`,
830
+ });
831
+ }
832
+ expect(
833
+ tab.url(),
834
+ `a ${name === "blob" ? "blob: document" : "outside site"} by ${how}: the tab stays`,
835
+ ).toBe(here);
836
+ await tab.close();
837
+ }
838
+ }
839
+ await page.waitForTimeout(SETTLE_MS);
840
+ const heard = (
841
+ await Promise.all(
842
+ ways.map(async (how) => [how, await host.canaryHits(`tab-nav-${how}`)] as const),
843
+ )
844
+ ).filter(([, hits]) => hits > 0);
845
+ expect(heard, "the outside site heard these").toEqual([]);
846
+ },
847
+ );
848
+
849
+ define(
850
+ "served.domain.tab-links",
851
+ "a page on a tab of its own can't send a link elsewhere by changing it after the shell read it, or from a shadow root; its fragment links and its own cancels still work",
852
+ async ({ page }) => {
853
+ // The browser follows a link with what it is once every listener ran; the shell follows
854
+ // what it read in the first. Each in a fresh tab (WebKit sent a cancelled navigation's
855
+ // request from a tab's first attempt), each outside one with a canary of its own.
856
+ info?.setTimeout(90_000);
857
+ const ways = [
858
+ "switch-href",
859
+ "switch-target",
860
+ "add-href",
861
+ "drop-download",
862
+ "open-shadow",
863
+ "closed-shadow",
864
+ ];
865
+ const canaries = Object.fromEntries(
866
+ await Promise.all(ways.map(async (how) => [how, await host.canary(`tab-links-${how}`)])),
867
+ ) as Record<string, string>;
868
+ const freshTab = async () => {
869
+ const located = await host.locate(await host.shell("tab-links"));
870
+ const tab = await page.context().newPage();
871
+ expect((await tab.goto(located.url))?.status()).toBe(200);
872
+ return tab;
873
+ };
874
+ for (const how of ways) {
875
+ const tab = await freshTab();
876
+ const here = tab.url();
877
+ await tab.evaluate(
878
+ ([way, outside]) => {
879
+ const url = `${outside}?d=secret`;
880
+ const link = document.createElement("a");
881
+ link.textContent = "go";
882
+ if (way === "switch-href") {
883
+ link.href = location.href;
884
+ } else if (way === "switch-target") {
885
+ link.href = url;
886
+ link.target = "_blank";
887
+ } else if (way === "drop-download") {
888
+ link.href = "data.bin";
889
+ link.setAttribute("download", "data.bin");
890
+ } else if (way !== "add-href") {
891
+ link.href = url;
892
+ }
893
+ if (way === "open-shadow" || way === "closed-shadow") {
894
+ const holder = document.createElement("div");
895
+ document.body.append(holder);
896
+ const root = holder.attachShadow({
897
+ mode: way === "open-shadow" ? "open" : "closed",
898
+ });
899
+ root.append(link);
900
+ // Past every listener after the shell's, the shadow tree's own included.
901
+ window.addEventListener("click", (event) => event.stopImmediatePropagation(), true);
902
+ } else {
903
+ document.body.append(link);
904
+ // After the shell's first listener, and past every one after it: the link changed
905
+ // before the browser reads it.
906
+ window.addEventListener(
907
+ "click",
908
+ (event) => {
909
+ event.stopImmediatePropagation();
910
+ if (way === "switch-target") {
911
+ link.target = "_self";
912
+ } else {
913
+ link.href = url;
914
+ }
915
+ if (way === "drop-download") {
916
+ link.removeAttribute("download");
917
+ }
918
+ },
919
+ true,
920
+ );
921
+ }
922
+ setTimeout(() => link.click(), 0);
923
+ },
924
+ [how, canaries[how] ?? ""] as const,
925
+ );
926
+ await tab.waitForTimeout(SETTLE_MS);
927
+ expect(tab.url(), `${how}: the tab stays`).toBe(here);
928
+ await tab.close();
929
+ }
930
+ await page.waitForTimeout(SETTLE_MS);
931
+ const heard = (
932
+ await Promise.all(
933
+ ways.map(async (how) => [how, await host.canaryHits(`tab-links-${how}`)] as const),
934
+ )
935
+ ).filter(([, hits]) => hits > 0);
936
+ expect(heard, "the outside site heard these").toEqual([]);
937
+ // Still as before: a fragment link jumps; a link content cancels goes nowhere.
938
+ const tab = await freshTab();
939
+ await tab.evaluate(() => {
940
+ const below = document.createElement("p");
941
+ below.id = "porthole-probe-below";
942
+ const jump = document.createElement("a");
943
+ jump.id = "porthole-probe-jump";
944
+ jump.href = "#porthole-probe-below";
945
+ jump.textContent = "jump";
946
+ const kept = document.createElement("a");
947
+ kept.id = "porthole-probe-kept";
948
+ kept.href = "#porthole-probe-kept";
949
+ kept.textContent = "kept";
950
+ kept.addEventListener("click", (event) => event.preventDefault());
951
+ document.body.append(jump, kept, below);
952
+ setTimeout(() => jump.click(), 0);
953
+ });
954
+ await expect
955
+ .poll(() => tab.evaluate(() => location.hash), { timeout: 3_000 })
956
+ .toBe("#porthole-probe-below");
957
+ await tab.evaluate(() => {
958
+ setTimeout(() => document.getElementById("porthole-probe-kept")?.click(), 0);
959
+ });
960
+ await tab.waitForTimeout(SETTLE_MS);
961
+ expect(await tab.evaluate(() => location.hash), "a click content cancelled").toBe(
962
+ "#porthole-probe-below",
963
+ );
964
+ await tab.close();
965
+ },
966
+ );
967
+
968
+ define(
969
+ "served.domain.tab-devices",
970
+ "a page on a tab of its own gets no camera, microphone, location or full screen, even with the browser's permission and a click",
971
+ async ({ page, browserName }) => {
972
+ const location = await host.locate(await host.shell("tab-devices"));
973
+ // The browser's permission given (a person who said yes before): only the page's own
974
+ // policy may refuse. An engine Playwright can't grant a name to asks, and is refused.
975
+ const context = page.context();
976
+ for (const name of ["geolocation", "camera", "microphone"]) {
977
+ await context.grantPermissions([name], { origin: location.origin }).catch(() => {});
978
+ }
979
+ await context.setGeolocation({ latitude: 48.8566, longitude: 2.3522 });
980
+ const warnings: string[] = [];
981
+ page.on("console", (message) => {
982
+ if (/permissions.policy/iu.test(message.text())) {
983
+ warnings.push(message.text());
984
+ }
985
+ });
986
+ const answer = await page.goto(location.url);
987
+ expect(answer?.status()).toBe(200);
988
+ await page.evaluate(() => {
989
+ const button = document.createElement("button");
990
+ button.id = "porthole-probe-devices";
991
+ button.textContent = "share";
992
+ button.addEventListener("click", () => {
993
+ // Full screen first: it takes the click's activation.
994
+ const element = document.documentElement;
995
+ const fullscreen =
996
+ typeof element.requestFullscreen === "function"
997
+ ? element.requestFullscreen().then(
998
+ () => "entered",
999
+ () => "rejected",
1000
+ )
1001
+ : Promise.resolve("absent");
1002
+ const media =
1003
+ navigator.mediaDevices === undefined
1004
+ ? Promise.resolve("absent")
1005
+ : navigator.mediaDevices.getUserMedia({ video: true, audio: true }).then(
1006
+ (stream) => {
1007
+ stream.getTracks().forEach((track) => track.stop());
1008
+ return "granted";
1009
+ },
1010
+ (error: unknown) =>
1011
+ `rejected ${error instanceof Error ? error.name : String(error)}`,
1012
+ );
1013
+ const position = new Promise<string>((resolve) => {
1014
+ navigator.geolocation.getCurrentPosition(
1015
+ () => resolve("granted"),
1016
+ (error) => resolve(`denied ${error.code}`),
1017
+ { timeout: 3_000 },
1018
+ );
1019
+ });
1020
+ void Promise.all([fullscreen, media, position]).then(([screen, devices, place]) => {
1021
+ if (document.fullscreenElement !== null) {
1022
+ void document.exitFullscreen();
1023
+ }
1024
+ document.body.dataset.devices = JSON.stringify({
1025
+ fullscreen: screen,
1026
+ media: devices,
1027
+ location: place,
1028
+ });
1029
+ });
1030
+ });
1031
+ document.body.append(button);
1032
+ });
1033
+ await press(page, "#porthole-probe-devices");
1034
+ await expect
1035
+ .poll(() => page.evaluate(() => document.body.dataset.devices ?? ""), { timeout: 6_000 })
1036
+ .not.toBe("");
1037
+ const said = JSON.parse(
1038
+ await page.evaluate(() => document.body.dataset.devices ?? "{}"),
1039
+ ) as Record<string, string>;
1040
+ expect(said.location, "location").toBe("denied 1");
1041
+ // No stream, however it is refused: a machine without a camera says NotFoundError even
1042
+ // where the policy would refuse (measured: Chromium, the header alone).
1043
+ expect(said.media, "camera and microphone").not.toBe("granted");
1044
+ expect(["rejected", "absent"], "full screen").toContain(said.fullscreen);
1045
+ if (warnings.length > 0) {
1046
+ info?.annotations.push({
1047
+ type: "measured",
1048
+ description: `${browserName}: ${warnings.slice(0, 3).join(" | ")}`,
1049
+ });
1050
+ }
1051
+ },
1052
+ );
1053
+
1054
+ define(
1055
+ "served.domain.tab-prompts",
1056
+ "a page on a tab of its own can't ask for a passkey, a payment (Apple Pay too) or a share, or put a video in full screen, even after a click",
1057
+ async ({ page }) => {
1058
+ // Each where the engine has it, refused at once (a prompt would wait for the person, up
1059
+ // to the request's own timeout). A payment method's address is fetched by the browser,
1060
+ // outside the CSP: the canary must hear nothing.
1061
+ await onTab(page, "tab-prompts");
1062
+ const canary = await host.canary("tab-payment");
1063
+ await page.evaluate((payTo) => {
1064
+ const button = document.createElement("button");
1065
+ button.id = "porthole-probe-prompts";
1066
+ button.textContent = "pay";
1067
+ const timed = (start: () => Promise<unknown> | undefined): Promise<string> => {
1068
+ const begun = performance.now();
1069
+ let asked: Promise<unknown> | undefined;
1070
+ try {
1071
+ asked = start();
1072
+ } catch (error) {
1073
+ return Promise.resolve(
1074
+ `refused ${error instanceof Error ? error.name : "error"} at once`,
1075
+ );
1076
+ }
1077
+ if (asked === undefined) {
1078
+ return Promise.resolve("absent");
1079
+ }
1080
+ return asked.then(
1081
+ () => "granted",
1082
+ (error: unknown) =>
1083
+ `refused ${error instanceof Error ? error.name : "error"}${performance.now() - begun < 1_500 ? " at once" : " later"}`,
1084
+ );
1085
+ };
1086
+ const challenge = new Uint8Array(32);
1087
+ button.addEventListener("click", () => {
1088
+ const passkey = timed(() =>
1089
+ navigator.credentials?.create({
1090
+ publicKey: {
1091
+ challenge,
1092
+ rp: { name: "Probe" },
1093
+ user: { id: challenge, name: "probe", displayName: "Probe" },
1094
+ pubKeyCredParams: [{ type: "public-key", alg: -7 }],
1095
+ timeout: 6_000,
1096
+ },
1097
+ }),
1098
+ );
1099
+ const payment = timed(() =>
1100
+ typeof PaymentRequest === "function"
1101
+ ? new PaymentRequest([{ supportedMethods: `${payTo}?d=secret` }], {
1102
+ total: { label: "Probe", amount: { currency: "USD", value: "1.00" } },
1103
+ }).show()
1104
+ : undefined,
1105
+ );
1106
+ const share = timed(() =>
1107
+ typeof navigator.share === "function"
1108
+ ? navigator.share({ title: "Probe", url: `${payTo}?via=share` })
1109
+ : undefined,
1110
+ );
1111
+ // WebKit's Apple Pay sheet, where it has one: a session begun from a click.
1112
+ const ApplePay = (
1113
+ window as unknown as {
1114
+ ApplePaySession?: new (
1115
+ version: number,
1116
+ request: object,
1117
+ ) => EventTarget & {
1118
+ begin(): void;
1119
+ };
1120
+ }
1121
+ ).ApplePaySession;
1122
+ const applePay = timed(() => {
1123
+ if (ApplePay === undefined) {
1124
+ return undefined;
1125
+ }
1126
+ const session = new ApplePay(3, {
1127
+ countryCode: "US",
1128
+ currencyCode: "USD",
1129
+ supportedNetworks: ["visa"],
1130
+ merchantCapabilities: ["supports3DS"],
1131
+ total: { label: "Probe", amount: "1.00" },
1132
+ });
1133
+ return new Promise((resolve, reject) => {
1134
+ session.addEventListener("cancel", () =>
1135
+ reject(new DOMException("cancelled", "AbortError")),
1136
+ );
1137
+ session.begin();
1138
+ setTimeout(() => resolve("begun"), 1_000);
1139
+ });
1140
+ });
1141
+ const video = document.createElement("video");
1142
+ document.body.append(video);
1143
+ const enter = (video as unknown as { webkitEnterFullscreen?: () => void })
1144
+ .webkitEnterFullscreen;
1145
+ let videoFullscreen = "absent";
1146
+ if (typeof enter === "function") {
1147
+ try {
1148
+ enter.call(video);
1149
+ videoFullscreen = "called";
1150
+ } catch (error) {
1151
+ videoFullscreen = `refused ${error instanceof Error ? error.name : "error"}`;
1152
+ }
1153
+ }
1154
+ void Promise.all([passkey, payment, share, applePay]).then(
1155
+ ([key, pay, sent, apple]) => {
1156
+ document.body.dataset.prompts = JSON.stringify({
1157
+ passkey: key,
1158
+ payment: pay,
1159
+ share: sent,
1160
+ applePay: apple,
1161
+ video: videoFullscreen,
1162
+ shown:
1163
+ (video as unknown as { webkitDisplayingFullscreen?: boolean })
1164
+ .webkitDisplayingFullscreen === true,
1165
+ });
1166
+ },
1167
+ );
1168
+ });
1169
+ document.body.append(button);
1170
+ }, canary);
1171
+ await press(page, "#porthole-probe-prompts");
1172
+ await expect
1173
+ .poll(() => page.evaluate(() => document.body.dataset.prompts ?? ""), {
1174
+ timeout: 10_000,
1175
+ })
1176
+ .not.toBe("");
1177
+ const said = JSON.parse(
1178
+ await page.evaluate(() => document.body.dataset.prompts ?? "{}"),
1179
+ ) as Record<string, string | boolean>;
1180
+ const atOnce = (value: unknown) =>
1181
+ value === "absent" || (typeof value === "string" && /^refused \w+ at once$/u.test(value));
1182
+ expect(atOnce(said.passkey), `a passkey: ${String(said.passkey)}`).toBe(true);
1183
+ expect(atOnce(said.payment), `a payment: ${String(said.payment)}`).toBe(true);
1184
+ expect(atOnce(said.share), `a share: ${String(said.share)}`).toBe(true);
1185
+ expect(atOnce(said.applePay), `Apple Pay: ${String(said.applePay)}`).toBe(true);
1186
+ expect(
1187
+ said.video === "absent" || String(said.video).startsWith("refused"),
1188
+ `a video's full screen: ${String(said.video)}`,
1189
+ ).toBe(true);
1190
+ expect(said.shown, "a video in full screen").toBe(false);
1191
+ await page.waitForTimeout(SETTLE_MS);
1192
+ expect(await host.canaryHits("tab-payment"), "the payment method's address").toBe(0);
1193
+ },
1194
+ );
1195
+
382
1196
  define(
383
1197
  "served.domain.frame-ancestors",
384
1198
  "only the host's origins may frame content",
@@ -592,11 +1406,17 @@ export function servedTests(
592
1406
  define(
593
1407
  "served.url.framed",
594
1408
  "a framed app's own requests ride on its partitioned cookie",
595
- async ({ page, browserName }) => {
596
- // Measured (P025): WebKit keeps no cookie in a cross-site frame, partitioned or not, so a
597
- // framed app's subresources are refused there; such hosts open the app on a tab.
598
- typed.fail(browserName === "webkit", "WebKit keeps no cookie in a cross-site frame");
1409
+ async ({ page }) => {
1410
+ // Where the browser keeps no cookie in a cross-site frame (P025: Playwright's WebKit on
1411
+ // Linux), a framed app's own requests are refused and such hosts open it on a tab: the
1412
+ // case must fail there. Measured by a probe of the browser's own, not by its name (P098:
1413
+ // the same WebKit on macOS keeps them).
599
1414
  const display = await host.show(page, await host.app("url-framed"));
1415
+ const scheme = new URL(display.origin).protocol === "https:" ? "https:" : "http:";
1416
+ typed.fail(
1417
+ !(await keepsFramedCookies(page, scheme)),
1418
+ "this browser keeps no cookie in a cross-site frame (measured)",
1419
+ );
600
1420
  const frame = await display.frame();
601
1421
  await expect
602
1422
  .poll(() => frame.evaluate(() => document.documentElement.dataset.app ?? null), {
@@ -605,6 +1425,70 @@ export function servedTests(
605
1425
  .toBe("ready");
606
1426
  },
607
1427
  );
1428
+
1429
+ define(
1430
+ "served.url.siblings",
1431
+ "another origin's page never rides an app's cookie: its load of the app's script is refused",
1432
+ async ({ page, browserName }) => {
1433
+ // P101: two apps framed on one host page share its cookie partition, and sibling labels
1434
+ // are same-site until the content domain is on the Public Suffix List (P047), so a tab's
1435
+ // Lax cookie goes with a sibling's requests too. The app's own load is the control.
1436
+ const load = (frame: Frame, src: string) =>
1437
+ frame.evaluate(
1438
+ (url) =>
1439
+ new Promise<string>((resolve) => {
1440
+ const script = document.createElement("script");
1441
+ script.addEventListener("load", () => resolve("load"));
1442
+ script.addEventListener("error", () => resolve("error"));
1443
+ script.src = url;
1444
+ document.head.append(script);
1445
+ setTimeout(() => resolve("timeout"), 3_000);
1446
+ }),
1447
+ src,
1448
+ );
1449
+ const ready = (frame: Frame) =>
1450
+ expect
1451
+ .poll(() => frame.evaluate(() => document.documentElement.dataset.app ?? null), {
1452
+ timeout: 3_000,
1453
+ })
1454
+ .toBe("ready");
1455
+ const scriptOf = async (frame: Frame, origin: string): Promise<string> => {
1456
+ const src = await frame.evaluate(
1457
+ () => document.querySelector<HTMLScriptElement>("script[src]")?.src ?? "",
1458
+ );
1459
+ expect(src, "the app's page loads a script").not.toBe("");
1460
+ expect(new URL(src).origin, "from its own origin").toBe(origin);
1461
+ return src;
1462
+ };
1463
+ // Framed side by side, where the engine keeps a framed cookie (WebKit doesn't, P025).
1464
+ if (browserName !== "webkit") {
1465
+ const a = await host.show(page, await host.app("url-siblings-a"));
1466
+ const frameA = await a.frame();
1467
+ await ready(frameA);
1468
+ const script = await scriptOf(frameA, a.origin);
1469
+ expect(await load(frameA, script), "the app's own load").toBe("load");
1470
+ const b = await host.show(page, await host.app("url-siblings-b"));
1471
+ const frameB = await b.frame();
1472
+ await ready(frameB);
1473
+ expect(await load(frameB, script), "another app's frame loading it").toBe("error");
1474
+ }
1475
+ // Each on a tab of its own, in one browser.
1476
+ const c = await host.locate(await host.app("url-siblings-c"));
1477
+ const d = await host.locate(await host.app("url-siblings-d"));
1478
+ const tab = await page.context().newPage();
1479
+ try {
1480
+ await tab.goto(c.url);
1481
+ await ready(tab.mainFrame());
1482
+ const script = await scriptOf(tab.mainFrame(), c.origin);
1483
+ expect(await load(tab.mainFrame(), script), "the app's own load").toBe("load");
1484
+ await tab.goto(d.url);
1485
+ await ready(tab.mainFrame());
1486
+ expect(await load(tab.mainFrame(), script), "another app's tab loading it").toBe("error");
1487
+ } finally {
1488
+ await tab.close();
1489
+ }
1490
+ },
1491
+ );
608
1492
  }
609
1493
  return tests;
610
1494
  }