@jobshimo/browser-link 0.36.0 → 0.38.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 (69) hide show
  1. package/dist/agent-instructions/content.js +5 -349
  2. package/dist/agent-instructions/content.js.map +1 -1
  3. package/dist/bridge/server.d.ts +5 -0
  4. package/dist/bridge/server.js +1 -1
  5. package/dist/bridge/server.js.map +1 -1
  6. package/dist/cdp/flow.d.ts +44 -3
  7. package/dist/cdp/flow.js +65 -19
  8. package/dist/cdp/flow.js.map +1 -1
  9. package/dist/cdp/inpage/builders.d.ts +110 -24
  10. package/dist/cdp/inpage/builders.js +203 -53
  11. package/dist/cdp/inpage/builders.js.map +1 -1
  12. package/dist/cdp/inpage/deep-query.d.ts +1 -1
  13. package/dist/cdp/inpage/deep-query.js +12 -9
  14. package/dist/cdp/inpage/deep-query.js.map +1 -1
  15. package/dist/cdp/inpage/observer.d.ts +36 -7
  16. package/dist/cdp/inpage/observer.js +242 -16
  17. package/dist/cdp/inpage/observer.js.map +1 -1
  18. package/dist/cdp/transport.js +96 -9
  19. package/dist/cdp/transport.js.map +1 -1
  20. package/dist/commands/about.js +4 -2
  21. package/dist/commands/about.js.map +1 -1
  22. package/dist/extension/background.js +97 -13
  23. package/dist/extension/background.js.map +1 -1
  24. package/dist/extension/flow.d.ts +44 -3
  25. package/dist/extension/flow.js +65 -19
  26. package/dist/extension/flow.js.map +1 -1
  27. package/dist/extension/inpage/builders.d.ts +110 -24
  28. package/dist/extension/inpage/builders.js +203 -53
  29. package/dist/extension/inpage/builders.js.map +1 -1
  30. package/dist/extension/inpage/deep-query.d.ts +1 -1
  31. package/dist/extension/inpage/deep-query.js +12 -9
  32. package/dist/extension/inpage/deep-query.js.map +1 -1
  33. package/dist/extension/inpage/observer.d.ts +36 -7
  34. package/dist/extension/inpage/observer.js +242 -16
  35. package/dist/extension/inpage/observer.js.map +1 -1
  36. package/dist/extension/manifest.json +1 -1
  37. package/dist/manual/core.d.ts +20 -0
  38. package/dist/manual/core.js +71 -0
  39. package/dist/manual/core.js.map +1 -0
  40. package/dist/manual/render.d.ts +22 -0
  41. package/dist/manual/render.js +56 -0
  42. package/dist/manual/render.js.map +1 -0
  43. package/dist/manual/status.d.ts +23 -0
  44. package/dist/manual/status.js +52 -0
  45. package/dist/manual/status.js.map +1 -0
  46. package/dist/manual/tool.d.ts +20 -0
  47. package/dist/manual/tool.js +106 -0
  48. package/dist/manual/tool.js.map +1 -0
  49. package/dist/manual/topics.d.ts +18 -0
  50. package/dist/manual/topics.js +60 -0
  51. package/dist/manual/topics.js.map +1 -0
  52. package/dist/map/queries.d.ts +2 -0
  53. package/dist/map/queries.js +23 -1
  54. package/dist/map/queries.js.map +1 -1
  55. package/dist/map/tools.js +26 -4
  56. package/dist/map/tools.js.map +1 -1
  57. package/dist/permissions.js +6 -0
  58. package/dist/permissions.js.map +1 -1
  59. package/dist/server.js +11 -14
  60. package/dist/server.js.map +1 -1
  61. package/dist/tools/browser-definitions.js +113 -23
  62. package/dist/tools/browser-definitions.js.map +1 -1
  63. package/dist/tools/browser-dispatch.d.ts +24 -26
  64. package/dist/tools/browser-dispatch.js +169 -14
  65. package/dist/tools/browser-dispatch.js.map +1 -1
  66. package/dist/tools/server-instructions.d.ts +24 -13
  67. package/dist/tools/server-instructions.js +25 -303
  68. package/dist/tools/server-instructions.js.map +1 -1
  69. package/package.json +1 -1
@@ -28,7 +28,7 @@ import { OBSERVER_GLOBAL } from './observer.js';
28
28
  * injected verbatim into `buildSnapshotJs`, `buildFindJs` and `buildStateJs`.
29
29
  * The observer global is looked up ONCE per evaluation and used only when it
30
30
  * is present, not torn down, and exposes `refFor`:
31
- * - `refOf(el)` returns the observer's `e<N>` ref for `el`, or `null`;
31
+ * - `refOf(el)` returns the observer's `<doc_tag>:e<N>` ref for `el`, or `null`;
32
32
  * - `withDocId(result)` adds `doc_id` to `result` and returns it;
33
33
  * - `snapshotStore()` returns the observer when it keeps snapshot records
34
34
  * (`recordSnapshot` / `getSnapshot`, used by `snapshot({ since })`), else
@@ -68,6 +68,53 @@ export const PAGE_OBSERVER_JS = `
68
68
  return null;
69
69
  }
70
70
  `;
