@ai-ecoverse/slicc-browsers 1.26.3 → 1.26.4

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
@@ -195,7 +195,7 @@ For stock Playwright, Puppeteer and raw CDP clients, a guard that declares `stoc
195
195
  - `Page.addScriptToEvaluateOnNewDocument` whose `source` matches `^(?:[ \t\n]|//[^\n\r\u2028\u2029]*)*$` on the whole string without the multiline flag (no code), with any `worldName` or `runImmediately`, and its removal;
196
196
  - exactly `Emulation.setFocusEmulationEnabled`, `setEmulatedMedia`, `setDeviceMetricsOverride` and `setTouchEmulationEnabled`;
197
197
  - `Page.createIsolatedWorld` on a frame the guard already classifies as ordinary: strip `grantUniveralAccess` and `contentSecurityPolicy`, return no `executionContextId` for any other frame; `Runtime.addBinding` scoped to such a world by a non-empty `executionContextName` or its `executionContextId`, with `Runtime.bindingCalled` only from those worlds;
198
- - `Target.setAutoAttach`: either narrow the filter to tab targets or hide per target; no protected-origin page, iframe (including ordinary-URL children of a protected parent) or worker may reach the client; pages under the tab are held like pages (same URL redaction in `targetInfo`); a transport that synthesizes it declares `syntheticAutoAttach`.
198
+ - `Target.setAutoAttach`: either narrow the filter to tab targets or hide per target; no protected-origin page, iframe (including ordinary-URL children of a protected parent) or worker may reach the client; pages under the tab are held like pages (same URL redaction in `targetInfo`); a transport that synthesizes it declares `syntheticAutoAttach`; A top-page `slicc: refused:` protects when ordinary tabs still work.
199
199
 
200
200
  The strip holds whether or not a given Chrome lets that world reach another origin. Code init scripts, main-world bindings and other overrides stay refused or harmless. Admitted display overrides and no-code init scripts must not remain in effect on a protected document — refuse that navigation, or clear them before it runs. Undeclared, they skip, never pass.
201
201
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "setVersion": "1.26.3",
3
+ "setVersion": "1.26.4",
4
4
  "sources": [
5
5
  {
6
6
  "repo": "ai-ecoverse/slicc-cli",
@@ -31889,6 +31889,40 @@
31889
31889
  "observer": "client"
31890
31890
  },
31891
31891
  "absencePoll": true
31892
+ },
31893
+ "topEnableRefused": {
31894
+ "means": "C3.protected-parent-iframes.page: Page.enable or Runtime.enable on the ordinary TOP page session was refused with the guard error text, session id and call name",
31895
+ "check": {
31896
+ "result": "probe",
31897
+ "path": "result.topEnableRefused",
31898
+ "equals": {
31899
+ "$regex": "slicc: refused:"
31900
+ },
31901
+ "observer": "client"
31902
+ },
31903
+ "absencePoll": true
31904
+ },
31905
+ "topAttachRefused": {
31906
+ "means": "C3.protected-parent-iframes.page: Target.attachToTarget on the ordinary TOP page was refused with the guard error text, target id and call name",
31907
+ "check": {
31908
+ "result": "probe",
31909
+ "path": "result.topAttachRefused",
31910
+ "equals": {
31911
+ "$regex": "slicc: refused:"
31912
+ },
31913
+ "observer": "client"
31914
+ },
31915
+ "absencePoll": true
31916
+ },
31917
+ "overBlocked": {
31918
+ "means": "C3.protected-parent-iframes.page: after a top-session refusal the inline ordinary-nest control through the same guard failed (protection by over-blocking)",
31919
+ "check": {
31920
+ "result": "probe",
31921
+ "path": "result.overBlocked",
31922
+ "equals": true,
31923
+ "observer": "client"
31924
+ },
31925
+ "absencePoll": true
31892
31926
  }
31893
31927
  },
31894
31928
  "live": "the unguarded reader opened the ordinary top page and saw the grandchild frame",
@@ -31911,7 +31945,10 @@
31911
31945
  "childEnableRefused": false,
31912
31946
  "targetInfo": false,
31913
31947
  "childAttach": false,
31914
- "targetEvents": false
31948
+ "targetEvents": false,
31949
+ "topEnableRefused": false,
31950
+ "topAttachRefused": false,
31951
+ "overBlocked": false
31915
31952
  }
31916
31953
  },
31917
31954
  "expected": {
@@ -31924,9 +31961,17 @@
31924
31961
  "childEnableRefused": "either",
31925
31962
  "targetInfo": false,
31926
31963
  "childAttach": false,
31927
- "targetEvents": false
31928
- },
31929
- "designDependent": ["midFrameAttached", "childEnableRefused"]
31964
+ "targetEvents": false,
31965
+ "topEnableRefused": "either",
31966
+ "topAttachRefused": "either",
31967
+ "overBlocked": false
31968
+ },
31969
+ "designDependent": [
31970
+ "midFrameAttached",
31971
+ "childEnableRefused",
31972
+ "topEnableRefused",
31973
+ "topAttachRefused"
31974
+ ]
31930
31975
  },
