@oxvo/ai-live-assist 7.4.50 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/AiLiveAssist.d.ts +76 -11
- package/cjs/AiLiveAssist.js +1771 -298
- package/cjs/client.d.ts +19 -0
- package/cjs/client.js +51 -0
- package/cjs/context.d.ts +23 -1
- package/cjs/context.js +713 -126
- package/cjs/control.d.ts +2 -0
- package/cjs/control.js +42 -3
- package/cjs/ctaOffer.d.ts +11 -0
- package/cjs/ctaOffer.js +185 -0
- package/cjs/dialogFocusScope.js +1 -1
- package/cjs/guideAdmission.d.ts +46 -0
- package/cjs/guideAdmission.js +397 -0
- package/cjs/guideHost.d.ts +47 -0
- package/cjs/guideHost.js +48 -0
- package/cjs/guideInstallation.d.ts +12 -0
- package/cjs/guideInstallation.js +60 -0
- package/cjs/guideInstaller.d.ts +4 -0
- package/cjs/guideInstaller.js +116 -0
- package/cjs/guideMount.d.ts +22 -0
- package/cjs/guideMount.js +84 -0
- package/cjs/guideRecording.d.ts +64 -0
- package/cjs/guideRecording.js +176 -0
- package/cjs/guideRecordingSession.d.ts +35 -0
- package/cjs/guideRecordingSession.js +167 -0
- package/cjs/guideSubjectStore.d.ts +32 -0
- package/cjs/guideSubjectStore.js +105 -0
- package/cjs/guideTypes.d.ts +117 -0
- package/cjs/guideTypes.js +15 -0
- package/cjs/index.d.ts +6 -0
- package/cjs/index.js +25 -11
- package/cjs/liveAudioProcessor.d.ts +92 -0
- package/cjs/liveAudioProcessor.js +269 -0
- package/cjs/liveAudioQueue.d.ts +40 -0
- package/cjs/liveAudioQueue.js +130 -0
- package/cjs/liveAudioWorklet.d.ts +1 -0
- package/cjs/liveAudioWorklet.js +63 -0
- package/cjs/liveBrowserDetector.d.ts +16 -0
- package/cjs/liveBrowserDetector.js +75 -0
- package/cjs/liveBrowserDetectorWorker.d.ts +1 -0
- package/cjs/liveBrowserDetectorWorker.js +72 -0
- package/cjs/liveControlChannel.d.ts +176 -0
- package/cjs/liveControlChannel.js +829 -0
- package/cjs/liveDuplexMedia.d.ts +204 -0
- package/cjs/liveDuplexMedia.js +740 -0
- package/cjs/liveGuideAdmission.d.ts +21 -0
- package/cjs/liveGuideAdmission.js +94 -0
- package/cjs/liveGuideWidget.d.ts +68 -0
- package/cjs/liveGuideWidget.js +451 -0
- package/cjs/liveSpeechAssets.d.ts +36 -0
- package/cjs/liveSpeechAssets.js +39 -0
- package/cjs/liveSpeechCaptureBridge.d.ts +32 -0
- package/cjs/liveSpeechCaptureBridge.js +140 -0
- package/cjs/liveSpeechDetector.d.ts +62 -0
- package/cjs/liveSpeechDetector.js +206 -0
- package/cjs/liveSpeechModel.d.ts +46 -0
- package/cjs/liveSpeechModel.js +105 -0
- package/cjs/liveSpeechResampler.d.ts +22 -0
- package/cjs/liveSpeechResampler.js +93 -0
- package/cjs/liveSpeechWorker.d.ts +56 -0
- package/cjs/liveSpeechWorker.js +143 -0
- package/cjs/locales/resources.js +568 -8
- package/cjs/media.d.ts +11 -0
- package/cjs/media.js +78 -9
- package/cjs/messages.js +22 -8
- package/cjs/pageAssistancePreference.d.ts +15 -3
- package/cjs/pageAssistancePreference.js +46 -7
- package/cjs/preview.d.ts +4 -1
- package/cjs/preview.js +42 -1
- package/cjs/recording.d.ts +12 -0
- package/cjs/recording.js +150 -0
- package/cjs/standalone.d.ts +6 -0
- package/cjs/standalone.js +12 -0
- package/cjs/types.d.ts +31 -5
- package/cjs/types.js +14 -0
- package/cjs/ui.d.ts +128 -4
- package/cjs/ui.js +1918 -276
- package/cjs/version.d.ts +1 -1
- package/cjs/version.js +1 -1
- package/cjs/voicePresenceUi.d.ts +52 -4
- package/cjs/voicePresenceUi.js +659 -57
- package/lib/AiLiveAssist.d.ts +76 -11
- package/lib/AiLiveAssist.js +1772 -299
- package/lib/client.d.ts +19 -0
- package/lib/client.js +51 -0
- package/lib/context.d.ts +23 -1
- package/lib/context.js +713 -126
- package/lib/control.d.ts +2 -0
- package/lib/control.js +42 -3
- package/lib/ctaOffer.d.ts +11 -0
- package/lib/ctaOffer.js +179 -0
- package/lib/dialogFocusScope.js +1 -1
- package/lib/guideAdmission.d.ts +46 -0
- package/lib/guideAdmission.js +392 -0
- package/lib/guideHost.d.ts +47 -0
- package/lib/guideHost.js +42 -0
- package/lib/guideInstallation.d.ts +12 -0
- package/lib/guideInstallation.js +56 -0
- package/lib/guideInstaller.d.ts +4 -0
- package/lib/guideInstaller.js +113 -0
- package/lib/guideMount.d.ts +22 -0
- package/lib/guideMount.js +77 -0
- package/lib/guideRecording.d.ts +64 -0
- package/lib/guideRecording.js +172 -0
- package/lib/guideRecordingSession.d.ts +35 -0
- package/lib/guideRecordingSession.js +163 -0
- package/lib/guideSubjectStore.d.ts +32 -0
- package/lib/guideSubjectStore.js +101 -0
- package/lib/guideTypes.d.ts +117 -0
- package/lib/guideTypes.js +11 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +21 -10
- package/lib/liveAudioProcessor.d.ts +92 -0
- package/lib/liveAudioProcessor.js +265 -0
- package/lib/liveAudioQueue.d.ts +40 -0
- package/lib/liveAudioQueue.js +126 -0
- package/lib/liveAudioWorklet.d.ts +1 -0
- package/lib/liveAudioWorklet.js +61 -0
- package/lib/liveBrowserDetector.d.ts +16 -0
- package/lib/liveBrowserDetector.js +71 -0
- package/lib/liveBrowserDetectorWorker.d.ts +1 -0
- package/lib/liveBrowserDetectorWorker.js +70 -0
- package/lib/liveControlChannel.d.ts +176 -0
- package/lib/liveControlChannel.js +825 -0
- package/lib/liveDuplexMedia.d.ts +204 -0
- package/lib/liveDuplexMedia.js +736 -0
- package/lib/liveGuideAdmission.d.ts +21 -0
- package/lib/liveGuideAdmission.js +90 -0
- package/lib/liveGuideWidget.d.ts +68 -0
- package/lib/liveGuideWidget.js +447 -0
- package/lib/liveSpeechAssets.d.ts +36 -0
- package/lib/liveSpeechAssets.js +35 -0
- package/lib/liveSpeechCaptureBridge.d.ts +32 -0
- package/lib/liveSpeechCaptureBridge.js +136 -0
- package/lib/liveSpeechDetector.d.ts +62 -0
- package/lib/liveSpeechDetector.js +202 -0
- package/lib/liveSpeechModel.d.ts +46 -0
- package/lib/liveSpeechModel.js +101 -0
- package/lib/liveSpeechResampler.d.ts +22 -0
- package/lib/liveSpeechResampler.js +89 -0
- package/lib/liveSpeechWorker.d.ts +56 -0
- package/lib/liveSpeechWorker.js +137 -0
- package/lib/locales/resources.js +568 -8
- package/lib/media.d.ts +11 -0
- package/lib/media.js +77 -8
- package/lib/messages.js +22 -8
- package/lib/pageAssistancePreference.d.ts +15 -3
- package/lib/pageAssistancePreference.js +46 -7
- package/lib/preview.d.ts +4 -1
- package/lib/preview.js +42 -1
- package/lib/recording.d.ts +12 -0
- package/lib/recording.js +146 -0
- package/lib/standalone.d.ts +6 -0
- package/lib/standalone.js +6 -0
- package/lib/types.d.ts +31 -5
- package/lib/types.js +14 -0
- package/lib/ui.d.ts +128 -4
- package/lib/ui.js +1919 -277
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/voicePresenceUi.d.ts +52 -4
- package/lib/voicePresenceUi.js +659 -57
- package/package.json +16 -1
package/cjs/context.js
CHANGED
|
@@ -10,8 +10,16 @@ const MAX_SELECTED_TEXT = 2000;
|
|
|
10
10
|
const SELECTION_RETENTION_MS = 120000;
|
|
11
11
|
const CAPTURE_SETTLE_MS = 250;
|
|
12
12
|
const MUTATION_CAPTURE_DEBOUNCE_MS = 350;
|
|
13
|
+
const SCROLL_SETTLEMENT_TIMEOUT_MS = 2000;
|
|
14
|
+
const SCROLL_SETTLEMENT_FRAME_FALLBACK_MS = 50;
|
|
15
|
+
const SCROLL_SETTLEMENT_POSITION_TOLERANCE_PX = 1;
|
|
16
|
+
const SCROLL_SETTLEMENT_STABLE_MS = 250;
|
|
17
|
+
const MAX_SCROLL_LAYOUT_CORRECTIONS = 3;
|
|
18
|
+
const RELEASED_NAVIGATION_SETTLEMENT_TIMEOUT_MS = 5000;
|
|
19
|
+
const FRAMER_GENERATED_PAGE_SELECTOR = '[data-framer-generated-page]';
|
|
13
20
|
const FRAMER_TOGGLE_ROOT_SELECTOR = '[data-framer-name="Toggle"]';
|
|
14
21
|
const FRAMER_TOGGLE_CONTROL_SELECTOR = 'div[name="Toggle Switch"][data-highlight="true"][tabindex]';
|
|
22
|
+
const ACTIONABLE_MUTATION_SELECTOR = `a[href],button,input,select,textarea,summary,[role="button"],[role="link"],[role="tab"],[role="menuitem"],[role="option"],[role="checkbox"],[role="radio"],[role="switch"],[role="combobox"],[role="listbox"],[role="treeitem"],[role="slider"],[role="spinbutton"],[role="searchbox"],[role="textbox"],${FRAMER_TOGGLE_CONTROL_SELECTOR}`;
|
|
15
23
|
const MAX_FRAMER_TOGGLE_LABEL = 120;
|
|
16
24
|
const PRIVATE_SELECTOR = [
|
|
17
25
|
'[data-oxvo-ai-live-assist-root]',
|
|
@@ -45,6 +53,7 @@ const EXPLICIT_SENSITIVITIES = new Set([
|
|
|
45
53
|
const id = (prefix) => `${prefix}_${crypto.randomUUID()}`;
|
|
46
54
|
// The runtime may rebind only IDs whose navigation identity this collector rotates.
|
|
47
55
|
const BOUND_NAVIGATION_TARGET_PREFIX = 'target_bound';
|
|
56
|
+
const BOUND_FIELD_TARGET_PREFIX = 'target_field';
|
|
48
57
|
const normalize = (value, maximum) => value
|
|
49
58
|
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, '')
|
|
50
59
|
.replace(/\s+/g, ' ')
|
|
@@ -63,16 +72,51 @@ const canonicalJson = (value) => {
|
|
|
63
72
|
};
|
|
64
73
|
return JSON.stringify(sort(value));
|
|
65
74
|
};
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
const navigationTargetBinding = (target) => canonicalJson({
|
|
76
|
+
role: target.role,
|
|
77
|
+
name: target.name,
|
|
78
|
+
inputType: target.inputType ?? null,
|
|
79
|
+
autocomplete: target.autocomplete ?? null,
|
|
80
|
+
semanticRegion: target.semanticRegion ?? null,
|
|
81
|
+
destinationPath: target.destinationPath ?? null,
|
|
82
|
+
sensitivity: target.sensitivity,
|
|
83
|
+
protectedRegion: target.protectedRegion ?? null,
|
|
84
|
+
frameOrigin: target.frameOrigin ?? null,
|
|
85
|
+
consequence: target.consequence ?? null,
|
|
86
|
+
regionAssessment: target.regionAssessment ?? null,
|
|
87
|
+
state: {
|
|
88
|
+
enabled: target.state.enabled,
|
|
89
|
+
...(target.state.checked !== undefined ? { checked: target.state.checked } : {}),
|
|
90
|
+
...(target.state.expanded !== undefined ? { expanded: target.state.expanded } : {}),
|
|
91
|
+
...(target.state.pressed !== undefined ? { pressed: target.state.pressed } : {}),
|
|
92
|
+
},
|
|
93
|
+
options: target.options ?? null,
|
|
94
|
+
});
|
|
95
|
+
const strictlyIntersectsViewport = (rect) => rect.bottom > 0 &&
|
|
96
|
+
rect.right > 0 &&
|
|
97
|
+
rect.top < window.innerHeight &&
|
|
98
|
+
rect.left < window.innerWidth;
|
|
99
|
+
const sameSettledRect = (left, right) => Math.abs(left.top - right.top) <= SCROLL_SETTLEMENT_POSITION_TOLERANCE_PX &&
|
|
100
|
+
Math.abs(left.left - right.left) <= SCROLL_SETTLEMENT_POSITION_TOLERANCE_PX &&
|
|
101
|
+
Math.abs(left.width - right.width) <= SCROLL_SETTLEMENT_POSITION_TOLERANCE_PX &&
|
|
102
|
+
Math.abs(left.height - right.height) <= SCROLL_SETTLEMENT_POSITION_TOLERANCE_PX;
|
|
103
|
+
const nextAnimationFrameOrTimeout = (maximumWaitMs) => new Promise((resolve) => {
|
|
104
|
+
let settled = false;
|
|
105
|
+
let frame = null;
|
|
106
|
+
const finish = () => {
|
|
107
|
+
if (settled)
|
|
108
|
+
return;
|
|
109
|
+
settled = true;
|
|
110
|
+
window.clearTimeout(timeout);
|
|
111
|
+
if (frame !== null)
|
|
112
|
+
window.cancelAnimationFrame(frame);
|
|
113
|
+
resolve();
|
|
73
114
|
};
|
|
74
|
-
|
|
75
|
-
|
|
115
|
+
const timeout = window.setTimeout(finish, maximumWaitMs);
|
|
116
|
+
frame = window.requestAnimationFrame(finish);
|
|
117
|
+
});
|
|
118
|
+
const actionTargetFingerprintBinding = (target) => canonicalJson({
|
|
119
|
+
targetId: target.targetId,
|
|
76
120
|
role: target.role,
|
|
77
121
|
name: target.name,
|
|
78
122
|
inputType: target.inputType ?? null,
|
|
@@ -84,33 +128,16 @@ const navigationTargetBinding = (element, target) => canonicalJson({
|
|
|
84
128
|
frameOrigin: target.frameOrigin ?? null,
|
|
85
129
|
consequence: target.consequence ?? null,
|
|
86
130
|
regionAssessment: target.regionAssessment ?? null,
|
|
87
|
-
state: target.state,
|
|
88
131
|
options: target.options ?? null,
|
|
89
|
-
geometry: navigationTargetGeometry(element),
|
|
90
132
|
});
|
|
91
133
|
const actionTargetFingerprint = async (target, subtle = globalThis.crypto?.subtle) => {
|
|
92
134
|
if (!subtle)
|
|
93
135
|
return null;
|
|
94
136
|
try {
|
|
95
|
-
const
|
|
96
|
-
targetId: target.targetId,
|
|
97
|
-
role: target.role,
|
|
98
|
-
name: target.name,
|
|
99
|
-
inputType: target.inputType ?? null,
|
|
100
|
-
autocomplete: target.autocomplete ?? null,
|
|
101
|
-
semanticRegion: target.semanticRegion ?? null,
|
|
102
|
-
destinationPath: target.destinationPath ?? null,
|
|
103
|
-
sensitivity: target.sensitivity,
|
|
104
|
-
protectedRegion: target.protectedRegion ?? null,
|
|
105
|
-
frameOrigin: target.frameOrigin ?? null,
|
|
106
|
-
consequence: target.consequence ?? null,
|
|
107
|
-
regionAssessment: target.regionAssessment ?? null,
|
|
108
|
-
options: target.options ?? null,
|
|
109
|
-
});
|
|
110
|
-
const digest = new Uint8Array(await subtle.digest('SHA-256', new TextEncoder().encode(canonical)));
|
|
137
|
+
const digest = new Uint8Array(await subtle.digest('SHA-256', new TextEncoder().encode(actionTargetFingerprintBinding(target))));
|
|
111
138
|
if (digest.byteLength !== 32)
|
|
112
139
|
return null;
|
|
113
|
-
return Array.from(digest, byte => byte.toString(16).padStart(2, '0')).join('');
|
|
140
|
+
return Array.from(digest, (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
114
141
|
}
|
|
115
142
|
catch {
|
|
116
143
|
return null;
|
|
@@ -161,6 +188,14 @@ const isCovered = (element, trustedGuideRoot = null) => {
|
|
|
161
188
|
return Boolean(top && top !== element && !element.contains(top) && !top.contains(element));
|
|
162
189
|
};
|
|
163
190
|
const safePageUrl = () => `${window.location.origin}${window.location.pathname}`;
|
|
191
|
+
const linkBrowsingTarget = (link) => (link.getAttribute('target') ?? document.querySelector('base[target]')?.getAttribute('target') ?? '').toLowerCase();
|
|
192
|
+
const supportsCurrentTabNavigation = (link) => ['', '_self', '_blank'].includes(linkBrowsingTarget(link)) && !link.hasAttribute('download');
|
|
193
|
+
// Navigation authority is bound to the same-origin, query-free path. Routers
|
|
194
|
+
// may add a section fragment on arrival; that is not a different page.
|
|
195
|
+
const sameNavigationDestination = (actual, expected) => {
|
|
196
|
+
const left = new URL(actual), right = new URL(expected);
|
|
197
|
+
return left.origin === right.origin && left.pathname === right.pathname && left.search === right.search;
|
|
198
|
+
};
|
|
164
199
|
const safeDestinationPath = (element) => {
|
|
165
200
|
if (!(element instanceof HTMLAnchorElement))
|
|
166
201
|
return null;
|
|
@@ -280,7 +315,8 @@ const nameFor = (element) => {
|
|
|
280
315
|
return normalize(semanticName ||
|
|
281
316
|
associatedLabel ||
|
|
282
317
|
attributeName ||
|
|
283
|
-
(buttonValue && sensitivityFor(element, buttonValue) === 'none' ? buttonValue : '')
|
|
318
|
+
(buttonValue && sensitivityFor(element, buttonValue) === 'none' ? buttonValue : '') ||
|
|
319
|
+
(safeDestinationPath(element) === '/' ? 'Home' : ''), 300);
|
|
284
320
|
};
|
|
285
321
|
const safeDescendantText = (element, maximum, renderedOnly = false) => {
|
|
286
322
|
const parts = [];
|
|
@@ -408,13 +444,21 @@ const checkedStateFor = (element) => {
|
|
|
408
444
|
}
|
|
409
445
|
return framerToggleDescriptor(element)?.checked;
|
|
410
446
|
};
|
|
411
|
-
const
|
|
412
|
-
if (
|
|
413
|
-
throw new Error('Framer
|
|
447
|
+
const dispatchFramerPrimaryPointerSequence = (element) => {
|
|
448
|
+
if (typeof window.PointerEvent !== 'function') {
|
|
449
|
+
throw new Error('Framer pointer interaction is unavailable.');
|
|
414
450
|
}
|
|
415
451
|
const rect = element.getBoundingClientRect();
|
|
416
452
|
const clientX = rect.left + rect.width / 2;
|
|
417
453
|
const clientY = rect.top + rect.height / 2;
|
|
454
|
+
const hit = document.elementFromPoint(clientX, clientY);
|
|
455
|
+
const eventTarget = element instanceof HTMLAnchorElement && hit && element.contains(hit) ? hit : element;
|
|
456
|
+
const nestedLink = eventTarget.closest('a[href]');
|
|
457
|
+
if (element instanceof HTMLAnchorElement && nestedLink instanceof HTMLAnchorElement && nestedLink !== element &&
|
|
458
|
+
(!sameNavigationDestination(nestedLink.href, element.href) || nestedLink.hasAttribute('download') ||
|
|
459
|
+
(nestedLink.target && nestedLink.target.toLowerCase() !== '_self'))) {
|
|
460
|
+
throw new Error('The nested navigation destination does not match the approved link.');
|
|
461
|
+
}
|
|
418
462
|
const shared = {
|
|
419
463
|
view: window,
|
|
420
464
|
bubbles: true,
|
|
@@ -424,7 +468,7 @@ const dispatchFramerTogglePrimaryPointer = (element) => {
|
|
|
424
468
|
clientY,
|
|
425
469
|
};
|
|
426
470
|
const pointer = (type, init) => {
|
|
427
|
-
|
|
471
|
+
eventTarget.dispatchEvent(new window.PointerEvent(type, {
|
|
428
472
|
...shared,
|
|
429
473
|
pointerId: 1,
|
|
430
474
|
pointerType: 'mouse',
|
|
@@ -435,10 +479,10 @@ const dispatchFramerTogglePrimaryPointer = (element) => {
|
|
|
435
479
|
}));
|
|
436
480
|
};
|
|
437
481
|
const mouse = (type, init) => {
|
|
438
|
-
|
|
482
|
+
eventTarget.dispatchEvent(new MouseEvent(type, { ...shared, ...init }));
|
|
439
483
|
};
|
|
440
484
|
pointer('pointerover', { button: -1, buttons: 0 });
|
|
441
|
-
|
|
485
|
+
eventTarget.dispatchEvent(new window.PointerEvent('pointerenter', {
|
|
442
486
|
...shared,
|
|
443
487
|
bubbles: false,
|
|
444
488
|
cancelable: false,
|
|
@@ -451,7 +495,7 @@ const dispatchFramerTogglePrimaryPointer = (element) => {
|
|
|
451
495
|
buttons: 0,
|
|
452
496
|
}));
|
|
453
497
|
mouse('mouseover', { button: 0, buttons: 0, detail: 0 });
|
|
454
|
-
|
|
498
|
+
eventTarget.dispatchEvent(new MouseEvent('mouseenter', {
|
|
455
499
|
...shared,
|
|
456
500
|
bubbles: false,
|
|
457
501
|
cancelable: false,
|
|
@@ -468,7 +512,7 @@ const dispatchFramerTogglePrimaryPointer = (element) => {
|
|
|
468
512
|
mouse('mouseup', { button: 0, buttons: 0, detail: 1 });
|
|
469
513
|
// Chromium's trusted mouse sequence keeps pointerId 1 on click but reports
|
|
470
514
|
// isPrimary false; these fields are trace-bound rather than normalized.
|
|
471
|
-
|
|
515
|
+
eventTarget.dispatchEvent(new window.PointerEvent('click', {
|
|
472
516
|
...shared,
|
|
473
517
|
pointerId: 1,
|
|
474
518
|
pointerType: 'mouse',
|
|
@@ -480,6 +524,12 @@ const dispatchFramerTogglePrimaryPointer = (element) => {
|
|
|
480
524
|
detail: 1,
|
|
481
525
|
}));
|
|
482
526
|
};
|
|
527
|
+
const dispatchFramerTogglePrimaryPointer = (element) => {
|
|
528
|
+
if (!framerToggleDescriptor(element)) {
|
|
529
|
+
throw new Error('Framer toggle pointer interaction is unavailable.');
|
|
530
|
+
}
|
|
531
|
+
dispatchFramerPrimaryPointerSequence(element);
|
|
532
|
+
};
|
|
483
533
|
const semanticSourceSensitivity = (source) => {
|
|
484
534
|
if (source.closest(PRIVATE_SELECTOR) || source.querySelector(PRIVATE_SELECTOR)) {
|
|
485
535
|
return 'private';
|
|
@@ -554,6 +604,13 @@ const isReadOnlyTextControl = (element) => (element instanceof HTMLInputElement
|
|
|
554
604
|
READONLY_INPUT_TYPES.has(element.type) &&
|
|
555
605
|
element.readOnly) ||
|
|
556
606
|
(element instanceof HTMLTextAreaElement && element.readOnly);
|
|
607
|
+
const isNativeEditableField = (element) => element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement ||
|
|
608
|
+
(element instanceof HTMLInputElement && ['text', 'search', 'email', 'tel', 'url', 'number'].includes(element.type));
|
|
609
|
+
// Private, in-memory only. A visitor edit rotates the opaque ID; field values
|
|
610
|
+
// are never added to the sanitized snapshot or sent to the runtime.
|
|
611
|
+
const localFieldValue = (element) => element instanceof HTMLSelectElement
|
|
612
|
+
? JSON.stringify(Array.from(element.options).filter(option => option.selected).map(option => option.index))
|
|
613
|
+
: element.value;
|
|
557
614
|
const enabled = (element) => {
|
|
558
615
|
if (element.getAttribute('aria-disabled') === 'true' ||
|
|
559
616
|
element.getAttribute('aria-readonly') === 'true' ||
|
|
@@ -642,7 +699,10 @@ class PageContextCollector {
|
|
|
642
699
|
this.captureTimer = null;
|
|
643
700
|
this.mutationCaptureTimer = null;
|
|
644
701
|
this.targetIds = new WeakMap();
|
|
702
|
+
this.pageScrollIds = new WeakMap();
|
|
645
703
|
this.navigationTargetBindings = new WeakMap();
|
|
704
|
+
this.fieldTargetBindings = new WeakMap();
|
|
705
|
+
this.fieldAppliedRevisions = new WeakMap();
|
|
646
706
|
this.textIds = new WeakMap();
|
|
647
707
|
this.optionIds = new WeakMap();
|
|
648
708
|
this.targets = new Map();
|
|
@@ -652,6 +712,8 @@ class PageContextCollector {
|
|
|
652
712
|
this.pendingNavigation = null;
|
|
653
713
|
this.pendingCapture = false;
|
|
654
714
|
this.deferredNavigation = null;
|
|
715
|
+
this.releasedNavigation = null;
|
|
716
|
+
this.releasedNavigationSettlement = null;
|
|
655
717
|
this.navigationSettlementGeneration = 0;
|
|
656
718
|
this.navigationSettlement = null;
|
|
657
719
|
this.recentSelection = null;
|
|
@@ -692,9 +754,48 @@ class PageContextCollector {
|
|
|
692
754
|
this.scheduleViewportCapture = () => {
|
|
693
755
|
this.scheduleMutationCapture();
|
|
694
756
|
};
|
|
757
|
+
this.mutationNodeIsInsideTrustedGuide = (node) => Boolean(this.trustedGuideRoot &&
|
|
758
|
+
(node === this.trustedGuideRoot || this.trustedGuideRoot.contains(node)));
|
|
759
|
+
this.mutationIsInsideTrustedGuide = (record) => {
|
|
760
|
+
if (this.mutationNodeIsInsideTrustedGuide(record.target))
|
|
761
|
+
return true;
|
|
762
|
+
if (record.type !== 'childList')
|
|
763
|
+
return false;
|
|
764
|
+
const changedNodes = [...record.addedNodes, ...record.removedNodes];
|
|
765
|
+
return (changedNodes.length > 0 &&
|
|
766
|
+
changedNodes.every(this.mutationNodeIsInsideTrustedGuide));
|
|
767
|
+
};
|
|
768
|
+
this.mutationNodeTouchesSemanticContext = (node) => {
|
|
769
|
+
const element = node instanceof Element
|
|
770
|
+
? node
|
|
771
|
+
: node.nodeType === Node.TEXT_NODE
|
|
772
|
+
? node.parentElement
|
|
773
|
+
: null;
|
|
774
|
+
return Boolean(element &&
|
|
775
|
+
(element.matches(ACTIONABLE_MUTATION_SELECTOR) ||
|
|
776
|
+
element.closest(ACTIONABLE_MUTATION_SELECTOR)));
|
|
777
|
+
};
|
|
778
|
+
this.mutationNodeContainsSemanticContext = (node) => this.mutationNodeTouchesSemanticContext(node) ||
|
|
779
|
+
Boolean(node instanceof Element &&
|
|
780
|
+
node.querySelector(ACTIONABLE_MUTATION_SELECTOR));
|
|
781
|
+
this.mutationNeedsImmediateCapture = (record) => {
|
|
782
|
+
if (record.type === 'attributes') {
|
|
783
|
+
if (record.attributeName === 'class' || record.attributeName === 'style') {
|
|
784
|
+
return false;
|
|
785
|
+
}
|
|
786
|
+
return this.mutationNodeTouchesSemanticContext(record.target);
|
|
787
|
+
}
|
|
788
|
+
if (this.mutationNodeTouchesSemanticContext(record.target))
|
|
789
|
+
return true;
|
|
790
|
+
if (record.type !== 'childList')
|
|
791
|
+
return false;
|
|
792
|
+
return [...record.addedNodes, ...record.removedNodes].some(this.mutationNodeContainsSemanticContext);
|
|
793
|
+
};
|
|
695
794
|
this.handleMutations = (records) => {
|
|
696
|
-
const
|
|
697
|
-
|
|
795
|
+
const relevantRecords = records.filter((record) => !this.mutationIsInsideTrustedGuide(record));
|
|
796
|
+
if (relevantRecords.length === 0)
|
|
797
|
+
return;
|
|
798
|
+
const hasSemanticMutation = relevantRecords.some(this.mutationNeedsImmediateCapture);
|
|
698
799
|
if (hasSemanticMutation)
|
|
699
800
|
this.scheduleCapture();
|
|
700
801
|
else
|
|
@@ -715,7 +816,21 @@ class PageContextCollector {
|
|
|
715
816
|
this.handleNavigation = () => {
|
|
716
817
|
if (!this.running)
|
|
717
818
|
return;
|
|
819
|
+
this.callbacks.onHighlight(null, 'focus');
|
|
820
|
+
this.releasedNavigation = null;
|
|
718
821
|
const currentUrl = safePageUrl();
|
|
822
|
+
if (this.captureTimer)
|
|
823
|
+
clearTimeout(this.captureTimer);
|
|
824
|
+
this.captureTimer = null;
|
|
825
|
+
if (this.mutationCaptureTimer)
|
|
826
|
+
clearTimeout(this.mutationCaptureTimer);
|
|
827
|
+
this.mutationCaptureTimer = null;
|
|
828
|
+
if (this.releasedNavigationSettlement &&
|
|
829
|
+
window.location.href !== this.releasedNavigationSettlement.fromUrl) {
|
|
830
|
+
this.finishReleasedNavigationSettlement(sameNavigationDestination(window.location.href, this.releasedNavigationSettlement.toUrl)
|
|
831
|
+
? 'settled'
|
|
832
|
+
: 'rejected');
|
|
833
|
+
}
|
|
719
834
|
if (this.executingActionId &&
|
|
720
835
|
this.pendingNavigation?.causalActionId === this.executingActionId &&
|
|
721
836
|
this.pendingNavigation.url === currentUrl) {
|
|
@@ -765,6 +880,7 @@ class PageContextCollector {
|
|
|
765
880
|
const handle = this.targets.get(targetId);
|
|
766
881
|
if (revision !== this.revision ||
|
|
767
882
|
!handle ||
|
|
883
|
+
handle.pageScroll ||
|
|
768
884
|
handle.revision !== revision ||
|
|
769
885
|
!handle.element.isConnected) {
|
|
770
886
|
return null;
|
|
@@ -812,7 +928,9 @@ class PageContextCollector {
|
|
|
812
928
|
],
|
|
813
929
|
});
|
|
814
930
|
}
|
|
815
|
-
window.addEventListener('resize', this.scheduleViewportCapture, {
|
|
931
|
+
window.addEventListener('resize', this.scheduleViewportCapture, {
|
|
932
|
+
passive: true,
|
|
933
|
+
});
|
|
816
934
|
document.addEventListener('scroll', this.scheduleViewportCapture, {
|
|
817
935
|
capture: true,
|
|
818
936
|
passive: true,
|
|
@@ -855,6 +973,8 @@ class PageContextCollector {
|
|
|
855
973
|
this.pendingNavigation = null;
|
|
856
974
|
this.pendingCapture = false;
|
|
857
975
|
this.deferredNavigation = null;
|
|
976
|
+
this.releasedNavigation = null;
|
|
977
|
+
this.finishReleasedNavigationSettlement('rejected');
|
|
858
978
|
this.navigationSettlementGeneration += 1;
|
|
859
979
|
this.navigationSettlement = null;
|
|
860
980
|
this.recentSelection = null;
|
|
@@ -877,6 +997,7 @@ class PageContextCollector {
|
|
|
877
997
|
const revision = this.revision + 1;
|
|
878
998
|
const nextTargets = new Map();
|
|
879
999
|
const targetValues = [];
|
|
1000
|
+
this.capturePageScrollTargets(revision, nextTargets, targetValues);
|
|
880
1001
|
const elements = document.querySelectorAll('a[href],button,input,select,textarea,summary,form,[contenteditable="true"],[role],[tabindex]');
|
|
881
1002
|
let truncated = false;
|
|
882
1003
|
for (const element of elements) {
|
|
@@ -918,22 +1039,7 @@ class PageContextCollector {
|
|
|
918
1039
|
});
|
|
919
1040
|
}
|
|
920
1041
|
const semanticRegion = normalize(element.closest('[data-oxvo-ai-region]')?.getAttribute('data-oxvo-ai-region') ?? '', 128);
|
|
921
|
-
const
|
|
922
|
-
const matchedRuleDigests = [];
|
|
923
|
-
for (const rule of this.selectorRegionRules.slice(0, 100)) {
|
|
924
|
-
if (!/^[0-9a-f]{64}$/.test(rule.digest) || rule.selector.length > 256) {
|
|
925
|
-
continue;
|
|
926
|
-
}
|
|
927
|
-
try {
|
|
928
|
-
const matched = element.matches(rule.selector) || Boolean(element.closest(rule.selector));
|
|
929
|
-
evaluatedRuleDigests.push(rule.digest);
|
|
930
|
-
if (matched)
|
|
931
|
-
matchedRuleDigests.push(rule.digest);
|
|
932
|
-
}
|
|
933
|
-
catch {
|
|
934
|
-
// Invalid tenant selectors remain unevaluated so server policy fails closed.
|
|
935
|
-
}
|
|
936
|
-
}
|
|
1042
|
+
const regionAssessment = this.assessSelectorRegions(element);
|
|
937
1043
|
const directSensitivity = sensitivityFor(element, name);
|
|
938
1044
|
const sensitivity = directSensitivity !== 'none'
|
|
939
1045
|
? directSensitivity
|
|
@@ -950,19 +1056,17 @@ class PageContextCollector {
|
|
|
950
1056
|
? { inputType: normalize(element.type, 32) }
|
|
951
1057
|
: {}),
|
|
952
1058
|
...(element.getAttribute('autocomplete')
|
|
953
|
-
? {
|
|
1059
|
+
? {
|
|
1060
|
+
autocomplete: normalize(element.getAttribute('autocomplete') ?? '', 128),
|
|
1061
|
+
}
|
|
954
1062
|
: {}),
|
|
955
1063
|
...(semanticRegion ? { semanticRegion } : {}),
|
|
956
1064
|
...(destinationPath ? { destinationPath } : {}),
|
|
957
1065
|
sensitivity,
|
|
958
|
-
protectedRegion: sensitivity !== 'none' || matchedRuleDigests.length > 0,
|
|
1066
|
+
protectedRegion: sensitivity !== 'none' || regionAssessment.matchedRuleDigests.length > 0,
|
|
959
1067
|
frameOrigin: 'same_origin',
|
|
960
1068
|
consequence: consequenceFor(element, role, name),
|
|
961
|
-
regionAssessment
|
|
962
|
-
policyVersion: this.policyVersion,
|
|
963
|
-
evaluatedRuleDigests,
|
|
964
|
-
matchedRuleDigests,
|
|
965
|
-
},
|
|
1069
|
+
regionAssessment,
|
|
966
1070
|
state: {
|
|
967
1071
|
visible,
|
|
968
1072
|
enabled: enabled(element),
|
|
@@ -976,31 +1080,52 @@ class PageContextCollector {
|
|
|
976
1080
|
const priorTargetId = this.targetIds.get(element);
|
|
977
1081
|
const boundNavigation = targetIdentity.consequence === 'navigation' &&
|
|
978
1082
|
typeof targetIdentity.destinationPath === 'string';
|
|
979
|
-
const binding = boundNavigation
|
|
980
|
-
? navigationTargetBinding(element, targetIdentity)
|
|
981
|
-
: null;
|
|
1083
|
+
const binding = boundNavigation ? navigationTargetBinding(targetIdentity) : null;
|
|
982
1084
|
const priorBinding = this.navigationTargetBindings.get(element);
|
|
1085
|
+
const boundField = isNativeEditableField(element) && sensitivity === 'none' &&
|
|
1086
|
+
targetIdentity.protectedRegion === false && targetIdentity.consequence === 'none';
|
|
1087
|
+
const fieldBinding = boundField ? {
|
|
1088
|
+
identity: canonicalJson({ target: navigationTargetBinding(targetIdentity), name: element.name }),
|
|
1089
|
+
value: localFieldValue(element), form: element.form,
|
|
1090
|
+
} : null;
|
|
1091
|
+
const priorFieldBinding = this.fieldTargetBindings.get(element);
|
|
983
1092
|
const targetId = binding
|
|
984
1093
|
? priorTargetId?.startsWith(`${BOUND_NAVIGATION_TARGET_PREFIX}_`) &&
|
|
985
1094
|
priorBinding === binding
|
|
986
1095
|
? priorTargetId
|
|
987
1096
|
: id(BOUND_NAVIGATION_TARGET_PREFIX)
|
|
988
|
-
:
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1097
|
+
: fieldBinding
|
|
1098
|
+
? priorTargetId?.startsWith(`${BOUND_FIELD_TARGET_PREFIX}_`) &&
|
|
1099
|
+
priorFieldBinding?.identity === fieldBinding.identity && priorFieldBinding.value === fieldBinding.value &&
|
|
1100
|
+
priorFieldBinding.form === fieldBinding.form
|
|
1101
|
+
? priorTargetId
|
|
1102
|
+
: id(BOUND_FIELD_TARGET_PREFIX)
|
|
1103
|
+
: priorTargetId &&
|
|
1104
|
+
!priorTargetId.startsWith(`${BOUND_NAVIGATION_TARGET_PREFIX}_`) &&
|
|
1105
|
+
!priorTargetId.startsWith(`${BOUND_FIELD_TARGET_PREFIX}_`)
|
|
1106
|
+
? priorTargetId
|
|
1107
|
+
: id('target');
|
|
992
1108
|
this.targetIds.set(element, targetId);
|
|
993
1109
|
if (binding)
|
|
994
1110
|
this.navigationTargetBindings.set(element, binding);
|
|
995
1111
|
else
|
|
996
1112
|
this.navigationTargetBindings.delete(element);
|
|
1113
|
+
if (fieldBinding)
|
|
1114
|
+
this.fieldTargetBindings.set(element, fieldBinding);
|
|
1115
|
+
else
|
|
1116
|
+
this.fieldTargetBindings.delete(element);
|
|
997
1117
|
const target = {
|
|
998
1118
|
targetId,
|
|
999
1119
|
revision,
|
|
1000
1120
|
...targetIdentity,
|
|
1001
1121
|
};
|
|
1002
1122
|
targetValues.push(target);
|
|
1003
|
-
nextTargets.set(targetId, {
|
|
1123
|
+
nextTargets.set(targetId, {
|
|
1124
|
+
element,
|
|
1125
|
+
revision,
|
|
1126
|
+
options: optionMap,
|
|
1127
|
+
target,
|
|
1128
|
+
});
|
|
1004
1129
|
}
|
|
1005
1130
|
const visibleText = [];
|
|
1006
1131
|
let totalText = 0;
|
|
@@ -1069,6 +1194,61 @@ class PageContextCollector {
|
|
|
1069
1194
|
this.latestSemanticSignature = signature;
|
|
1070
1195
|
return snapshot;
|
|
1071
1196
|
}
|
|
1197
|
+
assessSelectorRegions(element, root = null) {
|
|
1198
|
+
const evaluatedRuleDigests = [];
|
|
1199
|
+
const matchedRuleDigests = [];
|
|
1200
|
+
for (const rule of this.selectorRegionRules.slice(0, 100)) {
|
|
1201
|
+
if (!/^[0-9a-f]{64}$/.test(rule.digest) || rule.selector.length > 256)
|
|
1202
|
+
continue;
|
|
1203
|
+
try {
|
|
1204
|
+
const matched = [element, root].some(node => node && (node.matches(rule.selector) || Boolean(node.closest(rule.selector))));
|
|
1205
|
+
evaluatedRuleDigests.push(rule.digest);
|
|
1206
|
+
if (matched)
|
|
1207
|
+
matchedRuleDigests.push(rule.digest);
|
|
1208
|
+
}
|
|
1209
|
+
catch {
|
|
1210
|
+
// Invalid tenant selectors remain unevaluated so server policy fails closed.
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
return { policyVersion: this.policyVersion, evaluatedRuleDigests, matchedRuleDigests };
|
|
1214
|
+
}
|
|
1215
|
+
pageScrollAvailable(element) {
|
|
1216
|
+
return element === document.scrollingElement && isRendered(element) &&
|
|
1217
|
+
!document.body?.closest(PRIVATE_SELECTOR) &&
|
|
1218
|
+
![element, document.body].some((node) => node &&
|
|
1219
|
+
['hidden', 'clip'].includes(window.getComputedStyle(node).overflowY));
|
|
1220
|
+
}
|
|
1221
|
+
capturePageScrollTargets(revision, handles, targets) {
|
|
1222
|
+
const element = document.scrollingElement;
|
|
1223
|
+
if (!element || element.clientHeight <= 0 || element.scrollHeight <= element.clientHeight)
|
|
1224
|
+
return;
|
|
1225
|
+
// Native viewport controls use the existing bound action protocol. They are
|
|
1226
|
+
// not DOM buttons, never collect page text, and can execute only scrolling.
|
|
1227
|
+
const ids = this.pageScrollIds.get(element) ?? {
|
|
1228
|
+
up: id('target_page_scroll_up'), down: id('target_page_scroll_down'),
|
|
1229
|
+
};
|
|
1230
|
+
this.pageScrollIds.set(element, ids);
|
|
1231
|
+
const regionAssessment = this.assessSelectorRegions(element, document.body);
|
|
1232
|
+
const semanticRegion = normalize((document.body ?? element).closest('[data-oxvo-ai-region]')?.getAttribute('data-oxvo-ai-region') ?? '', 128);
|
|
1233
|
+
const available = this.pageScrollAvailable(element);
|
|
1234
|
+
for (const direction of ['up', 'down']) {
|
|
1235
|
+
const target = {
|
|
1236
|
+
targetId: ids[direction], revision,
|
|
1237
|
+
role: 'scrollbar', name: `Scroll page ${direction}`,
|
|
1238
|
+
sensitivity: 'none', protectedRegion: regionAssessment.matchedRuleDigests.length > 0,
|
|
1239
|
+
frameOrigin: 'same_origin', consequence: 'none', regionAssessment,
|
|
1240
|
+
...(semanticRegion ? { semanticRegion } : {}),
|
|
1241
|
+
state: {
|
|
1242
|
+
visible: true, covered: false,
|
|
1243
|
+
enabled: available && (direction === 'up'
|
|
1244
|
+
? window.scrollY > SCROLL_SETTLEMENT_POSITION_TOLERANCE_PX
|
|
1245
|
+
: window.scrollY < element.scrollHeight - element.clientHeight - SCROLL_SETTLEMENT_POSITION_TOLERANCE_PX),
|
|
1246
|
+
},
|
|
1247
|
+
};
|
|
1248
|
+
targets.push(target);
|
|
1249
|
+
handles.set(target.targetId, { element, revision, options: new Map(), target, pageScroll: direction });
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1072
1252
|
captureVisualContext() {
|
|
1073
1253
|
if (this.navigationSettlement)
|
|
1074
1254
|
return null;
|
|
@@ -1078,6 +1258,8 @@ class PageContextCollector {
|
|
|
1078
1258
|
const viewportHeight = Math.max(1, Math.round(window.innerHeight));
|
|
1079
1259
|
const regions = [];
|
|
1080
1260
|
for (const handle of this.targets.values()) {
|
|
1261
|
+
if (handle.pageScroll)
|
|
1262
|
+
continue;
|
|
1081
1263
|
const rect = handle.element.getBoundingClientRect();
|
|
1082
1264
|
const geometry = this.clippedGeometry(rect, viewportWidth, viewportHeight);
|
|
1083
1265
|
if (!geometry)
|
|
@@ -1144,22 +1326,36 @@ class PageContextCollector {
|
|
|
1144
1326
|
const initialStale = executionStale();
|
|
1145
1327
|
if (initialStale)
|
|
1146
1328
|
return initialStale;
|
|
1147
|
-
this.captureSnapshot(false);
|
|
1329
|
+
let preparationSnapshot = this.captureSnapshot(false);
|
|
1330
|
+
// An execute-time refresh must reach the runtime even when this grant is
|
|
1331
|
+
// rejected. Otherwise later captures see no change and retries keep using
|
|
1332
|
+
// the snapshot that just became stale.
|
|
1333
|
+
const publishRejectedContext = async () => {
|
|
1334
|
+
if (preparationSnapshot && this.running && authorityIsCurrent()) {
|
|
1335
|
+
await this.callbacks.onSnapshot(preparationSnapshot);
|
|
1336
|
+
}
|
|
1337
|
+
};
|
|
1148
1338
|
let handle = this.targets.get(grant.targetId);
|
|
1149
|
-
const
|
|
1339
|
+
const stableField = (current) => (grant.action === 'type' || grant.action === 'select') &&
|
|
1340
|
+
grant.targetId.startsWith(`${BOUND_FIELD_TARGET_PREFIX}_`) &&
|
|
1341
|
+
Boolean(current && isNativeEditableField(current.element) && this.fieldTargetBindings.has(current.element));
|
|
1342
|
+
const stablePageScroll = (current) => grant.action === 'scroll' && Boolean(current?.pageScroll && current.element === document.scrollingElement);
|
|
1343
|
+
const revisionMatchesOrStableTarget = () => grant.domRevision === this.revision ||
|
|
1150
1344
|
(grant.domRevision < this.revision &&
|
|
1151
|
-
grant.action === 'click' &&
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1345
|
+
(stableField(handle) || stablePageScroll(handle) || ((grant.action === 'click' || grant.action === 'scroll') &&
|
|
1346
|
+
handle?.element instanceof HTMLAnchorElement &&
|
|
1347
|
+
handle.target.consequence === 'navigation' &&
|
|
1348
|
+
typeof handle.target.destinationPath === 'string')));
|
|
1155
1349
|
if (expiresAt <= Date.now() ||
|
|
1156
1350
|
grant.pageId !== this.pageId ||
|
|
1157
1351
|
grant.pageUrl !== safePageUrl() ||
|
|
1158
1352
|
grant.policyVersion !== this.policyVersion ||
|
|
1159
|
-
!
|
|
1353
|
+
!revisionMatchesOrStableTarget() ||
|
|
1160
1354
|
!handle ||
|
|
1161
1355
|
handle.revision !== this.revision ||
|
|
1356
|
+
grant.domRevision < (this.fieldAppliedRevisions.get(handle.element) ?? 0) ||
|
|
1162
1357
|
!handle.element.isConnected) {
|
|
1358
|
+
await publishRejectedContext();
|
|
1163
1359
|
return {
|
|
1164
1360
|
...base,
|
|
1165
1361
|
status: 'stale',
|
|
@@ -1174,20 +1370,26 @@ class PageContextCollector {
|
|
|
1174
1370
|
const fingerprintedHandle = handle;
|
|
1175
1371
|
const fingerprint = await (0, exports.actionTargetFingerprint)(handle.target);
|
|
1176
1372
|
const postFingerprintStale = executionStale();
|
|
1177
|
-
if (postFingerprintStale)
|
|
1373
|
+
if (postFingerprintStale) {
|
|
1374
|
+
await publishRejectedContext();
|
|
1178
1375
|
return postFingerprintStale;
|
|
1179
|
-
|
|
1376
|
+
}
|
|
1377
|
+
preparationSnapshot = this.captureSnapshot(false) ?? preparationSnapshot;
|
|
1180
1378
|
handle = this.targets.get(grant.targetId);
|
|
1181
1379
|
if (!fingerprint ||
|
|
1182
1380
|
fingerprint !== grant.targetFingerprint ||
|
|
1183
1381
|
grant.pageId !== this.pageId ||
|
|
1184
1382
|
grant.pageUrl !== safePageUrl() ||
|
|
1185
1383
|
grant.policyVersion !== this.policyVersion ||
|
|
1186
|
-
!
|
|
1187
|
-
handle !== fingerprintedHandle ||
|
|
1384
|
+
!revisionMatchesOrStableTarget() ||
|
|
1385
|
+
(handle !== fingerprintedHandle && !((stableField(handle) || stablePageScroll(handle)) &&
|
|
1386
|
+
handle?.element === fingerprintedHandle.element &&
|
|
1387
|
+
actionTargetFingerprintBinding(handle.target) === actionTargetFingerprintBinding(fingerprintedHandle.target))) ||
|
|
1188
1388
|
!handle ||
|
|
1189
1389
|
handle.revision !== this.revision ||
|
|
1390
|
+
grant.domRevision < (this.fieldAppliedRevisions.get(handle.element) ?? 0) ||
|
|
1190
1391
|
!handle.element.isConnected) {
|
|
1392
|
+
await publishRejectedContext();
|
|
1191
1393
|
return {
|
|
1192
1394
|
...base,
|
|
1193
1395
|
status: 'stale',
|
|
@@ -1200,11 +1402,12 @@ class PageContextCollector {
|
|
|
1200
1402
|
};
|
|
1201
1403
|
}
|
|
1202
1404
|
const element = handle.element;
|
|
1203
|
-
const sensitivity = sensitivityFor(element, nameFor(element));
|
|
1405
|
+
const sensitivity = sensitivityFor(element, handle.pageScroll ? '' : nameFor(element));
|
|
1204
1406
|
const canRevealDesiredStateTarget = grant.action === 'click' &&
|
|
1205
1407
|
grant.desiredChecked !== undefined &&
|
|
1206
1408
|
checkedStateFor(element) !== undefined;
|
|
1207
1409
|
if (sensitivity !== 'none' ||
|
|
1410
|
+
(handle.pageScroll && (grant.action !== 'scroll' || !handle.target.state.enabled)) ||
|
|
1208
1411
|
handle.target.protectedRegion !== false ||
|
|
1209
1412
|
!isRendered(element) ||
|
|
1210
1413
|
(grant.action !== 'scroll' && !isVisible(element) && !canRevealDesiredStateTarget) ||
|
|
@@ -1212,6 +1415,7 @@ class PageContextCollector {
|
|
|
1212
1415
|
(grant.action !== 'scroll' &&
|
|
1213
1416
|
isVisible(element) &&
|
|
1214
1417
|
isCovered(element, this.trustedGuideRoot))) {
|
|
1418
|
+
await publishRejectedContext();
|
|
1215
1419
|
return {
|
|
1216
1420
|
...base,
|
|
1217
1421
|
status: 'blocked',
|
|
@@ -1251,22 +1455,121 @@ class PageContextCollector {
|
|
|
1251
1455
|
if (preHighlightStale)
|
|
1252
1456
|
return preHighlightStale;
|
|
1253
1457
|
const before = this.safeState(element);
|
|
1458
|
+
const scrollStartY = window.scrollY;
|
|
1254
1459
|
const beforeActionUrl = safePageUrl();
|
|
1255
|
-
|
|
1460
|
+
if (grant.action !== 'scroll')
|
|
1461
|
+
this.callbacks.onHighlight(element, 'focus');
|
|
1256
1462
|
const preMutationStale = executionStale();
|
|
1257
1463
|
if (preMutationStale)
|
|
1258
1464
|
return preMutationStale;
|
|
1259
1465
|
this.executingActionId = grant.actionId;
|
|
1260
1466
|
this.pendingCapture = false;
|
|
1261
1467
|
this.deferredNavigation = null;
|
|
1468
|
+
this.releasedNavigation = null;
|
|
1469
|
+
this.finishReleasedNavigationSettlement('rejected');
|
|
1470
|
+
let postActionSnapshot = null;
|
|
1262
1471
|
try {
|
|
1263
1472
|
switch (grant.action) {
|
|
1264
|
-
case 'scroll':
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1473
|
+
case 'scroll': {
|
|
1474
|
+
if (handle.pageScroll) {
|
|
1475
|
+
const direction = handle.pageScroll === 'down' ? 1 : -1;
|
|
1476
|
+
const top = Math.max(0, Math.min(element.scrollHeight - element.clientHeight, scrollStartY + direction * Math.max(1, Math.floor(window.innerHeight * 0.75))));
|
|
1477
|
+
try {
|
|
1478
|
+
window.scrollTo({ left: window.scrollX, top, behavior: 'instant' });
|
|
1479
|
+
}
|
|
1480
|
+
catch {
|
|
1481
|
+
window.scrollTo({ left: window.scrollX, top, behavior: 'auto' });
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
else {
|
|
1485
|
+
this.scrollTargetIntoView(element);
|
|
1486
|
+
}
|
|
1487
|
+
const settlement = await this.waitForScrollSettlement(grant, handle, expiresAt, executionStale, scrollStartY);
|
|
1488
|
+
if (settlement.status === 'stale')
|
|
1489
|
+
return settlement.result;
|
|
1490
|
+
if (settlement.status === 'target_changed') {
|
|
1491
|
+
this.callbacks.onHighlight(null, 'failure');
|
|
1492
|
+
return {
|
|
1493
|
+
...base,
|
|
1494
|
+
status: 'stale',
|
|
1495
|
+
observed: {
|
|
1496
|
+
url: safePageUrl(),
|
|
1497
|
+
revision: this.revision,
|
|
1498
|
+
targetState: 'detached',
|
|
1499
|
+
safeSummary: 'The requested target changed while scrolling into view.',
|
|
1500
|
+
},
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
if (settlement.status !== 'settled') {
|
|
1504
|
+
this.callbacks.onHighlight(null, 'failure');
|
|
1505
|
+
return {
|
|
1506
|
+
...base,
|
|
1507
|
+
status: 'blocked',
|
|
1508
|
+
observed: {
|
|
1509
|
+
url: safePageUrl(),
|
|
1510
|
+
revision: this.revision,
|
|
1511
|
+
targetState: 'unchanged',
|
|
1512
|
+
safeSummary: 'The target could not be safely brought into view.',
|
|
1513
|
+
},
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
this.capture();
|
|
1517
|
+
const fingerprintedSettledHandle = this.targets.get(grant.targetId);
|
|
1518
|
+
const refreshedFingerprint = fingerprintedSettledHandle
|
|
1519
|
+
? await (0, exports.actionTargetFingerprint)(fingerprintedSettledHandle.target)
|
|
1520
|
+
: null;
|
|
1521
|
+
const postSettlementStale = executionStale();
|
|
1522
|
+
if (postSettlementStale)
|
|
1523
|
+
return postSettlementStale;
|
|
1524
|
+
postActionSnapshot = this.capture();
|
|
1525
|
+
const finalHandle = this.targets.get(grant.targetId);
|
|
1526
|
+
if (!fingerprintedSettledHandle ||
|
|
1527
|
+
fingerprintedSettledHandle.element !== element ||
|
|
1528
|
+
!finalHandle ||
|
|
1529
|
+
finalHandle.element !== element ||
|
|
1530
|
+
actionTargetFingerprintBinding(finalHandle.target) !==
|
|
1531
|
+
actionTargetFingerprintBinding(fingerprintedSettledHandle.target) ||
|
|
1532
|
+
!element.isConnected ||
|
|
1533
|
+
grant.pageId !== this.pageId ||
|
|
1534
|
+
grant.pageUrl !== safePageUrl() ||
|
|
1535
|
+
grant.policyVersion !== this.policyVersion ||
|
|
1536
|
+
!refreshedFingerprint ||
|
|
1537
|
+
refreshedFingerprint !== grant.targetFingerprint) {
|
|
1538
|
+
this.callbacks.onHighlight(null, 'failure');
|
|
1539
|
+
return {
|
|
1540
|
+
...base,
|
|
1541
|
+
status: 'stale',
|
|
1542
|
+
observed: {
|
|
1543
|
+
url: safePageUrl(),
|
|
1544
|
+
revision: this.revision,
|
|
1545
|
+
targetState: element.isConnected ? 'changed' : 'detached',
|
|
1546
|
+
safeSummary: 'The requested target changed while scrolling into view.',
|
|
1547
|
+
},
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
const finalRect = element.getBoundingClientRect();
|
|
1551
|
+
if (!isRendered(element) ||
|
|
1552
|
+
!enabled(element) ||
|
|
1553
|
+
!strictlyIntersectsViewport(finalRect) ||
|
|
1554
|
+
!sameSettledRect(settlement.rect, finalRect) ||
|
|
1555
|
+
(handle.pageScroll && (!this.pageScrollAvailable(element) ||
|
|
1556
|
+
(window.scrollY - scrollStartY) * (handle.pageScroll === 'down' ? 1 : -1) <= SCROLL_SETTLEMENT_POSITION_TOLERANCE_PX)) ||
|
|
1557
|
+
finalHandle.target.state.covered) {
|
|
1558
|
+
this.callbacks.onHighlight(null, 'failure');
|
|
1559
|
+
return {
|
|
1560
|
+
...base,
|
|
1561
|
+
status: 'blocked',
|
|
1562
|
+
observed: {
|
|
1563
|
+
url: safePageUrl(),
|
|
1564
|
+
revision: this.revision,
|
|
1565
|
+
targetState: 'unchanged',
|
|
1566
|
+
safeSummary: 'The target could not be safely brought into view.',
|
|
1567
|
+
},
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1570
|
+
handle = finalHandle;
|
|
1269
1571
|
break;
|
|
1572
|
+
}
|
|
1270
1573
|
case 'highlight':
|
|
1271
1574
|
break;
|
|
1272
1575
|
case 'focus':
|
|
@@ -1275,7 +1578,7 @@ class PageContextCollector {
|
|
|
1275
1578
|
element.focus({ preventScroll: false });
|
|
1276
1579
|
break;
|
|
1277
1580
|
case 'click':
|
|
1278
|
-
this.click(element, grant.actionId, grant.desiredChecked, grant.desiredExpanded, grant.desiredPressed, grant.destinationPath);
|
|
1581
|
+
this.click(element, handle, grant.actionId, grant.desiredChecked, grant.desiredExpanded, grant.desiredPressed, grant.destinationPath);
|
|
1279
1582
|
break;
|
|
1280
1583
|
case 'type':
|
|
1281
1584
|
this.type(element, grant.value ?? '');
|
|
@@ -1294,14 +1597,28 @@ class PageContextCollector {
|
|
|
1294
1597
|
typeof grant.destinationPath === 'string') {
|
|
1295
1598
|
this.observeCausalNavigationAfterMutation(grant.actionId, grant.destinationPath, beforeActionUrl);
|
|
1296
1599
|
}
|
|
1297
|
-
|
|
1600
|
+
if (grant.action !== 'scroll') {
|
|
1601
|
+
await new Promise((resolve) => setTimeout(resolve, 80));
|
|
1602
|
+
}
|
|
1298
1603
|
const postActionStale = executionStale();
|
|
1299
1604
|
if (postActionStale)
|
|
1300
1605
|
return postActionStale;
|
|
1301
1606
|
if (!this.actionApplied(grant, element, handle)) {
|
|
1302
1607
|
throw new Error('The approved value was not applied.');
|
|
1303
1608
|
}
|
|
1304
|
-
|
|
1609
|
+
if ((grant.action === 'type' || grant.action === 'select') && isNativeEditableField(element)) {
|
|
1610
|
+
const binding = this.fieldTargetBindings.get(element);
|
|
1611
|
+
// Preserve this exact action's identity for its verified result only
|
|
1612
|
+
// after the native field contains the approved value. Later visitor
|
|
1613
|
+
// edits still rotate the ID on the next capture.
|
|
1614
|
+
if (binding && this.targetIds.get(element) === grant.targetId) {
|
|
1615
|
+
this.fieldTargetBindings.set(element, { ...binding, value: localFieldValue(element) });
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
const snapshot = postActionSnapshot ?? this.capture();
|
|
1619
|
+
if (grant.action === 'type' || grant.action === 'select') {
|
|
1620
|
+
this.fieldAppliedRevisions.set(element, snapshot.revision);
|
|
1621
|
+
}
|
|
1305
1622
|
const attached = element.isConnected;
|
|
1306
1623
|
const after = attached ? this.safeState(element) : '';
|
|
1307
1624
|
const expanded = attached
|
|
@@ -1311,7 +1628,7 @@ class PageContextCollector {
|
|
|
1311
1628
|
? literalBooleanAttribute(element, 'aria-pressed')
|
|
1312
1629
|
: undefined;
|
|
1313
1630
|
const checked = attached ? checkedStateFor(element) : undefined;
|
|
1314
|
-
this.callbacks.onHighlight(attached ? element : null, 'success');
|
|
1631
|
+
this.callbacks.onHighlight(attached && !handle.pageScroll ? element : null, 'success');
|
|
1315
1632
|
return {
|
|
1316
1633
|
...base,
|
|
1317
1634
|
status: 'executed',
|
|
@@ -1320,18 +1637,22 @@ class PageContextCollector {
|
|
|
1320
1637
|
revision: snapshot.revision,
|
|
1321
1638
|
targetState: !attached
|
|
1322
1639
|
? 'detached'
|
|
1323
|
-
: grant.action === 'type' || grant.action === 'select' || before !== after
|
|
1640
|
+
: grant.action === 'type' || grant.action === 'select' || before !== after || handle.pageScroll
|
|
1324
1641
|
? 'changed'
|
|
1325
1642
|
: 'unchanged',
|
|
1326
|
-
safeSummary:
|
|
1327
|
-
?
|
|
1328
|
-
: grant.action === '
|
|
1329
|
-
? 'The requested
|
|
1330
|
-
: grant.
|
|
1331
|
-
? 'The requested
|
|
1332
|
-
: grant.
|
|
1333
|
-
? 'The requested
|
|
1334
|
-
:
|
|
1643
|
+
safeSummary: handle.pageScroll
|
|
1644
|
+
? `The page moved ${handle.pageScroll} by ${Math.round(Math.abs(window.scrollY - scrollStartY))} pixels.`
|
|
1645
|
+
: grant.action === 'scroll'
|
|
1646
|
+
? 'The requested target is visible. This confirms target visibility, not a directional page scroll.'
|
|
1647
|
+
: grant.action === 'type'
|
|
1648
|
+
? 'The requested text was applied to the approved field.'
|
|
1649
|
+
: grant.action === 'select'
|
|
1650
|
+
? 'The requested option was applied to the approved field.'
|
|
1651
|
+
: grant.desiredChecked !== undefined
|
|
1652
|
+
? 'The requested checkbox state was applied.'
|
|
1653
|
+
: grant.desiredExpanded !== undefined || grant.desiredPressed !== undefined
|
|
1654
|
+
? 'The requested button state was applied.'
|
|
1655
|
+
: `${grant.action} executed on the approved ${roleFor(element)} target.`,
|
|
1335
1656
|
...(checked !== undefined ? { checked } : {}),
|
|
1336
1657
|
...(this.statefulButtonActionProof && expanded !== undefined ? { expanded } : {}),
|
|
1337
1658
|
...(this.statefulButtonActionProof && pressed !== undefined ? { pressed } : {}),
|
|
@@ -1356,6 +1677,7 @@ class PageContextCollector {
|
|
|
1356
1677
|
if (this.executingActionId !== actionId)
|
|
1357
1678
|
return null;
|
|
1358
1679
|
this.executingActionId = null;
|
|
1680
|
+
const deferred = this.deferredNavigation;
|
|
1359
1681
|
const navigation = this.pendingNavigation;
|
|
1360
1682
|
this.pendingNavigation = null;
|
|
1361
1683
|
const shouldCapture = this.pendingCapture || Boolean(navigation);
|
|
@@ -1376,18 +1698,145 @@ class PageContextCollector {
|
|
|
1376
1698
|
if (this.running &&
|
|
1377
1699
|
navigationAcknowledged &&
|
|
1378
1700
|
(!settlement || this.navigationSettlement === settlement) &&
|
|
1701
|
+
deferred?.actionId !== actionId &&
|
|
1379
1702
|
(shouldCapture || !navigation)) {
|
|
1380
1703
|
if (settlement)
|
|
1381
1704
|
this.navigationSettlement = null;
|
|
1382
1705
|
await this.captureAndPublish();
|
|
1383
1706
|
}
|
|
1384
|
-
const deferred = this.deferredNavigation;
|
|
1385
1707
|
this.deferredNavigation = null;
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1708
|
+
if (deferred?.actionId !== actionId ||
|
|
1709
|
+
window.location.href !== deferred.fromUrl) {
|
|
1710
|
+
this.releasedNavigation = null;
|
|
1711
|
+
return null;
|
|
1712
|
+
}
|
|
1713
|
+
this.releasedNavigation = deferred;
|
|
1714
|
+
return deferred.toUrl;
|
|
1715
|
+
}
|
|
1716
|
+
/**
|
|
1717
|
+
* Replays the exact approved link after its action result is durable. This
|
|
1718
|
+
* gives same-document routers (including Framer) their normal click and
|
|
1719
|
+
* overlay-close lifecycle. A slow or ignored router click fails closed so
|
|
1720
|
+
* an active voice session is never destroyed by an unrequested reload.
|
|
1721
|
+
*/
|
|
1722
|
+
async activateReleasedNavigation(url) {
|
|
1723
|
+
const navigation = this.releasedNavigation;
|
|
1724
|
+
this.releasedNavigation = null;
|
|
1725
|
+
if (!this.running ||
|
|
1726
|
+
!navigation ||
|
|
1727
|
+
navigation.toUrl !== url) {
|
|
1728
|
+
return 'rejected';
|
|
1729
|
+
}
|
|
1730
|
+
if (window.location.href !== navigation.fromUrl) {
|
|
1731
|
+
return sameNavigationDestination(window.location.href, navigation.toUrl)
|
|
1732
|
+
? 'settled'
|
|
1733
|
+
: 'rejected';
|
|
1734
|
+
}
|
|
1735
|
+
this.captureSnapshot(false);
|
|
1736
|
+
const handle = this.targets.get(navigation.targetId);
|
|
1737
|
+
const target = new URL(navigation.source.href, window.location.href);
|
|
1738
|
+
if (!navigation.source.isConnected ||
|
|
1739
|
+
!handle ||
|
|
1740
|
+
handle.element !== navigation.source ||
|
|
1741
|
+
actionTargetFingerprintBinding(handle.target) !== navigation.targetBinding ||
|
|
1742
|
+
handle.target.sensitivity !== 'none' ||
|
|
1743
|
+
handle.target.protectedRegion !== false ||
|
|
1744
|
+
handle.target.consequence !== 'navigation' ||
|
|
1745
|
+
target.href !== navigation.toUrl ||
|
|
1746
|
+
target.origin !== window.location.origin ||
|
|
1747
|
+
safeDestinationPath(navigation.source) !== target.pathname ||
|
|
1748
|
+
linkBrowsingTarget(navigation.source) !== navigation.browsingTarget ||
|
|
1749
|
+
!supportsCurrentTabNavigation(navigation.source) ||
|
|
1750
|
+
!isRendered(navigation.source) ||
|
|
1751
|
+
!isVisible(navigation.source) ||
|
|
1752
|
+
!enabled(navigation.source) ||
|
|
1753
|
+
isCovered(navigation.source, this.trustedGuideRoot)) {
|
|
1754
|
+
return 'rejected';
|
|
1755
|
+
}
|
|
1756
|
+
this.executingActionId = navigation.actionId;
|
|
1757
|
+
const settled = new Promise((resolve) => {
|
|
1758
|
+
const timeoutId = window.setTimeout(() => {
|
|
1759
|
+
const current = this.releasedNavigationSettlement;
|
|
1760
|
+
if (current?.actionId !== navigation.actionId)
|
|
1761
|
+
return;
|
|
1762
|
+
this.releasedNavigationSettlement = null;
|
|
1763
|
+
if (this.executingActionId === navigation.actionId) {
|
|
1764
|
+
this.executingActionId = null;
|
|
1765
|
+
}
|
|
1766
|
+
resolve('timed_out');
|
|
1767
|
+
}, RELEASED_NAVIGATION_SETTLEMENT_TIMEOUT_MS);
|
|
1768
|
+
this.releasedNavigationSettlement = {
|
|
1769
|
+
actionId: navigation.actionId,
|
|
1770
|
+
fromUrl: navigation.fromUrl,
|
|
1771
|
+
toUrl: navigation.toUrl,
|
|
1772
|
+
timeoutId,
|
|
1773
|
+
resolve,
|
|
1774
|
+
};
|
|
1775
|
+
});
|
|
1776
|
+
const useCurrentTab = navigation.browsingTarget === '_blank';
|
|
1777
|
+
try {
|
|
1778
|
+
// New-window links must stay in the observable tab. Navigate the exact
|
|
1779
|
+
// approved URL only after durable release; the normal document-navigation
|
|
1780
|
+
// recovery handles the new page. Dispatching their handlers can open a
|
|
1781
|
+
// popup even if the DOM target is temporarily changed (e.g. React props).
|
|
1782
|
+
if (useCurrentTab) {
|
|
1783
|
+
window.location.assign(navigation.toUrl);
|
|
1784
|
+
}
|
|
1785
|
+
else if (navigation.source.closest(FRAMER_GENERATED_PAGE_SELECTOR) &&
|
|
1786
|
+
typeof window.PointerEvent === 'function') {
|
|
1787
|
+
const preventNativeNavigation = (event) => {
|
|
1788
|
+
if (event.target === navigation.source ||
|
|
1789
|
+
event.composedPath().includes(navigation.source)) {
|
|
1790
|
+
event.preventDefault();
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
window.addEventListener('click', preventNativeNavigation);
|
|
1794
|
+
try {
|
|
1795
|
+
dispatchFramerPrimaryPointerSequence(navigation.source);
|
|
1796
|
+
}
|
|
1797
|
+
finally {
|
|
1798
|
+
window.removeEventListener('click', preventNativeNavigation);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
else {
|
|
1802
|
+
navigation.source.click();
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
catch {
|
|
1806
|
+
this.finishReleasedNavigationSettlement('rejected');
|
|
1807
|
+
}
|
|
1808
|
+
if (window.location.href !== navigation.fromUrl) {
|
|
1809
|
+
this.observeCausalNavigationAfterMutation(navigation.actionId, target.pathname, navigation.fromUrl);
|
|
1810
|
+
this.finishReleasedNavigationSettlement(sameNavigationDestination(window.location.href, navigation.toUrl) ? 'settled' : 'rejected');
|
|
1811
|
+
}
|
|
1812
|
+
const navigationSettled = await settled;
|
|
1813
|
+
if (navigationSettled === 'settled' &&
|
|
1814
|
+
this.executingActionId === navigation.actionId) {
|
|
1815
|
+
try {
|
|
1816
|
+
await this.completeActionExecution(navigation.actionId);
|
|
1817
|
+
}
|
|
1818
|
+
catch {
|
|
1819
|
+
// The exact navigation is already observed. A later context snapshot
|
|
1820
|
+
// failure must not turn the acknowledged action into a failed click.
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
else if (navigationSettled === 'rejected' &&
|
|
1824
|
+
this.executingActionId === navigation.actionId) {
|
|
1825
|
+
// A router may consume the exact click but send the browser somewhere
|
|
1826
|
+
// other than the approved destination. Complete the context-side action
|
|
1827
|
+
// as an unconfirmed causal navigation so its identity cannot leak into a
|
|
1828
|
+
// later, unrelated route change.
|
|
1829
|
+
try {
|
|
1830
|
+
await this.completeActionExecution(navigation.actionId);
|
|
1831
|
+
}
|
|
1832
|
+
catch {
|
|
1833
|
+
// The caller will publish an unconfirmed terminal result. Context
|
|
1834
|
+
// recapture is best-effort after the action authority is consumed.
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
return navigationSettled;
|
|
1389
1838
|
}
|
|
1390
|
-
click(element, actionId, desiredChecked, desiredExpanded, desiredPressed, expectedDestinationPath) {
|
|
1839
|
+
click(element, handle, actionId, desiredChecked, desiredExpanded, desiredPressed, expectedDestinationPath) {
|
|
1391
1840
|
if (!(element instanceof HTMLElement))
|
|
1392
1841
|
throw new Error('Target is not clickable.');
|
|
1393
1842
|
if (desiredChecked !== undefined &&
|
|
@@ -1437,27 +1886,19 @@ class PageContextCollector {
|
|
|
1437
1886
|
if (target.origin !== window.location.origin) {
|
|
1438
1887
|
throw new Error('External navigation is blocked.');
|
|
1439
1888
|
}
|
|
1440
|
-
if ((element
|
|
1441
|
-
|
|
1442
|
-
throw new Error('New-window and download navigation is blocked.');
|
|
1889
|
+
if (!supportsCurrentTabNavigation(element)) {
|
|
1890
|
+
throw new Error('Named-window and download navigation is blocked.');
|
|
1443
1891
|
}
|
|
1444
1892
|
const fromUrl = window.location.href;
|
|
1445
|
-
const preventDocumentNavigation = (event) => {
|
|
1446
|
-
if (event.composedPath().includes(element))
|
|
1447
|
-
event.preventDefault();
|
|
1448
|
-
};
|
|
1449
|
-
window.addEventListener('click', preventDocumentNavigation, { once: true });
|
|
1450
|
-
try {
|
|
1451
|
-
element.click();
|
|
1452
|
-
}
|
|
1453
|
-
finally {
|
|
1454
|
-
window.removeEventListener('click', preventDocumentNavigation);
|
|
1455
|
-
}
|
|
1456
1893
|
if (window.location.href === fromUrl && target.href !== fromUrl) {
|
|
1457
1894
|
this.deferredNavigation = {
|
|
1458
1895
|
actionId,
|
|
1459
1896
|
fromUrl,
|
|
1460
1897
|
toUrl: target.href,
|
|
1898
|
+
source: element,
|
|
1899
|
+
targetId: handle.target.targetId,
|
|
1900
|
+
targetBinding: actionTargetFingerprintBinding(handle.target),
|
|
1901
|
+
browsingTarget: linkBrowsingTarget(element),
|
|
1461
1902
|
};
|
|
1462
1903
|
}
|
|
1463
1904
|
return;
|
|
@@ -1502,7 +1943,11 @@ class PageContextCollector {
|
|
|
1502
1943
|
else {
|
|
1503
1944
|
throw new Error('Target does not accept text.');
|
|
1504
1945
|
}
|
|
1505
|
-
element.dispatchEvent(new InputEvent('input', {
|
|
1946
|
+
element.dispatchEvent(new InputEvent('input', {
|
|
1947
|
+
bubbles: true,
|
|
1948
|
+
inputType: 'insertText',
|
|
1949
|
+
data: value,
|
|
1950
|
+
}));
|
|
1506
1951
|
element.dispatchEvent(new Event('change', { bubbles: true }));
|
|
1507
1952
|
}
|
|
1508
1953
|
select(element, handle, optionValueId) {
|
|
@@ -1551,6 +1996,140 @@ class PageContextCollector {
|
|
|
1551
1996
|
path: window.location.pathname,
|
|
1552
1997
|
});
|
|
1553
1998
|
}
|
|
1999
|
+
scrollTargetIntoView(element) {
|
|
2000
|
+
try {
|
|
2001
|
+
element.scrollIntoView({ behavior: 'instant', block: 'center' });
|
|
2002
|
+
}
|
|
2003
|
+
catch {
|
|
2004
|
+
element.scrollIntoView({ behavior: 'auto', block: 'center' });
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
async waitForScrollSettlement(grant, expectedHandle, expiresAt, executionStale, scrollStartY) {
|
|
2008
|
+
const deadline = Math.min(Date.now() + SCROLL_SETTLEMENT_TIMEOUT_MS, expiresAt);
|
|
2009
|
+
let priorRect = null;
|
|
2010
|
+
let stableSince = null;
|
|
2011
|
+
let documentTop = expectedHandle.element.getBoundingClientRect().top + window.scrollY;
|
|
2012
|
+
let documentLeft = expectedHandle.element.getBoundingClientRect().left + window.scrollX;
|
|
2013
|
+
let layoutCorrections = 0;
|
|
2014
|
+
let priorScrollY = null;
|
|
2015
|
+
let interrupted = false;
|
|
2016
|
+
const interrupt = () => {
|
|
2017
|
+
interrupted = true;
|
|
2018
|
+
};
|
|
2019
|
+
const inputEvents = [
|
|
2020
|
+
'wheel',
|
|
2021
|
+
'touchstart',
|
|
2022
|
+
'pointerdown',
|
|
2023
|
+
'keydown',
|
|
2024
|
+
];
|
|
2025
|
+
for (const event of inputEvents)
|
|
2026
|
+
window.addEventListener(event, interrupt, {
|
|
2027
|
+
capture: true,
|
|
2028
|
+
passive: true,
|
|
2029
|
+
});
|
|
2030
|
+
try {
|
|
2031
|
+
while (Date.now() < deadline) {
|
|
2032
|
+
const stale = executionStale();
|
|
2033
|
+
if (stale)
|
|
2034
|
+
return { status: 'stale', result: stale };
|
|
2035
|
+
await nextAnimationFrameOrTimeout(Math.min(SCROLL_SETTLEMENT_FRAME_FALLBACK_MS, deadline - Date.now()));
|
|
2036
|
+
const postFrameStale = executionStale();
|
|
2037
|
+
if (postFrameStale)
|
|
2038
|
+
return { status: 'stale', result: postFrameStale };
|
|
2039
|
+
if (Date.now() >= deadline)
|
|
2040
|
+
return { status: 'timed_out' };
|
|
2041
|
+
const refreshedHandle = this.targets.get(grant.targetId);
|
|
2042
|
+
if (!refreshedHandle ||
|
|
2043
|
+
refreshedHandle.element !== expectedHandle.element ||
|
|
2044
|
+
!expectedHandle.element.isConnected ||
|
|
2045
|
+
grant.pageId !== this.pageId ||
|
|
2046
|
+
grant.pageUrl !== safePageUrl() ||
|
|
2047
|
+
grant.policyVersion !== this.policyVersion ||
|
|
2048
|
+
(refreshedHandle !== expectedHandle &&
|
|
2049
|
+
actionTargetFingerprintBinding(refreshedHandle.target) !==
|
|
2050
|
+
actionTargetFingerprintBinding(expectedHandle.target))) {
|
|
2051
|
+
return { status: 'target_changed' };
|
|
2052
|
+
}
|
|
2053
|
+
// Context refreshes replace handles, not necessarily the approved DOM
|
|
2054
|
+
// target. Retain only the same element and semantic authority binding.
|
|
2055
|
+
expectedHandle = refreshedHandle;
|
|
2056
|
+
if (interrupted ||
|
|
2057
|
+
!isRendered(expectedHandle.element) ||
|
|
2058
|
+
!enabled(expectedHandle.element)) {
|
|
2059
|
+
return { status: 'unavailable' };
|
|
2060
|
+
}
|
|
2061
|
+
const rect = expectedHandle.element.getBoundingClientRect();
|
|
2062
|
+
if (expectedHandle.pageScroll) {
|
|
2063
|
+
if (!this.pageScrollAvailable(expectedHandle.element))
|
|
2064
|
+
return { status: 'unavailable' };
|
|
2065
|
+
const currentY = window.scrollY;
|
|
2066
|
+
const moved = (currentY - scrollStartY) * (expectedHandle.pageScroll === 'down' ? 1 : -1) >
|
|
2067
|
+
SCROLL_SETTLEMENT_POSITION_TOLERANCE_PX;
|
|
2068
|
+
if (!moved || priorScrollY === null || Math.abs(currentY - priorScrollY) > SCROLL_SETTLEMENT_POSITION_TOLERANCE_PX) {
|
|
2069
|
+
stableSince = moved ? Date.now() : null;
|
|
2070
|
+
}
|
|
2071
|
+
priorScrollY = currentY;
|
|
2072
|
+
if (stableSince !== null && Date.now() - stableSince >= SCROLL_SETTLEMENT_STABLE_MS) {
|
|
2073
|
+
return { status: 'settled', rect };
|
|
2074
|
+
}
|
|
2075
|
+
continue;
|
|
2076
|
+
}
|
|
2077
|
+
const nextDocumentTop = rect.top + window.scrollY;
|
|
2078
|
+
const nextDocumentLeft = rect.left + window.scrollX;
|
|
2079
|
+
const layoutShifted = Math.abs(nextDocumentTop - documentTop) >
|
|
2080
|
+
SCROLL_SETTLEMENT_POSITION_TOLERANCE_PX ||
|
|
2081
|
+
Math.abs(nextDocumentLeft - documentLeft) >
|
|
2082
|
+
SCROLL_SETTLEMENT_POSITION_TOLERANCE_PX;
|
|
2083
|
+
documentTop = nextDocumentTop;
|
|
2084
|
+
documentLeft = nextDocumentLeft;
|
|
2085
|
+
if (!strictlyIntersectsViewport(rect)) {
|
|
2086
|
+
priorRect = null;
|
|
2087
|
+
stableSince = null;
|
|
2088
|
+
// Lazy content can move the same approved link after it briefly enters
|
|
2089
|
+
// view. Follow only layout shifts, never an unchanged offscreen target
|
|
2090
|
+
// or visitor input, within the original deadline and a fixed budget.
|
|
2091
|
+
if (layoutShifted &&
|
|
2092
|
+
layoutCorrections < MAX_SCROLL_LAYOUT_CORRECTIONS) {
|
|
2093
|
+
this.captureSnapshot(false);
|
|
2094
|
+
const current = this.targets.get(grant.targetId);
|
|
2095
|
+
if (!current ||
|
|
2096
|
+
current.element !== expectedHandle.element ||
|
|
2097
|
+
actionTargetFingerprintBinding(current.target) !==
|
|
2098
|
+
actionTargetFingerprintBinding(expectedHandle.target) ||
|
|
2099
|
+
grant.pageId !== this.pageId ||
|
|
2100
|
+
grant.pageUrl !== safePageUrl() ||
|
|
2101
|
+
grant.policyVersion !== this.policyVersion) {
|
|
2102
|
+
return { status: 'target_changed' };
|
|
2103
|
+
}
|
|
2104
|
+
expectedHandle = current;
|
|
2105
|
+
const preCorrectionStale = executionStale();
|
|
2106
|
+
if (preCorrectionStale)
|
|
2107
|
+
return { status: 'stale', result: preCorrectionStale };
|
|
2108
|
+
this.scrollTargetIntoView(current.element);
|
|
2109
|
+
layoutCorrections += 1;
|
|
2110
|
+
const corrected = current.element.getBoundingClientRect();
|
|
2111
|
+
documentTop = corrected.top + window.scrollY;
|
|
2112
|
+
documentLeft = corrected.left + window.scrollX;
|
|
2113
|
+
}
|
|
2114
|
+
continue;
|
|
2115
|
+
}
|
|
2116
|
+
if (!priorRect || !sameSettledRect(priorRect, rect))
|
|
2117
|
+
stableSince = Date.now();
|
|
2118
|
+
priorRect = rect;
|
|
2119
|
+
if (stableSince !== null &&
|
|
2120
|
+
Date.now() - stableSince >= SCROLL_SETTLEMENT_STABLE_MS)
|
|
2121
|
+
return { status: 'settled', rect };
|
|
2122
|
+
}
|
|
2123
|
+
const stale = executionStale();
|
|
2124
|
+
return stale
|
|
2125
|
+
? { status: 'stale', result: stale }
|
|
2126
|
+
: { status: 'timed_out' };
|
|
2127
|
+
}
|
|
2128
|
+
finally {
|
|
2129
|
+
for (const event of inputEvents)
|
|
2130
|
+
window.removeEventListener(event, interrupt, true);
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
1554
2133
|
actionApplied(grant, element, handle) {
|
|
1555
2134
|
if (grant.desiredChecked !== undefined) {
|
|
1556
2135
|
return checkedStateFor(element) === grant.desiredChecked;
|
|
@@ -1731,6 +2310,17 @@ class PageContextCollector {
|
|
|
1731
2310
|
resetBoundTargetIds() {
|
|
1732
2311
|
this.targetIds = new WeakMap();
|
|
1733
2312
|
this.navigationTargetBindings = new WeakMap();
|
|
2313
|
+
this.pageScrollIds = new WeakMap();
|
|
2314
|
+
this.fieldTargetBindings = new WeakMap();
|
|
2315
|
+
this.fieldAppliedRevisions = new WeakMap();
|
|
2316
|
+
}
|
|
2317
|
+
finishReleasedNavigationSettlement(settled) {
|
|
2318
|
+
const current = this.releasedNavigationSettlement;
|
|
2319
|
+
if (!current)
|
|
2320
|
+
return;
|
|
2321
|
+
this.releasedNavigationSettlement = null;
|
|
2322
|
+
window.clearTimeout(current.timeoutId);
|
|
2323
|
+
current.resolve(settled);
|
|
1734
2324
|
}
|
|
1735
2325
|
installNavigationHooks() {
|
|
1736
2326
|
this.originalPushState = history.pushState;
|
|
@@ -1755,8 +2345,5 @@ class PageContextCollector {
|
|
|
1755
2345
|
this.originalPushState = null;
|
|
1756
2346
|
this.originalReplaceState = null;
|
|
1757
2347
|
}
|
|
1758
|
-
reducedMotion() {
|
|
1759
|
-
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
1760
|
-
}
|
|
1761
2348
|
}
|
|
1762
2349
|
exports.PageContextCollector = PageContextCollector;
|