71
+ /**
72
+ * In-page action-target resolution (spec v4 §6.3), injected after
73
+ * `DEEP_QUERY_JS` and `PAGE_OBSERVER_JS` into the builders that take a
74
+ * `selector` or a `ref` (click, type, focus, element rect, `wait_for` by
75
+ * ref, `find` by ref):
76
+ * `resolveTarget(opts)` with a non-empty `opts.ref` asks the observer
77
+ * (`resolveRefDetailed`, which re-resolves a replaced node by its semantic
78
+ * key) and answers `{ ok: true, el, reresolved }`, `{ ok: false, reason:
79
+ * 'ref-stale', ref, doc_id }` or `{ ok: false, reason: 'observer-unavailable'
80
+ * }`; otherwise it resolves `opts.selector` exactly as the selector builders
81
+ * always did (`invalid-selector` checked against `document` first, then
82
+ * `deepQueryFirst`, `not-found`). Kept out of `PAGE_OBSERVER_JS` so the
83
+ * snapshot and state sources do not carry code they never call.
84
+ */
85
+ export const RESOLVE_TARGET_JS = `
86
+ function resolveTarget(opts) {
87
+ if (typeof opts.ref === 'string' && opts.ref.length > 0) {
88
+ if (!pageObserver || typeof pageObserver.resolveRefDetailed !== 'function') {
89
+ return { ok: false, reason: 'observer-unavailable' };
90
+ }
91
+ let found = null;
92
+ try {
93
+ found = pageObserver.resolveRefDetailed(opts.ref);
94
+ } catch (e) {
95
+ found = null;
96
+ }
97
+ if (!found || !found.el) return withDocId({ ok: false, reason: 'ref-stale', ref: opts.ref });
98
+ return { ok: true, el: found.el, reresolved: found.reresolved === true };
99
+ }
100
+ try {
101
+ document.querySelector(opts.selector);
102
+ } catch (e) {
103
+ return { ok: false, reason: 'invalid-selector', error: e && e.message ? e.message : String(e) };
104
+ }
105
+ const el = deepQueryFirst(opts.selector);
106
+ if (!el) return { ok: false, reason: 'not-found' };
107
+ return { ok: true, el: el, reresolved: false };
108
+ }
109
+ `;
110
+ /** JSON for the `selector` / `ref` pair, embedded as data in the built
111
+ * source; `ref` is included only when given so a selector build keeps the
112
+ * same options object as before. */
113
+ function targetJson(opts) {
114
+ return typeof opts.ref === 'string' && opts.ref.length > 0
115
+ ? { selector: opts.selector, ref: opts.ref }
116
+ : { selector: opts.selector };
117
+ }
71
118
  export function buildSnapshotJs(opts = {}) {
72
119
  const optsJson = JSON.stringify({
73
120
  withinSelector: typeof opts.within_selector === 'string' ? opts.within_selector : null,
@@ -260,6 +307,16 @@ export function buildSnapshotJs(opts = {}) {
260
307
  })()
261
308
  `;
262
309
  }
310
+ /** Only the documented key fields reach the built source, as JSON data. */
311
+ function findKeyJson(key) {
312
+ return Array.isArray(key.path)
313
+ ? {
314
+ role: key.role,
315
+ name: key.name,
316
+ path: key.path.map((step) => ({ tag: step.tag, index: step.index })),
317
+ }
318
+ : { role: key.role, name: key.name };
319
+ }
263
320
  export function buildFindJs(opts) {
264
321
  const optsJson = JSON.stringify({
265
322
  text: opts.text,
@@ -267,13 +324,98 @@ export function buildFindJs(opts) {
267
324
  exact: opts.exact === true,
268
325
  candidateLimit: 5,
269
326
  nearMissLimit: 3,
327
+ ...(typeof opts.ref === 'string' && opts.ref.length > 0 ? { ref: opts.ref } : {}),
328
+ ...(opts.key ? { key: findKeyJson(opts.key) } : {}),
270
329
  });
271
330
  return `
272
331
  (() => {
273
332
  ${DEEP_QUERY_JS}
274
333
  ${DOM_HELPERS_JS}
275
334
  ${PAGE_OBSERVER_JS}
335
+ ${typeof opts.ref === 'string' && opts.ref.length > 0 ? RESOLVE_TARGET_JS : ''}
276
336
  const opts = ${optsJson};
337
+ function semanticKeyOf(el) {
338
+ if (!pageObserver || typeof pageObserver.semanticKeyFor !== 'function') return null;
339
+ try {
340
+ const key = pageObserver.semanticKeyFor(el);
341
+ return key && typeof key === 'object' ? key : null;
342
+ } catch (e) {
343
+ return null;
344
+ }
345
+ }
346
+ function singleMatch(el, ref, reresolved) {
347
+ const center = viewportCenterOf(el);
348
+ const selInfo = genSelectorInfo(el);
349
+ const result = { matched: true, selector: selInfo.selector };
350
+ if (ref) result.ref = ref;
351
+ result.coords = {
352
+ x: Math.round(center.x),
353
+ y: Math.round(center.y),
354
+ };
355
+ result.tag = el.tagName.toLowerCase();
356
+ result.text = shortText(el);
357
+ if (selInfo.ambiguous) result.ambiguous = true;
358
+ const frame = frameSelectorFor(el);
359
+ if (frame) result.frame = frame;
360
+ if (reresolved) result.reresolved = true;
361
+ const key = semanticKeyOf(el);
362
+ if (key) result.semantic_key = key;
363
+ return withDocId(result);
364
+ }
365
+ if (typeof opts.ref === 'string') {
366
+ const target = resolveTarget(opts);
367
+ if (!target.ok) {
368
+ const failure = { matched: false, reason: target.reason, ref: opts.ref };
369
+ return withDocId(failure);
370
+ }
371
+ return singleMatch(target.el, opts.ref, target.reresolved);
372
+ }
373
+ if (opts.key) {
374
+ if (!pageObserver || typeof pageObserver.semanticKeyFor !== 'function') {
375
+ return { matched: false, reason: 'observer-unavailable' };
376
+ }
377
+ const wanted = opts.key;
378
+ const candidates = [];
379
+ for (const el of deepQueryAll('*')) {
380
+ const key = semanticKeyOf(el);
381
+ if (key && key.role === wanted.role && key.name === wanted.name) {
382
+ candidates.push({ el: el, path: Array.isArray(key.path) ? key.path : [] });
383
+ }
384
+ }
385
+ const count = candidates.length;
386
+ const shared = 'key: ' + count + ' candidates share role and name; ';
387
+ let picked = null;
388
+ let error = count > 1 ? shared + 'pass path to disambiguate' : null;
389
+ if (!Array.isArray(wanted.path)) {
390
+ if (count === 1) picked = candidates[0].el;
391
+ } else {
392
+ // Same rule as the observer's re-resolution: identical tag path and
393
+ // exactly one such candidate; identical rows are refused, never guessed.
394
+ let sameTags = 0;
395
+ let only = null;
396
+ for (const c of candidates) {
397
+ if (c.path.length !== wanted.path.length) continue;
398
+ let same = true;
399
+ for (let i = 0; i < c.path.length && same; i++) {
400
+ if (c.path[i].tag !== wanted.path[i].tag) same = false;
401
+ }
402
+ if (!same) continue;
403
+ sameTags++;
404
+ only = c.el;
405
+ }
406
+ if (sameTags === 1) {
407
+ picked = only;
408
+ } else if (sameTags > 1) {
409
+ error = 'key: ' + sameTags + ' candidates share role, name and tag path';
410
+ } else if (count > 0) {
411
+ error = shared + 'none has the same tag path';
412
+ }
413
+ }
414
+ if (picked) return singleMatch(picked, refOf(picked), false);
415
+ const failure = { matched: false, reason: 'not-found' };
416
+ if (error) failure.error = error;
417
+ return withDocId(failure);
418
+ }
277
419
  const needle = opts.text.toLowerCase();
278
420
  const needleTokens = needle.split(/[^a-z0-9]+/).filter(Boolean);
279
421
  const ROLE_SELECTORS = {
@@ -392,37 +534,21 @@ export function buildFindJs(opts) {
392
534
  });
393
535
  }
394
536
  const el = matches[0];
395
- const center = viewportCenterOf(el);
396
- const selInfo = genSelectorInfo(el);
397
- const result = { matched: true, selector: selInfo.selector };
398
- const ref = refOf(el);
399
- if (ref) result.ref = ref;
400
- result.coords = {
401
- x: Math.round(center.x),
402
- y: Math.round(center.y),
403
- };
404
- result.tag = el.tagName.toLowerCase();
405
- result.text = shortText(el);
406
- if (selInfo.ambiguous) result.ambiguous = true;
407
- const frame = frameSelectorFor(el);
408
- if (frame) result.frame = frame;
409
- return withDocId(result);
537
+ return singleMatch(el, refOf(el), false);
410
538
  })()
411
539
  `;
412
540
  }
413
541
  export function buildClickResolveJs(opts) {
414
- const optsJson = JSON.stringify({ selector: opts.selector, force: opts.force });
542
+ const optsJson = JSON.stringify({ ...targetJson(opts), force: opts.force });
415
543
  return `
416
544
  (() => {
417
545
  ${DEEP_QUERY_JS}
546
+ ${PAGE_OBSERVER_JS}
547
+ ${RESOLVE_TARGET_JS}
418
548
  const opts = ${optsJson};
419
- try {
420
- document.querySelector(opts.selector);
421
- } catch (e) {
422
- return { ok: false, reason: 'invalid-selector', error: e && e.message ? e.message : String(e) };
423
- }
424
- const el = deepQueryFirst(opts.selector);
425
- if (!el) return { ok: false, reason: 'not-found' };
549
+ const target = resolveTarget(opts);
550
+ if (!target.ok) return target;
551
+ const el = target.el;
426
552
  const chain = frameElementChain(el);
427
553
  for (const fe of chain) {
428
554
  if (fe.scrollIntoView) fe.scrollIntoView({ block: 'center', inline: 'center' });
@@ -432,46 +558,67 @@ export function buildClickResolveJs(opts) {
432
558
  const tag = el.tagName.toLowerCase();
433
559
  const occlusion = checkOcclusion(el, center.localX, center.localY);
434
560
  if (!occlusion.allowed && !opts.force) {
561
+ if (occlusion.retargeted) {
562
+ return { ok: false, reason: 'retargeted', hit_element: occlusion.hit };
563
+ }
435
564
  return { ok: false, reason: 'occluded', blocker: occlusion.blocker };
436
565
  }
437
566
  const result = { ok: true, x: center.x, y: center.y, tag };
438
- const hit = occlusion.allowed ? occlusion.hit : occlusion.blocker;
567
+ const hit = occlusion.hit || occlusion.blocker;
439
568
  if (hit) result.hit_element = hit;
569
+ if (target.reresolved) result.reresolved = true;
440
570
  return result;
441
571
  })()
442
572
  `;
443
573
  }
444
574
  export function buildTypeResolveJs(opts) {
445
- const optsJson = JSON.stringify({ selector: opts.selector });
575
+ const optsJson = JSON.stringify(targetJson(opts));
446
576
  return `
447
577
  (() => {
448
578
  ${DEEP_QUERY_JS}
579
+ ${PAGE_OBSERVER_JS}
580
+ ${RESOLVE_TARGET_JS}
449
581
  const opts = ${optsJson};
450
- try {
451
- document.querySelector(opts.selector);
452
- } catch (e) {
453
- return { ok: false, reason: 'invalid-selector', error: e && e.message ? e.message : String(e) };
454
- }
455
- const el = deepQueryFirst(opts.selector);
456
- if (!el) return { ok: false, reason: 'not-found' };
582
+ const target = resolveTarget(opts);
583
+ if (!target.ok) return target;
584
+ const el = target.el;
457
585
  el.focus();
458
586
  ${opts.clear ? "if ('value' in el) { el.value = ''; el.dispatchEvent(new Event('input', { bubbles: true })); }" : ''}
459
- return { ok: true };
587
+ return target.reresolved ? { ok: true, reresolved: true } : { ok: true };
460
588
  })()`;
461
589
  }
462
590
  export function buildFocusJs(opts) {
463
- const optsJson = JSON.stringify({ selector: opts.selector });
591
+ const optsJson = JSON.stringify(targetJson(opts));
464
592
  return `
465
593
  (() => {
466
594
  ${DEEP_QUERY_JS}
595
+ ${PAGE_OBSERVER_JS}
596
+ ${RESOLVE_TARGET_JS}
467
597
  const opts = ${optsJson};
468
- const el = deepQueryFirst(opts.selector);
469
- if (!el) return false;
470
- el.focus();
471
- return true;
598
+ const target = resolveTarget(opts);
599
+ const byRef = typeof opts.ref === 'string';
600
+ if (!target.ok) return byRef ? target : false;
601
+ target.el.focus();
602
+ if (!byRef) return true;
603
+ return target.reresolved ? { ok: true, reresolved: true } : { ok: true };
472
604
  })()`;
473
605
  }
474
- export function buildWaitForSelectorJs(selector, condition) {
606
+ export function buildWaitForSelectorJs(target, condition) {
607
+ if (typeof target !== 'string') {
608
+ const refOptsJson = JSON.stringify({ ref: target.ref, condition });
609
+ return `
610
+ (() => {
611
+ ${DEEP_QUERY_JS}
612
+ ${PAGE_OBSERVER_JS}
613
+ ${RESOLVE_TARGET_JS}
614
+ const opts = ${refOptsJson};
615
+ const target = resolveTarget(opts);
616
+ if (!target.ok && target.reason === 'observer-unavailable') return target;
617
+ const el = target.ok ? target.el : null;
618
+ ${WAIT_FOR_CONDITION_JS}
619
+ })()`;
620
+ }
621
+ const selector = target;
475
622
  const optsJson = JSON.stringify({ selector, condition });
476
623
  return `
477
624
  (() => {
@@ -479,7 +626,12 @@ export function buildWaitForSelectorJs(selector, condition) {
479
626
  const opts = ${optsJson};
480
627
  document.querySelector(opts.selector);
481
628
  const el = deepQueryFirst(opts.selector);
482
- if (opts.condition === 'attached') return Boolean(el);
629
+ ${WAIT_FOR_CONDITION_JS}
630
+ })()`;
631
+ }
632
+ /** The condition check shared by both `wait_for` probe targets; `el` is
633
+ * the resolved element or `null`. */
634
+ const WAIT_FOR_CONDITION_JS = `if (opts.condition === 'attached') return Boolean(el);
483
635
  if (opts.condition === 'detached') return !el;
484
636
  const wantHidden = opts.condition === 'hidden';
485
637
  if (!el) return wantHidden;
@@ -488,22 +640,18 @@ export function buildWaitForSelectorJs(selector, condition) {
488
640
  if (s.display === 'none' || s.visibility === 'hidden' || s.opacity === '0') return wantHidden;
489
641
  const r = el.getBoundingClientRect();
490
642
  const shown = r.width > 0 && r.height > 0;
491
- return wantHidden ? !shown : shown;
492
- })()`;
493
- }
643
+ return wantHidden ? !shown : shown;`;
494
644
  export function buildElementRectJs(opts) {
495
- const optsJson = JSON.stringify({ selector: opts.selector });
645
+ const optsJson = JSON.stringify(targetJson(opts));
496
646
  return `
497
647
  (() => {
498
648
  ${DEEP_QUERY_JS}
649
+ ${PAGE_OBSERVER_JS}
650
+ ${RESOLVE_TARGET_JS}
499
651
  const opts = ${optsJson};
500
- try {
501
- document.querySelector(opts.selector);
502
- } catch (e) {
503
- return { ok: false, reason: 'invalid-selector', error: e && e.message ? e.message : String(e) };
504
- }
505
- const el = deepQueryFirst(opts.selector);
506
- if (!el) return { ok: false, reason: 'not-found' };
652
+ const target = resolveTarget(opts);
653
+ if (!target.ok) return target;
654
+ const el = target.el;
507
655
  const chain = frameElementChain(el);
508
656
  // behavior 'instant' overrides CSS scroll-behavior: smooth, which would
509
657
  // leave the rect below stale while the scroll is still animating.
@@ -528,13 +676,15 @@ export function buildElementRectJs(opts) {
528
676
  scrollX = top.scrollX || 0;
529
677
  scrollY = top.scrollY || 0;
530
678
  } catch (_) {}
531
- return {
679
+ const result = {
532
680
  ok: true,
533
681
  x: offsetX + rect.left + scrollX,
534
682
  y: offsetY + rect.top + scrollY,
535
683
  width: rect.width,
536
684
  height: rect.height,
537
685
  };
686
+ if (target.reresolved) result.reresolved = true;
687
+ return result;
538
688
  })()`;
539
689
  }
540
690
  export function buildSettleJs(opts) {
@@ -1 +1 @@
1
- {"version":3,"file":"builders.js","sourceRoot":"","sources":["../../../src/cdp/inpage/builders.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,M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C,SAAS,CAAC;QAC9B,eAAe,EAAE,IAAI,CAAC,gBAAgB;QACtC,kBAAkB,EAAE,IAAI,CAAC,mBAAmB;QAC5C,WAAW,EAAE,IAAI,CAAC,YAAY;KAC/B,CAAC,CAAC;IACH,OAAO;;IAEL,aAAa;IACb,cAAc;iBACD,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4DxB,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO;;IAEL,aAAa;IACb,cAAc;IACd,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsFnB,CAAC;AACF,CAAC"}
@@ -54,4 +54,4 @@
54
54
  * `dom-helpers.ts`), snapshot/find mark the affected entry with
55
55
  * `ambiguous: true` so agents know not to cache that selector.
56
56
  */
57
- export declare const DEEP_QUERY_JS = "\n function collectSearchRoots(start) {\n // start: a Document, Element or ShadowRoot to scope the search to.\n // Returns [start, ...every open shadow root and same-origin iframe\n // document reachable inside start's subtree, recursively]. The caller\n // runs .querySelectorAll()/.querySelector() on each entry directly \u2014\n // each entry's own querySelectorAll does NOT pierce into nested shadow\n // roots or iframes on its own, which is why we enumerate them here.\n var roots = [start];\n function walk(scope, depth) {\n // Depth guard, same pattern as the other recursive helpers here:\n // pathological nesting (or a cycle introduced by a broken mock)\n // must degrade to a truncated result, never a stack overflow.\n if (depth > 20) return;\n var all;\n try {\n all = scope.querySelectorAll('*');\n } catch (_) {\n return;\n }\n for (var i = 0; i < all.length; i++) {\n var el = all[i];\n if (el.shadowRoot) {\n roots.push(el.shadowRoot);\n walk(el.shadowRoot, depth + 1);\n }\n if (el.tagName === 'IFRAME') {\n var doc = null;\n try {\n doc = el.contentDocument;\n } catch (_) {\n doc = null;\n }\n if (doc) {\n roots.push(doc);\n walk(doc, depth + 1);\n }\n }\n }\n }\n walk(start, 0);\n return roots;\n }\n\n function deepWalkAll(callback, start) {\n // Tree-walk primitive: invoke callback(el) for every element reachable\n // from start (default: document) across the top document, every open\n // shadow root, and every same-origin iframe document.\n var root = start || document;\n var roots = collectSearchRoots(root);\n for (var r = 0; r < roots.length; r++) {\n var all;\n try {\n all = roots[r].querySelectorAll('*');\n } catch (_) {\n continue;\n }\n for (var i = 0; i < all.length; i++) callback(all[i]);\n }\n }\n\n function deepQueryAll(selector, start) {\n var root = start || document;\n var roots = collectSearchRoots(root);\n var out = [];\n for (var r = 0; r < roots.length; r++) {\n var found;\n try {\n found = roots[r].querySelectorAll(selector);\n } catch (_) {\n continue;\n }\n for (var i = 0; i < found.length; i++) out.push(found[i]);\n }\n return out;\n }\n\n function deepQueryFirst(selector, start) {\n var root = start || document;\n var roots = collectSearchRoots(root);\n for (var r = 0; r < roots.length; r++) {\n var el = null;\n try {\n el = roots[r].querySelector(selector);\n } catch (_) {\n el = null;\n }\n if (el) return el;\n }\n return null;\n }\n\n function frameElementChain(el) {\n // Walk up from el's own window to the top window, collecting the\n // <iframe> element that hosts each intermediate document. Outermost\n // frame first. Same-origin only \u2014 frameElement throws/returns null\n // across an origin boundary, at which point the chain simply stops\n // (the coordinate math below degrades gracefully rather than throwing).\n var chain = [];\n var doc = el.ownerDocument;\n var win = doc && doc.defaultView;\n if (!win) return chain;\n var topWin;\n try {\n topWin = win.top;\n } catch (_) {\n topWin = win;\n }\n var guard = 0;\n while (win && win !== topWin && guard < 20) {\n guard++;\n var fe = null;\n try {\n fe = win.frameElement;\n } catch (_) {\n fe = null;\n }\n if (!fe) break;\n chain.unshift(fe);\n win = fe.ownerDocument && fe.ownerDocument.defaultView;\n }\n return chain;\n }\n\n function frameViewportOriginOffset(fe) {\n // The embedded document's viewport origin sits at the frame element's\n // CONTENT box, but getBoundingClientRect() returns the BORDER box \u2014\n // border and padding must be added on top of rect.left/rect.top or\n // every coordinate inside a styled iframe lands short. clientLeft/\n // clientTop are the border widths; padding comes from computed style\n // (read through the frame's own view \u2014 same-origin, so reachable).\n var borderX = fe.clientLeft || 0;\n var borderY = fe.clientTop || 0;\n var padX = 0;\n var padY = 0;\n try {\n var view = (fe.ownerDocument && fe.ownerDocument.defaultView) || window;\n var style = view.getComputedStyle(fe);\n padX = parseFloat(style.paddingLeft) || 0;\n padY = parseFloat(style.paddingTop) || 0;\n } catch (_) {}\n return { x: borderX + padX, y: borderY + padY };\n }\n\n function clickRectOf(el) {\n // For a line-wrapped INLINE element (a link spanning two lines), the\n // center of getBoundingClientRect() can land in the unpainted gap\n // between the line boxes \u2014 elementFromPoint would report whatever sits\n // behind, and a dispatched click would miss. The first client rect is\n // always a painted fragment, so its center is a safe click point.\n // Block-level elements have exactly one client rect, identical to the\n // bounding rect \u2014 no behavior change for them.\n var rects = null;\n try {\n rects = el.getClientRects ? el.getClientRects() : null;\n } catch (_) {\n rects = null;\n }\n if (rects && rects.length > 0) return rects[0];\n return el.getBoundingClientRect();\n }\n\n function viewportCenterOf(el) {\n // Returns the element's click point in two coordinate spaces:\n // - localX/localY: relative to el's OWN document viewport (what\n // that document's elementFromPoint expects).\n // - x/y: relative to the TOP-LEVEL viewport (what CDP\n // Input.dispatchMouseEvent expects) \u2014 localX/localY plus the\n // accumulated content-box origin of every ancestor <iframe>\n // element (border-box rect + border + padding). Shadow DOM\n // boundaries need no offset: they do not introduce a new\n // coordinate space.\n // Both spaces derive from the SAME point (first-client-rect center),\n // so the occlusion hit-test and the CDP dispatch always agree.\n var rect = clickRectOf(el);\n var localX = rect.left + rect.width / 2;\n var localY = rect.top + rect.height / 2;\n var chain = frameElementChain(el);\n var offsetX = 0;\n var offsetY = 0;\n for (var i = 0; i < chain.length; i++) {\n var frameRect = chain[i].getBoundingClientRect();\n var origin = frameViewportOriginOffset(chain[i]);\n offsetX += frameRect.left + origin.x;\n offsetY += frameRect.top + origin.y;\n }\n return { x: offsetX + localX, y: offsetY + localY, localX: localX, localY: localY };\n }\n\n function composedContains(ancestor, node) {\n // Node.contains() does not cross shadow boundaries. This walks the\n // COMPOSED tree: when climbing hits a ShadowRoot (no parentNode), jump\n // to its host and keep climbing.\n var cur = node;\n var guard = 0;\n while (cur && guard < 1000) {\n guard++;\n if (cur === ancestor) return true;\n if (cur.parentNode) {\n cur = cur.parentNode;\n continue;\n }\n if (cur.host) {\n cur = cur.host;\n continue;\n }\n break;\n }\n return false;\n }\n\n function describeElement(el) {\n if (!el || !el.tagName) return 'an unknown element';\n var desc = el.tagName.toLowerCase();\n if (el.id) desc += '#' + el.id;\n if (el.classList && el.classList.length) {\n var classes = [];\n for (var i = 0; i < el.classList.length && i < 2; i++) classes.push(el.classList[i]);\n if (classes.length) desc += '.' + classes.join('.');\n }\n return desc;\n }\n\n function hitTestDeep(root, x, y) {\n var node = null;\n try {\n node = root && root.elementFromPoint ? root.elementFromPoint(x, y) : null;\n } catch (_) {\n node = null;\n }\n // The hit element may itself host a nested open shadow root whose\n // content visually covers the point \u2014 descend until elementFromPoint\n // stops finding a deeper shadow tree.\n var guard = 0;\n while (node && node.shadowRoot && guard < 20) {\n guard++;\n var inner = null;\n try {\n inner = node.shadowRoot.elementFromPoint ? node.shadowRoot.elementFromPoint(x, y) : null;\n } catch (_) {\n inner = null;\n }\n if (!inner || inner === node) break;\n node = inner;\n }\n return node;\n }\n\n function computedPointerEvents(el) {\n // Read through the element's own window (cross-document\n // getComputedStyle is unreliable); any failure fails open (not 'none').\n try {\n var view = (el.ownerDocument && el.ownerDocument.defaultView) || window;\n return view.getComputedStyle(el).pointerEvents;\n } catch (_) {\n return '';\n }\n }\n\n function checkOcclusion(target, localX, localY) {\n // Hit-test starting from the element's OWN root (its closest shadow\n // root, or the document that owns it when not in shadow DOM) using\n // LOCAL coordinates \u2014 the same coordinate space that root's own\n // elementFromPoint expects (an iframe document's viewport starts at\n // its own top-left, not the top-level page's).\n var root = target.getRootNode ? target.getRootNode() : document;\n var hit = hitTestDeep(root, localX, localY);\n if (!hit) {\n // Nothing hit-tested at all (e.g. elementFromPoint unsupported in\n // this environment, or the point is outside the rendered area).\n // Fail open rather than block a click we cannot actually verify.\n return { allowed: true };\n }\n if (hit === target || composedContains(target, hit)) {\n return { allowed: true };\n }\n if (composedContains(hit, target)) {\n // ANCESTOR hit: the click targets the ancestor and never reaches\n // the element itself (events bubble upward, not down). Allowed as\n // before, but surfaced so click results can report hit_element.\n return { allowed: true, hit: describeElement(hit) };\n }\n if (computedPointerEvents(target) === 'none') {\n // A pointer-events:none target can never be the hit-test result \u2014 a\n // real user click at this exact point reaches hit instead, by the\n // page's own design (invisible a11y layer over the visual control's\n // hit-target sibling). The hit is not a\n // blocker to dismiss; it IS what a real click activates, so allow\n // the dispatch and report the true recipient.\n return { allowed: true, hit: describeElement(hit) };\n }\n return { allowed: false, blocker: describeElement(hit) };\n }\n";
57
+ export declare const DEEP_QUERY_JS = "\n function collectSearchRoots(start) {\n // start: a Document, Element or ShadowRoot to scope the search to.\n // Returns [start, ...every open shadow root and same-origin iframe\n // document reachable inside start's subtree, recursively]. The caller\n // runs .querySelectorAll()/.querySelector() on each entry directly \u2014\n // each entry's own querySelectorAll does NOT pierce into nested shadow\n // roots or iframes on its own, which is why we enumerate them here.\n var roots = [start];\n function walk(scope, depth) {\n // Depth guard, same pattern as the other recursive helpers here:\n // pathological nesting (or a cycle introduced by a broken mock)\n // must degrade to a truncated result, never a stack overflow.\n if (depth > 20) return;\n var all;\n try {\n all = scope.querySelectorAll('*');\n } catch (_) {\n return;\n }\n for (var i = 0; i < all.length; i++) {\n var el = all[i];\n if (el.shadowRoot) {\n roots.push(el.shadowRoot);\n walk(el.shadowRoot, depth + 1);\n }\n if (el.tagName === 'IFRAME') {\n var doc = null;\n try {\n doc = el.contentDocument;\n } catch (_) {\n doc = null;\n }\n if (doc) {\n roots.push(doc);\n walk(doc, depth + 1);\n }\n }\n }\n }\n walk(start, 0);\n return roots;\n }\n\n function deepWalkAll(callback, start) {\n // Tree-walk primitive: invoke callback(el) for every element reachable\n // from start (default: document) across the top document, every open\n // shadow root, and every same-origin iframe document.\n var root = start || document;\n var roots = collectSearchRoots(root);\n for (var r = 0; r < roots.length; r++) {\n var all;\n try {\n all = roots[r].querySelectorAll('*');\n } catch (_) {\n continue;\n }\n for (var i = 0; i < all.length; i++) callback(all[i]);\n }\n }\n\n function deepQueryAll(selector, start) {\n var root = start || document;\n var roots = collectSearchRoots(root);\n var out = [];\n for (var r = 0; r < roots.length; r++) {\n var found;\n try {\n found = roots[r].querySelectorAll(selector);\n } catch (_) {\n continue;\n }\n for (var i = 0; i < found.length; i++) out.push(found[i]);\n }\n return out;\n }\n\n function deepQueryFirst(selector, start) {\n var root = start || document;\n var roots = collectSearchRoots(root);\n for (var r = 0; r < roots.length; r++) {\n var el = null;\n try {\n el = roots[r].querySelector(selector);\n } catch (_) {\n el = null;\n }\n if (el) return el;\n }\n return null;\n }\n\n function frameElementChain(el) {\n // Walk up from el's own window to the top window, collecting the\n // <iframe> element that hosts each intermediate document. Outermost\n // frame first. Same-origin only \u2014 frameElement throws/returns null\n // across an origin boundary, at which point the chain simply stops\n // (the coordinate math below degrades gracefully rather than throwing).\n var chain = [];\n var doc = el.ownerDocument;\n var win = doc && doc.defaultView;\n if (!win) return chain;\n var topWin;\n try {\n topWin = win.top;\n } catch (_) {\n topWin = win;\n }\n var guard = 0;\n while (win && win !== topWin && guard < 20) {\n guard++;\n var fe = null;\n try {\n fe = win.frameElement;\n } catch (_) {\n fe = null;\n }\n if (!fe) break;\n chain.unshift(fe);\n win = fe.ownerDocument && fe.ownerDocument.defaultView;\n }\n return chain;\n }\n\n function frameViewportOriginOffset(fe) {\n // The embedded document's viewport origin sits at the frame element's\n // CONTENT box, but getBoundingClientRect() returns the BORDER box \u2014\n // border and padding must be added on top of rect.left/rect.top or\n // every coordinate inside a styled iframe lands short. clientLeft/\n // clientTop are the border widths; padding comes from computed style\n // (read through the frame's own view \u2014 same-origin, so reachable).\n var borderX = fe.clientLeft || 0;\n var borderY = fe.clientTop || 0;\n var padX = 0;\n var padY = 0;\n try {\n var view = (fe.ownerDocument && fe.ownerDocument.defaultView) || window;\n var style = view.getComputedStyle(fe);\n padX = parseFloat(style.paddingLeft) || 0;\n padY = parseFloat(style.paddingTop) || 0;\n } catch (_) {}\n return { x: borderX + padX, y: borderY + padY };\n }\n\n function clickRectOf(el) {\n // For a line-wrapped INLINE element (a link spanning two lines), the\n // center of getBoundingClientRect() can land in the unpainted gap\n // between the line boxes \u2014 elementFromPoint would report whatever sits\n // behind, and a dispatched click would miss. The first client rect is\n // always a painted fragment, so its center is a safe click point.\n // Block-level elements have exactly one client rect, identical to the\n // bounding rect \u2014 no behavior change for them.\n var rects = null;\n try {\n rects = el.getClientRects ? el.getClientRects() : null;\n } catch (_) {\n rects = null;\n }\n if (rects && rects.length > 0) return rects[0];\n return el.getBoundingClientRect();\n }\n\n function viewportCenterOf(el) {\n // Returns the element's click point in two coordinate spaces:\n // - localX/localY: relative to el's OWN document viewport (what\n // that document's elementFromPoint expects).\n // - x/y: relative to the TOP-LEVEL viewport (what CDP\n // Input.dispatchMouseEvent expects) \u2014 localX/localY plus the\n // accumulated content-box origin of every ancestor <iframe>\n // element (border-box rect + border + padding). Shadow DOM\n // boundaries need no offset: they do not introduce a new\n // coordinate space.\n // Both spaces derive from the SAME point (first-client-rect center),\n // so the occlusion hit-test and the CDP dispatch always agree.\n var rect = clickRectOf(el);\n var localX = rect.left + rect.width / 2;\n var localY = rect.top + rect.height / 2;\n var chain = frameElementChain(el);\n var offsetX = 0;\n var offsetY = 0;\n for (var i = 0; i < chain.length; i++) {\n var frameRect = chain[i].getBoundingClientRect();\n var origin = frameViewportOriginOffset(chain[i]);\n offsetX += frameRect.left + origin.x;\n offsetY += frameRect.top + origin.y;\n }\n return { x: offsetX + localX, y: offsetY + localY, localX: localX, localY: localY };\n }\n\n function composedContains(ancestor, node) {\n // Node.contains() does not cross shadow boundaries. This walks the\n // COMPOSED tree: when climbing hits a ShadowRoot (no parentNode), jump\n // to its host and keep climbing.\n var cur = node;\n var guard = 0;\n while (cur && guard < 1000) {\n guard++;\n if (cur === ancestor) return true;\n if (cur.parentNode) {\n cur = cur.parentNode;\n continue;\n }\n if (cur.host) {\n cur = cur.host;\n continue;\n }\n break;\n }\n return false;\n }\n\n function describeElement(el) {\n if (!el || !el.tagName) return 'an unknown element';\n var desc = el.tagName.toLowerCase();\n if (el.id) desc += '#' + el.id;\n if (el.classList && el.classList.length) {\n var classes = [];\n for (var i = 0; i < el.classList.length && i < 2; i++) classes.push(el.classList[i]);\n if (classes.length) desc += '.' + classes.join('.');\n }\n return desc;\n }\n\n function hitTestDeep(root, x, y) {\n var node = null;\n try {\n node = root && root.elementFromPoint ? root.elementFromPoint(x, y) : null;\n } catch (_) {\n node = null;\n }\n // The hit element may itself host a nested open shadow root whose\n // content visually covers the point \u2014 descend until elementFromPoint\n // stops finding a deeper shadow tree.\n var guard = 0;\n while (node && node.shadowRoot && guard < 20) {\n guard++;\n var inner = null;\n try {\n inner = node.shadowRoot.elementFromPoint ? node.shadowRoot.elementFromPoint(x, y) : null;\n } catch (_) {\n inner = null;\n }\n if (!inner || inner === node) break;\n node = inner;\n }\n return node;\n }\n\n function computedPointerEvents(el) {\n // Read through the element's own window (cross-document\n // getComputedStyle is unreliable); any failure fails open (not 'none').\n try {\n var view = (el.ownerDocument && el.ownerDocument.defaultView) || window;\n return view.getComputedStyle(el).pointerEvents;\n } catch (_) {\n return '';\n }\n }\n\n function checkOcclusion(target, localX, localY) {\n // Hit-test starting from the element's OWN root (its closest shadow\n // root, or the document that owns it when not in shadow DOM) using\n // LOCAL coordinates \u2014 the same coordinate space that root's own\n // elementFromPoint expects (an iframe document's viewport starts at\n // its own top-left, not the top-level page's).\n var root = target.getRootNode ? target.getRootNode() : document;\n var hit = hitTestDeep(root, localX, localY);\n if (!hit) {\n // Nothing hit-tested at all (e.g. elementFromPoint unsupported in\n // this environment, or the point is outside the rendered area).\n // Fail open rather than block a click we cannot actually verify.\n return { allowed: true };\n }\n if (hit === target || composedContains(target, hit)) {\n return { allowed: true };\n }\n if (computedPointerEvents(target) === 'none') {\n // A pointer-events:none target can never be the hit-test result \u2014 a\n // real user click at this exact point reaches hit instead, by the\n // page's own design (an icon inside its button, or an invisible a11y\n // layer over the visual control's hit-target sibling). The hit is not\n // a blocker to dismiss; it IS what a real click activates, so allow\n // the dispatch and report the true recipient.\n return { allowed: true, hit: describeElement(hit) };\n }\n if (composedContains(hit, target)) {\n // ANCESTOR hit on a target that does take pointer events: the target\n // is painted but not at its own centre (clipped by an overflow\n // container, zero-size, covered by its own parent). The click would\n // land on the ancestor and never reach the element itself (events\n // bubble upward, not down), so refuse it as 'retargeted' and report\n // where it would land.\n return { allowed: false, retargeted: true, hit: describeElement(hit) };\n }\n return { allowed: false, blocker: describeElement(hit) };\n }\n";
@@ -330,21 +330,24 @@ export const DEEP_QUERY_JS = `
330
330
  if (hit === target || composedContains(target, hit)) {
331
331
  return { allowed: true };
332
332
  }
333
- if (composedContains(hit, target)) {
334
- // ANCESTOR hit: the click targets the ancestor and never reaches
335
- // the element itself (events bubble upward, not down). Allowed as
336
- // before, but surfaced so click results can report hit_element.
337
- return { allowed: true, hit: describeElement(hit) };
338
- }
339
333
  if (computedPointerEvents(target) === 'none') {
340
334
  // A pointer-events:none target can never be the hit-test result — a
341
335
  // real user click at this exact point reaches hit instead, by the
342
- // page's own design (invisible a11y layer over the visual control's
343
- // hit-target sibling). The hit is not a
344
- // blocker to dismiss; it IS what a real click activates, so allow
336
+ // page's own design (an icon inside its button, or an invisible a11y
337
+ // layer over the visual control's hit-target sibling). The hit is not
338
+ // a blocker to dismiss; it IS what a real click activates, so allow
345
339
  // the dispatch and report the true recipient.
346
340
  return { allowed: true, hit: describeElement(hit) };
347
341
  }
342
+ if (composedContains(hit, target)) {
343
+ // ANCESTOR hit on a target that does take pointer events: the target
344
+ // is painted but not at its own centre (clipped by an overflow
345
+ // container, zero-size, covered by its own parent). The click would
346
+ // land on the ancestor and never reach the element itself (events
347
+ // bubble upward, not down), so refuse it as 'retargeted' and report
348
+ // where it would land.
349
+ return { allowed: false, retargeted: true, hit: describeElement(hit) };
350
+ }
348
351
  return { allowed: false, blocker: describeElement(hit) };
349
352
  }
350
353
  `;
@@ -1 +1 @@
1
- {"version":3,"file":"deep-query.js","sourceRoot":"","sources":["../../../src/cdp/inpage/deep-query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqS5B,CAAC"}
1
+ {"version":3,"file":"deep-query.js","sourceRoot":"","sources":["../../../src/cdp/inpage/deep-query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwS5B,CAAC"}
@@ -11,7 +11,7 @@
11
11
  * `cdp/builders-parity.test.ts` checks the built output.
12
12
  */
13
13
  /** Bump whenever the in-page protocol (global shape, messages, methods) changes. */
14
- export declare const OBSERVER_VERSION = 2;
14
+ export declare const OBSERVER_VERSION = 3;
15
15
  /** Name of the `Runtime.addBinding` function the observer pushes messages through. */
16
16
  export declare const OBSERVER_BINDING = "__blPageObserverPush";
17
17
  /** Well-known global that holds the installed observer instance. */
@@ -33,10 +33,30 @@ export interface ObserverInstallOpts {
33
33
  * `{ ok: true, installed, version, doc_id, coverage }`.
34
34
  *
35
35
  * The instance also owns element identity (spec v4 §5.6): `refFor(el)` issues
36
- * `e<N>` (monotonic per document instance, from `e1`) the first time an
37
- * element is seen and reuses it while the node lives; `resolveRef(ref)`
38
- * returns the element while it is connected, else `null`. Refs are only valid
39
- * for the `doc_id` that issued them. Neither method throws. `nextSnapshotId()`
36
+ * `<doc_tag>:e<N>` (`doc_tag` = the first 6 characters of `doc_id`, N
37
+ * monotonic per document instance, from 1) the first time an element is seen
38
+ * and reuses it while the node lives; `resolveRef(ref)` returns the element
39
+ * while it is connected, else `null`. Refs are only valid for the document
40
+ * instance that issued them: a ref whose tag is not this instance's tag, or a
41
+ * bare `e<N>` with no tag, is `null` everywhere (resolve, re-resolve, key)
42
+ * without consulting the registries. Neither method throws.
43
+ *
44
+ * Secondary identity (spec v4 §5.6, decided by lab 10): `semanticKeyFor(el)`
45
+ * returns `{ role, name, path }` — role from the `role` attribute or a small
46
+ * implicit table, accessible-ish name (aria-label, aria-labelledby, associated
47
+ * label, text ≤ 80 chars, placeholder, title, button-like input value) and up
48
+ * to 8 `{ tag, index }` ancestor steps (1-based same-tag sibling index, a
49
+ * shadow boundary as `{ tag: '#shadow', index: 0 }`). `refFor` stores the key
50
+ * when it issues a ref. `resolveRefDetailed(ref)` returns `{ el, reresolved }`:
51
+ * the live node with `reresolved: false`, else the element with the same role,
52
+ * name and tag-only path when exactly one exists, rebinding the ref to it
53
+ * (`reresolved: true`); zero or several candidates give `null` (sibling
54
+ * indices are kept in the key as data but never pick among candidates). Candidates come from the document, every open shadow root reachable
55
+ * from it, and every root the `attachShadow` patch observed (closed ones
56
+ * included); closed roots attached before install are not reachable.
57
+ * `resolveRef(ref)` is `resolveRefDetailed(ref)?.el ?? null`. `keyForRef(ref)`
58
+ * returns a copy of the stored key or `null`. None of these throws.
59
+ * `nextSnapshotId()`
40
60
  * issues `<doc_id>:s<N>` (N monotonic per document instance, from 1) for each
41
61
  * `snapshot` result and returns `null` once the instance is torn down; the
42
62
  * `doc_id` prefix lets a stale id from another document be rejected.
@@ -65,10 +85,19 @@ export declare function buildObserverChangesJs(mark: number, docId?: string): st
65
85
  /**
66
86
  * Build the ref-resolve expression, for tests and debugging. Evaluates to
67
87
  * `{ ok: true, found: true, tag }` when `ref` names an element of the current
68
- * document that is still connected, `{ ok: true, found: false }` when it is
69
- * unknown or stale, or `{ ok: false, reason: 'observer-unavailable' }`.
88
+ * document that is still connected — plus `reresolved: true` when the node was
89
+ * gone and the ref was just rebound by its semantic key —
90
+ * `{ ok: true, found: false }` when it is unknown or stale, or
91
+ * `{ ok: false, reason: 'observer-unavailable' }`.
70
92
  */
71
93
  export declare function buildObserverRefResolveJs(ref: string): string;
94
+ /**
95
+ * Build the semantic-key read expression. Evaluates to `{ ok: true, key }`
96
+ * with the `{ role, name, path }` stored when `ref` was issued, `{ ok: true,
97
+ * key: null }` for a ref this document instance does not know, or
98
+ * `{ ok: false, reason: 'observer-unavailable' }`.
99
+ */
100
+ export declare function buildObserverSemanticKeyJs(ref: string): string;
72
101
  /**
73
102
  * Build the teardown expression: disconnects every observer, restores the
74
103
  * `attachShadow` and `history` patches when they are still the observer's,