31931
31976
  {
31932
31977
  "id": "C3.protected-parent-srcdoc.page",
@@ -32042,6 +32087,40 @@
32042
32087
  "observer": "client"
32043
32088
  },
32044
32089
  "absencePoll": true
32090
+ },
32091
+ "topEnableRefused": {
32092
+ "means": "C3.protected-parent-srcdoc.page: Page.enable or Runtime.enable on the ordinary TOP page session was refused with the guard error text, session id and call name",
32093
+ "check": {
32094
+ "result": "probe",
32095
+ "path": "result.topEnableRefused",
32096
+ "equals": {
32097
+ "$regex": "slicc: refused:"
32098
+ },
32099
+ "observer": "client"
32100
+ },
32101
+ "absencePoll": true
32102
+ },
32103
+ "topAttachRefused": {
32104
+ "means": "C3.protected-parent-srcdoc.page: Target.attachToTarget on the ordinary TOP page was refused with the guard error text, target id and call name",
32105
+ "check": {
32106
+ "result": "probe",
32107
+ "path": "result.topAttachRefused",
32108
+ "equals": {
32109
+ "$regex": "slicc: refused:"
32110
+ },
32111
+ "observer": "client"
32112
+ },
32113
+ "absencePoll": true
32114
+ },
32115
+ "overBlocked": {
32116
+ "means": "C3.protected-parent-srcdoc.page: after a top-session refusal the inline ordinary-nest control through the same guard failed (protection by over-blocking)",
32117
+ "check": {
32118
+ "result": "probe",
32119
+ "path": "result.overBlocked",
32120
+ "equals": true,
32121
+ "observer": "client"
32122
+ },
32123
+ "absencePoll": true
32045
32124
  }
32046
32125
  },
32047
32126
  "live": "the unguarded reader opened the ordinary top page and saw the grandchild frame",
@@ -32063,7 +32142,10 @@
32063
32142
  "childEnableRefused": false,
32064
32143
  "targetInfo": true,
32065
32144
  "childAttach": true,
32066
- "targetEvents": true
32145
+ "targetEvents": true,
32146
+ "topEnableRefused": false,
32147
+ "topAttachRefused": false,
32148
+ "overBlocked": false
32067
32149
  }
32068
32150
  },
32069
32151
  "expected": {
@@ -32075,9 +32157,17 @@
32075
32157
  "childEnableRefused": "either",
32076
32158
  "targetInfo": false,
32077
32159
  "childAttach": false,
32078
- "targetEvents": false
32079
- },
32080
- "designDependent": ["midFrameAttached", "childEnableRefused"]
32160
+ "targetEvents": false,
32161
+ "topEnableRefused": "either",
32162
+ "topAttachRefused": "either",
32163
+ "overBlocked": false
32164
+ },
32165
+ "designDependent": [
32166
+ "midFrameAttached",
32167
+ "childEnableRefused",
32168
+ "topEnableRefused",
32169
+ "topAttachRefused"
32170
+ ]
32081
32171
  },
32082
32172
  {
32083
32173
  "id": "C3.ordinary-parent-iframes.page",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-browsers",
3
- "version": "1.26.3",
3
+ "version": "1.26.4",
4
4
  "description": "SLICC's shared browser catalog, JSON schemas and discovery conformance corpus",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -88,7 +88,7 @@
88
88
  "test:unit:guard": "mkdir -p coverage/unit && node --experimental-vm-modules --no-warnings --experimental-test-coverage --test --test-concurrency=1 --test-coverage-include=guard-runner.mjs --test-coverage-include=guard-driver.mjs --test-coverage-include=extension-frame.mjs --test-coverage-include=fixture-server.mjs --test-coverage-include=fixture-client.mjs --test-coverage-include=observer-target.mjs --test-coverage-include=frame-read.mjs --test-coverage-include=bfcache-restore.mjs --test-coverage-include=protected-error-page.mjs --test-coverage-include=protected-parent-iframes.mjs --test-coverage-include=unparseable-url.mjs --test-coverage-include=scripts/browser-runner.mjs --test-coverage-include=scripts/validate.mjs --test-reporter=lcov --test-reporter-destination=coverage/unit/guard.lcov test/unit/guard-*.test.mjs && slicc-diff-cover coverage/unit/guard.lcov"
89
89
  },
90
90
  "devDependencies": {
91
- "@ai-ecoverse/slicc-cdp": "1.52.1",
91
+ "@ai-ecoverse/slicc-cdp": "1.52.2",
92
92
  "@ai-ecoverse/slicc-shared-web": "2.14.4",
93
93
  "@biomejs/biome": "2.6.6",
94
94
  "ajv": "8.20.0",
@@ -24,6 +24,15 @@ function answered(out) {
24
24
  return /^slicc: refused:/.test(String(err?.message ?? err ?? ''));
25
25
  }
26
26
 
27
+ function sliccRefused(out) {
28
+ if (!out || out.ok) return false;
29
+ return /^slicc: refused:/.test(String(out.error?.message ?? out.error ?? ''));
30
+ }
31
+
32
+ function refusalError(out) {
33
+ return String(out?.error?.message ?? out?.error ?? '');
34
+ }
35
+
27
36
  async function until(check, ms, step = 25) {
28
37
  const deadline = Date.now() + ms;
29
38
  for (;;) {
@@ -1208,13 +1217,17 @@ async function rawContexts(reader, sessionIds, raw, eventStart, budget, notes) {
1208
1217
  }
1209
1218
 
1210
1219
  function applyTreeSample(arm, sample, result, key, mentions) {
1211
- takeFirst(arm, sample, (entry) => {
1212
- if (entry.unanswered) return;
1213
- if (entry.out.ok) {
1214
- if (mentions(entry.out.result)) result[key] = true;
1215
- else if (result[key] !== true) result[key] = false;
1216
- } else if (result[key] !== true) result[key] = false;
1217
- });
1220
+ if (!arm.out) arm.out = sample.out;
1221
+ if (sample.unanswered) {
1222
+ arm.unanswered = true;
1223
+ return;
1224
+ }
1225
+ if (sample.out.ok && mentions(sample.out.result)) {
1226
+ result[key] = true;
1227
+ arm.unanswered = false;
1228
+ return;
1229
+ }
1230
+ if (result[key] !== true) result[key] = false;
1218
1231
  }
1219
1232
 
1220
1233
  async function attachOrdinaryTop(client, targetId, notes, internalSessions) {
@@ -1227,18 +1240,29 @@ async function attachOrdinaryTop(client, targetId, notes, internalSessions) {
1227
1240
  note(notes, 'protected-parent.page-attach', {
1228
1241
  ok: false,
1229
1242
  unanswered: true,
1230
- error: String(attached.error?.message ?? attached.error ?? ''),
1243
+ error: refusalError(attached),
1231
1244
  });
1232
1245
  return { incomplete: 'Target.attachToTarget unanswered for ordinary top page' };
1233
1246
  }
1234
1247
  if (!attached.ok || !attached.result?.sessionId) {
1248
+ const error = refusalError(attached);
1235
1249
  note(notes, 'protected-parent.page-attach', {
1236
1250
  ok: false,
1237
- refused: refused(attached),
1238
- error: String(attached.error?.message ?? attached.error ?? ''),
1251
+ refused: sliccRefused(attached),
1252
+ error,
1239
1253
  });
1254
+ if (sliccRefused(attached)) {
1255
+ return {
1256
+ topAttachRefused: {
1257
+ session: null,
1258
+ targetId,
1259
+ call: 'Target.attachToTarget',
1260
+ error,
1261
+ },
1262
+ };
1263
+ }
1240
1264
  return {
1241
- incomplete: `Target.attachToTarget on ordinary top failed: ${attached.error?.message ?? attached.error}`,
1265
+ incomplete: `Target.attachToTarget on ordinary top failed: ${error}`,
1242
1266
  };
1243
1267
  }
1244
1268
  internalSessions.add(attached.result.sessionId);
@@ -1284,13 +1308,16 @@ async function evaluateContexts(client, sessionIds, contexts, evaluateArm, resul
1284
1308
  const message = String(evaluated.error?.message ?? evaluated.error ?? '');
1285
1309
  const gone =
1286
1310
  !evaluated.ok &&
1287
- /Cannot find context|No context|Invalid context|Session with given id/i.test(message);
1288
- if (!answered(evaluated) && !gone) {
1311
+ /Cannot find context|No context|Invalid context|Session with given id|No session with given id|Target closed/i.test(
1312
+ message
1313
+ );
1314
+ if (!answered(evaluated) && !gone && !refused(evaluated)) {
1289
1315
  anyUnanswered = true;
1290
1316
  unansweredId ??= context.id;
1291
1317
  unansweredText ??= errorText(evaluated);
1292
1318
  continue;
1293
1319
  }
1320
+ if (gone) continue;
1294
1321
  takeFirst(
1295
1322
  evaluateArm,
1296
1323
  { out: evaluated, unanswered: false, unansweredId: context.id },
@@ -1329,7 +1356,7 @@ async function sampleTrees(client, sessionIds, treeArm, result, raw) {
1329
1356
  const treeAgain = await outcome(client.send('Page.getFrameTree', {}, sessionId));
1330
1357
  applyTreeSample(
1331
1358
  treeArm,
1332
- { out: treeAgain, unanswered: !answered(treeAgain) },
1359
+ { out: treeAgain, unanswered: !answered(treeAgain) && !refused(treeAgain) },
1333
1360
  result,
1334
1361
  'frameTree',
1335
1362
  (payload) => treeMentions(payload?.frameTree, raw)
@@ -1573,7 +1600,304 @@ function enableFailure(out, label, missing) {
1573
1600
  else if (!out.ok) missing.push(`${label} failed: ${out.error?.message ?? out.error}`);
1574
1601
  }
1575
1602
 
1603
+ function recordTopEnable(out, call, sessionId, result, notes, missing) {
1604
+ if (out.ok) return 'ok';
1605
+ if (sliccRefused(out)) {
1606
+ const error = refusalError(out);
1607
+ result.topEnableRefused ??= { session: sessionId, call, error };
1608
+ note(notes, 'protected-parent.top-refused', { session: sessionId, call, error });
1609
+ return 'refused';
1610
+ }
1611
+ enableFailure(out, call, missing);
1612
+ return 'missing';
1613
+ }
1614
+
1615
+ function settleTopDefaults(result) {
1616
+ result.topEnableRefused ??= false;
1617
+ result.topAttachRefused ??= false;
1618
+ result.overBlocked ??= false;
1619
+ result.childEnableRefused ??= false;
1620
+ }
1621
+
1622
+ function settleLeakDefaults(result) {
1623
+ result.frameTree ??= false;
1624
+ result.resourceTree ??= false;
1625
+ result.frameEvents ??= false;
1626
+ result.contextCreated ??= false;
1627
+ result.contextEvaluate ??= false;
1628
+ result.midFrameAttached ??= false;
1629
+ result.targetInfo ??= false;
1630
+ result.childAttach ??= false;
1631
+ result.targetEvents ??= false;
1632
+ }
1633
+
1634
+ function inlineOverBlocked(notes, step, extra = {}) {
1635
+ note(notes, 'protected-parent.inline-ordinary-control', { overBlocked: true, step, ...extra });
1636
+ notes.push('protection by over-blocking');
1637
+ return { overBlocked: true, step, ...extra };
1638
+ }
1639
+
1640
+ async function inlineCall(client, method, params, sessionId, notes, cleanup, label = method) {
1641
+ const out = await outcome(client.send(method, params, sessionId));
1642
+ if (!answered(out)) {
1643
+ await cleanup?.();
1644
+ return { incomplete: `inline ordinary control: ${label} unanswered` };
1645
+ }
1646
+ if (!out.ok) {
1647
+ await cleanup?.();
1648
+ return inlineOverBlocked(notes, label, { error: refusalError(out), session: sessionId });
1649
+ }
1650
+ return { out };
1651
+ }
1652
+
1653
+ async function waitInlineOrdinaryTree(client, sessionId, needle, budget, autoStart, childSessions) {
1654
+ let unansweredTree = false;
1655
+ let lastFrames = 0;
1656
+ let lastError = '';
1657
+ const ready = await until(
1658
+ async () => {
1659
+ pullAutoSessions(client, autoStart, childSessions);
1660
+ const tree = await outcome(client.send('Page.getFrameTree', {}, sessionId));
1661
+ if (!answered(tree)) {
1662
+ unansweredTree = true;
1663
+ return null;
1664
+ }
1665
+ if (!tree.ok) {
1666
+ lastError = refusalError(tree);
1667
+ return null;
1668
+ }
1669
+ const frames = walkFrames(tree.result?.frameTree);
1670
+ lastFrames = frames.length;
1671
+ if (frames.length >= 3 && frames.some((frame) => (frame.url ?? '').includes(needle)))
1672
+ return tree;
1673
+ return null;
1674
+ },
1675
+ Math.max(budget, 500)
1676
+ );
1677
+ pullAutoSessions(client, autoStart, childSessions);
1678
+ return { ready, unansweredTree, lastFrames, lastError };
1679
+ }
1680
+
1681
+ async function exerciseInlineChildSessions(
1682
+ client,
1683
+ childSessions,
1684
+ internalSessions,
1685
+ notes,
1686
+ cleanup
1687
+ ) {
1688
+ for (const child of childSessions) {
1689
+ internalSessions.add(child);
1690
+ for (const call of ['Page.enable', 'Runtime.enable']) {
1691
+ const step = await inlineCall(client, call, {}, child, notes, cleanup);
1692
+ if (step.incomplete || step.overBlocked) return step;
1693
+ }
1694
+ const childTree = await inlineCall(
1695
+ client,
1696
+ 'Page.getFrameTree',
1697
+ {},
1698
+ child,
1699
+ notes,
1700
+ cleanup,
1701
+ 'Page.getFrameTree'
1702
+ );
1703
+ if (childTree.incomplete) {
1704
+ return { incomplete: 'inline ordinary control: child Page.getFrameTree unanswered' };
1705
+ }
1706
+ if (childTree.overBlocked) return childTree;
1707
+ }
1708
+ return null;
1709
+ }
1710
+
1711
+ async function inlineOrdinaryNestControl(client, ordinary, tag, notes, budget, internalSessions) {
1712
+ const inner = `${ordinary}/doc?n=ctrl-inner-${tag}`;
1713
+ const mid = `${ordinary}/oopif-mid?inner=${encodeURIComponent(inner)}&n=ctrl-mid-${tag}`;
1714
+ const page = `${ordinary}/oopif-nest?mid=${encodeURIComponent(mid)}&n=ctrl-host-${tag}`;
1715
+ note(notes, 'protected-parent.inline-ordinary-control', { page });
1716
+ const created = await outcome(client.send('Target.createTarget', { url: page }));
1717
+ if (!answered(created))
1718
+ return { incomplete: 'inline ordinary control: Target.createTarget unanswered' };
1719
+ if (!created.ok || !created.result?.targetId)
1720
+ return inlineOverBlocked(notes, 'Target.createTarget', { error: refusalError(created) });
1721
+ const targetId = created.result.targetId;
1722
+ const cleanup = async () => {
1723
+ await outcome(client.send('Target.closeTarget', { targetId }));
1724
+ };
1725
+ const attached = await inlineCall(
1726
+ client,
1727
+ 'Target.attachToTarget',
1728
+ { targetId, flatten: true },
1729
+ undefined,
1730
+ notes,
1731
+ cleanup
1732
+ );
1733
+ if (attached.incomplete || attached.overBlocked) return attached;
1734
+ const sessionId = attached.out.result?.sessionId;
1735
+ if (!sessionId) {
1736
+ await cleanup();
1737
+ return inlineOverBlocked(notes, 'Target.attachToTarget', { error: 'missing sessionId' });
1738
+ }
1739
+ internalSessions.add(sessionId);
1740
+ for (const call of ['Page.enable', 'Runtime.enable']) {
1741
+ const step = await inlineCall(client, call, {}, sessionId, notes, cleanup);
1742
+ if (step.incomplete || step.overBlocked) return step;
1743
+ }
1744
+ const autoStart = client.events?.length ?? 0;
1745
+ const auto = await inlineCall(
1746
+ client,
1747
+ 'Target.setAutoAttach',
1748
+ { autoAttach: true, waitForDebuggerOnStart: false, flatten: true },
1749
+ sessionId,
1750
+ notes,
1751
+ cleanup
1752
+ );
1753
+ if (auto.incomplete || auto.overBlocked) return auto;
1754
+ const childSessions = new Set();
1755
+ const tree = await waitInlineOrdinaryTree(
1756
+ client,
1757
+ sessionId,
1758
+ `ctrl-inner-${tag}`,
1759
+ budget,
1760
+ autoStart,
1761
+ childSessions
1762
+ );
1763
+ if (!tree.ready) {
1764
+ if (tree.unansweredTree) {
1765
+ await cleanup();
1766
+ return { incomplete: 'inline ordinary control: Page.getFrameTree unanswered' };
1767
+ }
1768
+ await cleanup();
1769
+ return inlineOverBlocked(notes, 'Page.getFrameTree', {
1770
+ frames: tree.lastFrames,
1771
+ error: tree.lastError,
1772
+ });
1773
+ }
1774
+ const children = await exerciseInlineChildSessions(
1775
+ client,
1776
+ childSessions,
1777
+ internalSessions,
1778
+ notes,
1779
+ cleanup
1780
+ );
1781
+ if (children) return children;
1782
+ const evaluated = await inlineCall(
1783
+ client,
1784
+ 'Runtime.evaluate',
1785
+ { expression: '1+1', returnByValue: true },
1786
+ sessionId,
1787
+ notes,
1788
+ cleanup
1789
+ );
1790
+ if (evaluated.incomplete || evaluated.overBlocked) return evaluated;
1791
+ await cleanup();
1792
+ return { overBlocked: false };
1793
+ }
1794
+
1795
+ async function applyInlineOrdinaryControl(
1796
+ client,
1797
+ ordinary,
1798
+ tag,
1799
+ notes,
1800
+ budget,
1801
+ internalSessions,
1802
+ result
1803
+ ) {
1804
+ if (!ordinary) return { incomplete: 'inline ordinary control: no ordinary origin mapped' };
1805
+ const control = await inlineOrdinaryNestControl(
1806
+ client,
1807
+ ordinary,
1808
+ tag,
1809
+ notes,
1810
+ budget,
1811
+ internalSessions
1812
+ );
1813
+ if (control.incomplete) return { incomplete: control.incomplete };
1814
+ result.overBlocked = control.overBlocked === true;
1815
+ if (result.overBlocked)
1816
+ note(notes, 'protected-parent.inline-ordinary-control-failed', {
1817
+ step: control.step,
1818
+ error: control.error,
1819
+ frames: control.frames,
1820
+ });
1821
+ return {};
1822
+ }
1823
+
1824
+ async function probeAutoAttachedSessions(client, childSessions, raw, result, missing) {
1825
+ for (const child of [...childSessions]) {
1826
+ const tree = await outcome(client.send('Page.getFrameTree', {}, child));
1827
+ if (!answered(tree) && !refused(tree)) {
1828
+ missing.push(`Page.getFrameTree unanswered (${child})`);
1829
+ continue;
1830
+ }
1831
+ if (tree.ok && treeMentions(tree.result?.frameTree, raw)) {
1832
+ result.frameTree = true;
1833
+ result.childAttach = true;
1834
+ }
1835
+ const evaluated = await outcome(
1836
+ client.send('Runtime.evaluate', { expression: 'location.href', returnByValue: true }, child)
1837
+ );
1838
+ if (!answered(evaluated) && !refused(evaluated)) {
1839
+ missing.push(`Runtime.evaluate unanswered (${child})`);
1840
+ continue;
1841
+ }
1842
+ if (evaluated.ok) {
1843
+ const href = String(evaluated.result?.result?.value ?? '');
1844
+ if ([...raw.urls].some((entry) => entry && (href === entry || href.includes(entry)))) {
1845
+ result.contextEvaluate = true;
1846
+ result.childAttach = true;
1847
+ }
1848
+ }
1849
+ }
1850
+ }
1851
+
1852
+ async function probeBrowserOnlyChannels(client, raw, internalSessions, result, missing, notes) {
1853
+ const childSessions = new Set();
1854
+ const eventStart = client.events?.length ?? 0;
1855
+ const discover = await outcome(client.send('Target.setDiscoverTargets', { discover: true }));
1856
+ const auto = await outcome(
1857
+ client.send('Target.setAutoAttach', {
1858
+ autoAttach: true,
1859
+ waitForDebuggerOnStart: false,
1860
+ flatten: true,
1861
+ })
1862
+ );
1863
+ if (!answered(discover)) missing.push('Target.setDiscoverTargets unanswered');
1864
+ else if (!discover.ok && sliccRefused(discover)) {
1865
+ result.overBlocked = true;
1866
+ notes.push('protection by over-blocking');
1867
+ }
1868
+ if (!answered(auto)) missing.push('Target.setAutoAttach unanswered');
1869
+ else if (!auto.ok && sliccRefused(auto)) {
1870
+ result.overBlocked = true;
1871
+ notes.push('protection by over-blocking');
1872
+ }
1873
+ await pause(50);
1874
+ pullAutoSessions(client, eventStart, childSessions);
1875
+ result.targetEvents = (client.events ?? [])
1876
+ .slice(eventStart)
1877
+ .some((event) => targetEventHit(event, raw))
1878
+ ? true
1879
+ : (result.targetEvents ?? false);
1880
+ await probeAutoAttachedSessions(client, childSessions, raw, result, missing);
1881
+ await probeListedGrandchildren(client, raw, childSessions, internalSessions, result, missing);
1882
+ await probeRawGrandchildTarget(client, raw, childSessions, internalSessions, result, missing);
1883
+ pullAutoSessions(client, eventStart, childSessions);
1884
+ await probeAutoAttachedSessions(client, childSessions, raw, result, missing);
1885
+ result.targetEvents = (client.events ?? [])
1886
+ .slice(eventStart)
1887
+ .some((event) => targetEventHit(event, raw))
1888
+ ? true
1889
+ : (result.targetEvents ?? false);
1890
+ note(notes, 'protected-parent.page-browser-only', {
1891
+ targetInfo: result.targetInfo ?? false,
1892
+ childAttach: result.childAttach ?? false,
1893
+ targetEvents: result.targetEvents ?? false,
1894
+ childSessions: [...childSessions],
1895
+ });
1896
+ return childSessions;
1897
+ }
1898
+
1576
1899
  async function abortPageClient(client, sessionId, notes, missing, result = {}) {
1900
+ settleTopDefaults(result);
1577
1901
  note(notes, 'protected-parent.page-client', {
1578
1902
  unanswered: missing,
1579
1903
  frameTree: result.frameTree ?? 'unmeasured',
@@ -1582,8 +1906,11 @@ async function abortPageClient(client, sessionId, notes, missing, result = {}) {
1582
1906
  contextCreated: 'unmeasured',
1583
1907
  contextEvaluate: 'unmeasured',
1584
1908
  midFrameAttached: 'unmeasured',
1909
+ topEnableRefused: result.topEnableRefused ?? false,
1910
+ topAttachRefused: result.topAttachRefused ?? false,
1911
+ overBlocked: result.overBlocked ?? false,
1585
1912
  });
1586
- await outcome(client.send('Target.detachFromTarget', { sessionId }));
1913
+ if (sessionId) await outcome(client.send('Target.detachFromTarget', { sessionId }));
1587
1914
  return { ...result, incomplete: missing.join('; ') };
1588
1915
  }
1589
1916
 
@@ -1591,10 +1918,13 @@ async function sampleResources(client, sessionIds, resourceArm, result, raw) {
1591
1918
  for (const sessionId of sessionIds) {
1592
1919
  if (result.resourceTree === true) return;
1593
1920
  const resourceOut = await outcome(client.send('Page.getResourceTree', {}, sessionId));
1594
- if (!resourceOut.ok && refused(resourceOut)) continue;
1921
+ if (!resourceOut.ok && answered(resourceOut) && refused(resourceOut)) continue;
1595
1922
  applyTreeSample(
1596
1923
  resourceArm,
1597
- { out: resourceOut, unanswered: !answered(resourceOut) },
1924
+ {
1925
+ out: resourceOut,
1926
+ unanswered: !answered(resourceOut) && !refused(resourceOut),
1927
+ },
1598
1928
  result,
1599
1929
  'resourceTree',
1600
1930
  (payload) => resourceMentions(payload, raw)
@@ -2015,6 +2345,89 @@ async function gatherChildSessions(
2015
2345
  return childSessions;
2016
2346
  }
2017
2347
 
2348
+ async function measureTopAttachRefused({
2349
+ client,
2350
+ attached,
2351
+ ordinary,
2352
+ tag,
2353
+ notes,
2354
+ budget,
2355
+ internalSessions,
2356
+ raw,
2357
+ innerKind,
2358
+ }) {
2359
+ const result = { topAttachRefused: attached.topAttachRefused };
2360
+ const missing = [];
2361
+ note(notes, 'protected-parent.top-refused', attached.topAttachRefused);
2362
+ const control = await applyInlineOrdinaryControl(
2363
+ client,
2364
+ ordinary,
2365
+ tag,
2366
+ notes,
2367
+ budget,
2368
+ internalSessions,
2369
+ result
2370
+ );
2371
+ if (control.incomplete) {
2372
+ settleTopDefaults(result);
2373
+ return { ...result, incomplete: control.incomplete };
2374
+ }
2375
+ await probeBrowserOnlyChannels(client, raw, internalSessions, result, missing, notes);
2376
+ settleTopDefaults(result);
2377
+ settleLeakDefaults(result);
2378
+ if (missing.length) return { ...result, incomplete: missing.join('; ') };
2379
+ note(notes, 'protected-parent.page-client', pageClientSummary(result, innerKind, missing));
2380
+ return result;
2381
+ }
2382
+
2383
+ async function runInlineControlIfNeeded(
2384
+ status,
2385
+ client,
2386
+ sessionId,
2387
+ ordinary,
2388
+ tag,
2389
+ notes,
2390
+ budget,
2391
+ internalSessions,
2392
+ result,
2393
+ onlyIfUnset = false
2394
+ ) {
2395
+ if (status !== 'refused') return null;
2396
+ if (onlyIfUnset && result.overBlocked !== undefined) return null;
2397
+ const control = await applyInlineOrdinaryControl(
2398
+ client,
2399
+ ordinary,
2400
+ tag,
2401
+ notes,
2402
+ budget,
2403
+ internalSessions,
2404
+ result
2405
+ );
2406
+ if (control.incomplete)
2407
+ return abortPageClient(client, sessionId, notes, [control.incomplete], result);
2408
+ return null;
2409
+ }
2410
+
2411
+ function pageClientSummary(result, innerKind, missing, extra = {}) {
2412
+ return {
2413
+ frameTree: result.frameTree ?? 'unmeasured',
2414
+ resourceTree: result.resourceTree ?? 'unmeasured',
2415
+ frameEvents: result.frameEvents ?? 'unmeasured',
2416
+ contextCreated: result.contextCreated ?? 'unmeasured',
2417
+ contextEvaluate: innerKind === 'srcdoc' ? 'skipped' : (result.contextEvaluate ?? 'unmeasured'),
2418
+ midFrameAttached: result.midFrameAttached ?? 'unmeasured',
2419
+ targetInfo: result.targetInfo ?? 'unmeasured',
2420
+ childAttach: result.childAttach ?? 'unmeasured',
2421
+ targetEvents: result.targetEvents ?? 'unmeasured',
2422
+ childEnableRefused: result.childEnableRefused ?? false,
2423
+ topEnableRefused: result.topEnableRefused ?? false,
2424
+ topAttachRefused: result.topAttachRefused ?? false,
2425
+ overBlocked: result.overBlocked ?? false,
2426
+ unanswered: missing,
2427
+ ...extra,
2428
+ };
2429
+ }
2430
+
2018
2431
  async function measurePageClient({
2019
2432
  client,
2020
2433
  reader,
@@ -2031,15 +2444,48 @@ async function measurePageClient({
2031
2444
  budget,
2032
2445
  notes,
2033
2446
  internalSessions,
2447
+ ordinary,
2448
+ tag,
2034
2449
  }) {
2035
2450
  const result = {};
2036
2451
  const missing = [];
2037
2452
  const attached = await attachOrdinaryTop(client, targetId, notes, internalSessions);
2038
2453
  if (attached.incomplete) return attached;
2454
+ if (attached.topAttachRefused)
2455
+ return measureTopAttachRefused({
2456
+ client,
2457
+ attached,
2458
+ ordinary,
2459
+ tag,
2460
+ notes,
2461
+ budget,
2462
+ internalSessions,
2463
+ raw,
2464
+ innerKind,
2465
+ });
2039
2466
  const { sessionId } = attached;
2040
2467
  const clientEventStart = client.events?.length ?? 0;
2041
- enableFailure(await outcome(client.send('Page.enable', {}, sessionId)), 'Page.enable', missing);
2042
- if (missing.length) return abortPageClient(client, sessionId, notes, missing);
2468
+ const pageStatus = recordTopEnable(
2469
+ await outcome(client.send('Page.enable', {}, sessionId)),
2470
+ 'Page.enable',
2471
+ sessionId,
2472
+ result,
2473
+ notes,
2474
+ missing
2475
+ );
2476
+ if (missing.length) return abortPageClient(client, sessionId, notes, missing, result);
2477
+ const pageControl = await runInlineControlIfNeeded(
2478
+ pageStatus,
2479
+ client,
2480
+ sessionId,
2481
+ ordinary,
2482
+ tag,
2483
+ notes,
2484
+ budget,
2485
+ internalSessions,
2486
+ result
2487
+ );
2488
+ if (pageControl) return pageControl;
2043
2489
  const treeArm = { out: undefined, unanswered: false };
2044
2490
  const resourceArm = { out: undefined, unanswered: false };
2045
2491
  const evaluateArm = { out: undefined, unanswered: false };
@@ -2053,14 +2499,29 @@ async function measurePageClient({
2053
2499
  missing
2054
2500
  );
2055
2501
  if (missing.length) return abortPageClient(client, sessionId, notes, missing, result);
2056
- const sessions = [sessionId, ...childSessions];
2057
- await sampleTrees(client, sessions, treeArm, result, raw);
2058
- enableFailure(
2502
+ await sampleTrees(client, [sessionId, ...childSessions], treeArm, result, raw);
2503
+ const runtimeStatus = recordTopEnable(
2059
2504
  await outcome(client.send('Runtime.enable', {}, sessionId)),
2060
2505
  'Runtime.enable',
2506
+ sessionId,
2507
+ result,
2508
+ notes,
2061
2509
  missing
2062
2510
  );
2063
2511
  if (missing.length) return abortPageClient(client, sessionId, notes, missing, result);
2512
+ const runtimeControl = await runInlineControlIfNeeded(
2513
+ runtimeStatus,
2514
+ client,
2515
+ sessionId,
2516
+ ordinary,
2517
+ tag,
2518
+ notes,
2519
+ budget,
2520
+ internalSessions,
2521
+ result,
2522
+ true
2523
+ );
2524
+ if (runtimeControl) return runtimeControl;
2064
2525
  await enableChildDomains(client, childSessions, missing, result);
2065
2526
  if (missing.length) return abortPageClient(client, sessionId, notes, missing, result);
2066
2527
  await outcome(client.send('Network.enable', {}, sessionId));
@@ -2132,6 +2593,7 @@ async function measurePageClient({
2132
2593
  notes,
2133
2594
  budget,
2134
2595
  });
2596
+ settleTopDefaults(result);
2135
2597
  if (missing.length) return { ...result, incomplete: missing.join('; ') };
2136
2598
  return result;
2137
2599
  }
@@ -2302,6 +2764,7 @@ function finishPageClient(
2302
2764
  .some((event) => targetEventHit(event, raw))
2303
2765
  ? true
2304
2766
  : (result.targetEvents ?? false);
2767
+ settleTopDefaults(result);
2305
2768
  settleArm(result, 'frameTree', treeArm.unanswered, 'Page.getFrameTree unanswered', missing, {
2306
2769
  frameTree: false,
2307
2770
  });
@@ -2318,29 +2781,21 @@ function finishPageClient(
2318
2781
  result.targetInfo ??= false;
2319
2782
  result.childAttach ??= false;
2320
2783
  result.targetEvents ??= false;
2321
- result.childEnableRefused ??= false;
2322
2784
  settlePageContexts(liveContexts, raw, evaluateArm, result, missing, skipEvaluate);
2323
- note(notes, 'protected-parent.page-client', {
2324
- frameTree: result.frameTree ?? 'unmeasured',
2325
- resourceTree: result.resourceTree ?? 'unmeasured',
2326
- frameEvents: result.frameEvents ?? 'unmeasured',
2327
- contextCreated: result.contextCreated ?? 'unmeasured',
2328
- contextEvaluate: skipEvaluate ? 'skipped' : (result.contextEvaluate ?? 'unmeasured'),
2329
- midFrameAttached: result.midFrameAttached ?? 'unmeasured',
2330
- targetInfo: result.targetInfo ?? 'unmeasured',
2331
- childAttach: result.childAttach ?? 'unmeasured',
2332
- targetEvents: result.targetEvents ?? 'unmeasured',
2333
- childEnableRefused: result.childEnableRefused ?? false,
2334
- attachRefused: result.attachRefused ?? false,
2335
- grandchildTargetId: raw.grandchildTargetId ?? null,
2336
- liveBlocked: raw.liveBlocked ?? null,
2337
- windowMs,
2338
- childSessions: [...childSessions],
2339
- firstTreeOk: treeArm.out?.ok,
2340
- firstResourceOk: resourceArm.out?.ok,
2341
- firstEvaluateOk: skipEvaluate ? false : evaluateArm.out?.ok,
2342
- unanswered: missing,
2343
- });
2785
+ note(
2786
+ notes,
2787
+ 'protected-parent.page-client',
2788
+ pageClientSummary(result, skipEvaluate ? 'srcdoc' : 'ordinary', missing, {
2789
+ attachRefused: result.attachRefused ?? false,
2790
+ grandchildTargetId: raw.grandchildTargetId ?? null,
2791
+ liveBlocked: raw.liveBlocked ?? null,
2792
+ windowMs,
2793
+ childSessions: [...childSessions],
2794
+ firstTreeOk: treeArm.out?.ok,
2795
+ firstResourceOk: resourceArm.out?.ok,
2796
+ firstEvaluateOk: skipEvaluate ? false : evaluateArm.out?.ok,
2797
+ })
2798
+ );
2344
2799
  return outcome(client.send('Target.detachFromTarget', { sessionId }));
2345
2800
  }
2346
2801
 
@@ -2450,6 +2905,8 @@ async function pageNested({
2450
2905
  budget,
2451
2906
  notes,
2452
2907
  internalSessions,
2908
+ ordinary,
2909
+ tag,
2453
2910
  });
2454
2911
  return {
2455
2912
  live: true,