cdp-toolkit 3.1.0 → 3.3.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.
@@ -590,7 +590,7 @@ export type LogEntry = LogGenericLogEntry | LogConsoleLogEntry | LogJavascriptLo
590
590
  // --- emulation module ----------------------------------------------------
591
591
 
592
592
  export type EmulationForcedColorsModeTheme = "light" | "dark";
593
- /** Firefox 153: not implemented. */
593
+ /** Firefox 160: not implemented. */
594
594
  export interface EmulationSetForcedColorsModeThemeOverrideParameters {
595
595
  theme: EmulationForcedColorsModeTheme | null; contexts?: BrowsingContextId[]; userContexts?: BrowserUserContext[];
596
596
  }
@@ -614,9 +614,8 @@ export interface EmulationSetLocaleOverrideParameters { locale: string | null; c
614
614
  export type EmulationSetLocaleOverrideResult = BidiEmptyResult;
615
615
 
616
616
  export interface EmulationMediaFeature { name: string; value: string }
617
- /** Firefox 153: not implemented. */
618
617
  export interface EmulationSetMediaFeaturesOverrideParameters {
619
- features: EmulationMediaFeature[] | null; contexts?: BrowsingContextId[]; userContexts?: BrowserUserContext[];
618
+ features: Record<string, string> | null; /* feature name -> value; null resets */ contexts?: BrowsingContextId[]; userContexts?: BrowserUserContext[];
620
619
  }
621
620
  export type EmulationSetMediaFeaturesOverrideResult = BidiEmptyResult;
622
621
 
@@ -649,7 +648,7 @@ export type EmulationSetUserAgentOverrideResult = BidiEmptyResult;
649
648
  export interface EmulationSetViewportMetaOverrideParameters { viewportMeta: true | null; contexts?: BrowsingContextId[]; userContexts?: BrowserUserContext[] }
650
649
  export type EmulationSetViewportMetaOverrideResult = BidiEmptyResult;
651
650
 
652
- /** Firefox 153: not implemented. */
651
+ /** Firefox 160: not implemented. */
653
652
  export interface EmulationSetScriptingEnabledParameters { enabled: false | null; contexts?: BrowsingContextId[]; userContexts?: BrowserUserContext[] }
654
653
  export type EmulationSetScriptingEnabledResult = BidiEmptyResult;
655
654
 
@@ -662,7 +661,7 @@ export type EmulationSetScrollbarTypeOverrideResult = BidiEmptyResult;
662
661
  export interface EmulationSetTimezoneOverrideParameters { timezone: string | null; contexts?: BrowsingContextId[]; userContexts?: BrowserUserContext[] }
663
662
  export type EmulationSetTimezoneOverrideResult = BidiEmptyResult;
664
663
 
665
- /** Firefox 153: not implemented. */
664
+ /** Firefox 160: not implemented. */
666
665
  export interface EmulationSetTouchOverrideParameters {
667
666
  maxTouchPoints: BidiJsUint | null /* .ge 1 */; contexts?: BrowsingContextId[]; userContexts?: BrowserUserContext[];
668
667
  }
@@ -725,25 +724,44 @@ export interface BidiCommands {
725
724
  "storage.getCookies": { params: StorageGetCookiesParameters; result: StorageGetCookiesResult };
726
725
  "storage.setCookie": { params: StorageSetCookieParameters; result: StorageSetCookieResult };
727
726
 
728
- /** Firefox 153: not implemented. */
727
+ /** Firefox 160: not implemented. */
729
728
  "emulation.setForcedColorsModeThemeOverride": { params: EmulationSetForcedColorsModeThemeOverrideParameters; result: EmulationSetForcedColorsModeThemeOverrideResult };
730
729
  "emulation.setGeolocationOverride": { params: EmulationSetGeolocationOverrideParameters; result: EmulationSetGeolocationOverrideResult };
731
730
  "emulation.setLocaleOverride": { params: EmulationSetLocaleOverrideParameters; result: EmulationSetLocaleOverrideResult };
732
- /** Firefox 153: not implemented. */
733
731
  "emulation.setMediaFeaturesOverride": { params: EmulationSetMediaFeaturesOverrideParameters; result: EmulationSetMediaFeaturesOverrideResult };
734
732
  "emulation.setNetworkConditions": { params: EmulationSetNetworkConditionsParameters; result: EmulationSetNetworkConditionsResult };
735
733
  "emulation.setScreenOrientationOverride": { params: EmulationSetScreenOrientationOverrideParameters; result: EmulationSetScreenOrientationOverrideResult };
736
734
  "emulation.setScreenSettingsOverride": { params: EmulationSetScreenSettingsOverrideParameters; result: EmulationSetScreenSettingsOverrideResult };
737
- /** Firefox 153: not implemented. */
735
+ /** Firefox 160: not implemented. */
738
736
  "emulation.setScriptingEnabled": { params: EmulationSetScriptingEnabledParameters; result: EmulationSetScriptingEnabledResult };
739
737
  /** Firefox 153: not implemented. */
740
738
  "emulation.setScrollbarTypeOverride": { params: EmulationSetScrollbarTypeOverrideParameters; result: EmulationSetScrollbarTypeOverrideResult };
741
739
  "emulation.setTimezoneOverride": { params: EmulationSetTimezoneOverrideParameters; result: EmulationSetTimezoneOverrideResult };
742
- /** Firefox 153: not implemented. */
740
+ /** Firefox 160: not implemented. */
743
741
  "emulation.setTouchOverride": { params: EmulationSetTouchOverrideParameters; result: EmulationSetTouchOverrideResult };
744
742
  "emulation.setUserAgentOverride": { params: EmulationSetUserAgentOverrideParameters; result: EmulationSetUserAgentOverrideResult };
745
743
  /** Firefox 153: not implemented. */
746
744
  "emulation.setViewportMetaOverride": { params: EmulationSetViewportMetaOverrideParameters; result: EmulationSetViewportMetaOverrideResult };
745
+
746
+ /** Measured on Firefox 160.0 (not present on 153): `allowed` + destinationFolder redirects every
747
+ * download; `null` restores the browser's own behavior. See ../bidi-browser-tools.ts. */
748
+ "browser.setDownloadBehavior": { params: BrowserSetDownloadBehaviorParameters; result: BidiEmptyResult };
749
+ /** WebDriver BiDi permissions extension module, measured on Firefox 160.0. */
750
+ "permissions.setPermission": { params: PermissionsSetPermissionParameters; result: BidiEmptyResult };
751
+ }
752
+
753
+ // --- browser.setDownloadBehavior / permissions extension -----------------
754
+ export type BrowserDownloadBehavior =
755
+ | { type: "allowed"; destinationFolder: string }
756
+ | { type: "denied" };
757
+ export interface BrowserSetDownloadBehaviorParameters {
758
+ downloadBehavior: BrowserDownloadBehavior | null; userContexts?: BrowserUserContext[];
759
+ }
760
+ export interface PermissionsPermissionDescriptor { name: string; [extra: string]: unknown }
761
+ export type PermissionsPermissionState = "granted" | "denied" | "prompt";
762
+ export interface PermissionsSetPermissionParameters {
763
+ descriptor: PermissionsPermissionDescriptor; state: PermissionsPermissionState; origin: string;
764
+ embeddedOrigin?: string; userContext?: string;
747
765
  }
748
766
  export type BidiMethod = keyof BidiCommands;
749
767
 
@@ -49,6 +49,128 @@ export function coerceSnapshotResult(raw: unknown): StampedSnapshot {
49
49
  return { snapshot: (raw as StampedSnapshot).snapshot, nodeCount: (raw as StampedSnapshot).nodeCount };
50
50
  }
51
51
 
52
+ /**
53
+ * The reduced role + accessible-name heuristics, as in-page JS source. Shared by the snapshot
54
+ * walker below and by `describeElementSource` (src/shared-tools.ts), which names the element an
55
+ * action is about to touch, so a click result and a snapshot line agree on what "button \"Save\""
56
+ * means. Expects a `MAX_NAME_LENGTH` var in the enclosing function; interpolates nothing itself.
57
+ */
58
+ export const ACCNAME_HELPERS_SOURCE = `
59
+ function truncate(s) {
60
+ s = s.trim().replace(/\\s+/g, " ");
61
+ if (s.length > MAX_NAME_LENGTH) return s.slice(0, MAX_NAME_LENGTH - 1) + "\\u2026";
62
+ return s;
63
+ }
64
+
65
+ function textOf(el) {
66
+ return el.textContent || "";
67
+ }
68
+
69
+ function idRefsText(doc, ids) {
70
+ var parts = [];
71
+ var list = ids.trim().split(/\\s+/);
72
+ for (var i = 0; i < list.length; i++) {
73
+ var ref = doc.getElementById(list[i]);
74
+ if (ref) parts.push(textOf(ref));
75
+ }
76
+ return parts.join(" ").trim();
77
+ }
78
+
79
+ // Text of a <label>, minus any nested form control's own content: a
80
+ // label that WRAPS its control ("<label>Color <select>...</select></label>")
81
+ // would otherwise include every option's text in the control's own name.
82
+ function labelOwnText(label) {
83
+ var clone = label.cloneNode(true);
84
+ var controls = clone.querySelectorAll("input, select, textarea, button");
85
+ for (var i = 0; i < controls.length; i++) {
86
+ controls[i].parentNode.removeChild(controls[i]);
87
+ }
88
+ return textOf(clone);
89
+ }
90
+
91
+ // Guard: without this, an <option> inside a labelled <select> would
92
+ // inherit the select's own label via closest("label"), not its text.
93
+ var LABELABLE_TAGS = { INPUT: 1, TEXTAREA: 1, SELECT: 1, BUTTON: 1, METER: 1, OUTPUT: 1, PROGRESS: 1 };
94
+
95
+ function nativeLabelText(el) {
96
+ if (!LABELABLE_TAGS[el.tagName]) return "";
97
+ var doc = el.ownerDocument;
98
+ if (el.id) {
99
+ var forLabel = doc.querySelector('label[for="' + el.id + '"]');
100
+ if (forLabel) return labelOwnText(forLabel);
101
+ }
102
+ var ancestor = el.closest ? el.closest("label") : null;
103
+ if (ancestor) return labelOwnText(ancestor);
104
+ return "";
105
+ }
106
+
107
+ // Reduced accname: aria-labelledby, then aria-label, then native label,
108
+ // then alt/title/placeholder, then trimmed own text for content-named
109
+ // elements. Not the full W3C accname algorithm (no recursive traversal
110
+ // rules for nested presentational content) but covers the common cases.
111
+ function accessibleName(el, contentNamed) {
112
+ var doc = el.ownerDocument;
113
+ var labelledby = el.getAttribute("aria-labelledby");
114
+ if (labelledby) {
115
+ var viaIds = idRefsText(doc, labelledby);
116
+ if (viaIds) return truncate(viaIds);
117
+ }
118
+ var ariaLabel = el.getAttribute("aria-label");
119
+ if (ariaLabel && ariaLabel.trim()) return truncate(ariaLabel);
120
+ var native = nativeLabelText(el);
121
+ if (native && native.trim()) return truncate(native);
122
+ var alt = el.getAttribute("alt");
123
+ if (alt && alt.trim()) return truncate(alt);
124
+ var title = el.getAttribute("title");
125
+ if (title && title.trim()) return truncate(title);
126
+ var placeholder = el.getAttribute("placeholder");
127
+ if (placeholder && placeholder.trim()) return truncate(placeholder);
128
+ if (contentNamed) {
129
+ var text = textOf(el);
130
+ if (text && text.trim()) return truncate(text);
131
+ }
132
+ return "";
133
+ }
134
+
135
+ var IMPLICIT_ROLE_BY_TAG = {
136
+ A: "link", BUTTON: "button", NAV: "navigation", MAIN: "main", FORM: "form", DIALOG: "dialog",
137
+ UL: "list", OL: "list", LI: "listitem", TABLE: "table", TR: "row", TD: "cell", TH: "columnheader",
138
+ SELECT: "combobox", OPTION: "option", TEXTAREA: "textbox", IMG: "img",
139
+ H1: "heading", H2: "heading", H3: "heading", H4: "heading", H5: "heading", H6: "heading",
140
+ PROGRESS: "progressbar", METER: "meter"
141
+ };
142
+
143
+ var INPUT_TYPE_ROLE = {
144
+ button: "button", submit: "button", reset: "button", checkbox: "checkbox", radio: "radio",
145
+ range: "slider", number: "spinbutton", search: "searchbox", email: "textbox", tel: "textbox",
146
+ url: "textbox", password: "textbox", text: "textbox", image: "button"
147
+ };
148
+
149
+ var CONTENT_NAMED_ROLES = {
150
+ button: true, link: true, heading: true, option: true, cell: true,
151
+ columnheader: true, listitem: true, menuitem: true, tab: true
152
+ };
153
+
154
+ function implicitRole(el) {
155
+ var explicit = el.getAttribute("role");
156
+ if (explicit) return explicit;
157
+ var tag = el.tagName;
158
+ if (tag === "INPUT") {
159
+ var type = (el.getAttribute("type") || "text").toLowerCase();
160
+ return INPUT_TYPE_ROLE[type] || "textbox";
161
+ }
162
+ if (tag === "A" && !el.getAttribute("href")) return "";
163
+ if (Object.prototype.hasOwnProperty.call(IMPLICIT_ROLE_BY_TAG, tag)) {
164
+ return IMPLICIT_ROLE_BY_TAG[tag];
165
+ }
166
+ // Deliberate divergence: Chrome's real AX tree says "generic" here,
167
+ // but "textbox" is the useful signal an agent needs. Chrome is out of
168
+ // step, do not "fix" this toward parity.
169
+ if (el.isContentEditable) return "textbox";
170
+ return "";
171
+ }
172
+ `;
173
+
52
174
  /**
53
175
  * The in-page function source. Zero-argument, self-contained: no closures
54
176
  * over TypeScript scope, no imports, nothing but plain DOM/ARIA calls that
@@ -102,119 +224,7 @@ export function buildSnapshotFunctionSource(): string {
102
224
  return true;
103
225
  }
104
226
 
105
- function truncate(s) {
106
- s = s.trim().replace(/\\s+/g, " ");
107
- if (s.length > MAX_NAME_LENGTH) return s.slice(0, MAX_NAME_LENGTH - 1) + "\\u2026";
108
- return s;
109
- }
110
-
111
- function textOf(el) {
112
- return el.textContent || "";
113
- }
114
-
115
- function idRefsText(doc, ids) {
116
- var parts = [];
117
- var list = ids.trim().split(/\\s+/);
118
- for (var i = 0; i < list.length; i++) {
119
- var ref = doc.getElementById(list[i]);
120
- if (ref) parts.push(textOf(ref));
121
- }
122
- return parts.join(" ").trim();
123
- }
124
-
125
- // Text of a <label>, minus any nested form control's own content: a
126
- // label that WRAPS its control ("<label>Color <select>...</select></label>")
127
- // would otherwise include every option's text in the control's own name.
128
- function labelOwnText(label) {
129
- var clone = label.cloneNode(true);
130
- var controls = clone.querySelectorAll("input, select, textarea, button");
131
- for (var i = 0; i < controls.length; i++) {
132
- controls[i].parentNode.removeChild(controls[i]);
133
- }
134
- return textOf(clone);
135
- }
136
-
137
- // Guard: without this, an <option> inside a labelled <select> would
138
- // inherit the select's own label via closest("label"), not its text.
139
- var LABELABLE_TAGS = { INPUT: 1, TEXTAREA: 1, SELECT: 1, BUTTON: 1, METER: 1, OUTPUT: 1, PROGRESS: 1 };
140
-
141
- function nativeLabelText(el) {
142
- if (!LABELABLE_TAGS[el.tagName]) return "";
143
- var doc = el.ownerDocument;
144
- if (el.id) {
145
- var forLabel = doc.querySelector('label[for="' + el.id + '"]');
146
- if (forLabel) return labelOwnText(forLabel);
147
- }
148
- var ancestor = el.closest ? el.closest("label") : null;
149
- if (ancestor) return labelOwnText(ancestor);
150
- return "";
151
- }
152
-
153
- // Reduced accname: aria-labelledby, then aria-label, then native label,
154
- // then alt/title/placeholder, then trimmed own text for content-named
155
- // elements. Not the full W3C accname algorithm (no recursive traversal
156
- // rules for nested presentational content) but covers the common cases.
157
- function accessibleName(el, contentNamed) {
158
- var doc = el.ownerDocument;
159
- var labelledby = el.getAttribute("aria-labelledby");
160
- if (labelledby) {
161
- var viaIds = idRefsText(doc, labelledby);
162
- if (viaIds) return truncate(viaIds);
163
- }
164
- var ariaLabel = el.getAttribute("aria-label");
165
- if (ariaLabel && ariaLabel.trim()) return truncate(ariaLabel);
166
- var native = nativeLabelText(el);
167
- if (native && native.trim()) return truncate(native);
168
- var alt = el.getAttribute("alt");
169
- if (alt && alt.trim()) return truncate(alt);
170
- var title = el.getAttribute("title");
171
- if (title && title.trim()) return truncate(title);
172
- var placeholder = el.getAttribute("placeholder");
173
- if (placeholder && placeholder.trim()) return truncate(placeholder);
174
- if (contentNamed) {
175
- var text = textOf(el);
176
- if (text && text.trim()) return truncate(text);
177
- }
178
- return "";
179
- }
180
-
181
- var IMPLICIT_ROLE_BY_TAG = {
182
- A: "link", BUTTON: "button", NAV: "navigation", MAIN: "main", FORM: "form", DIALOG: "dialog",
183
- UL: "list", OL: "list", LI: "listitem", TABLE: "table", TR: "row", TD: "cell", TH: "columnheader",
184
- SELECT: "combobox", OPTION: "option", TEXTAREA: "textbox", IMG: "img",
185
- H1: "heading", H2: "heading", H3: "heading", H4: "heading", H5: "heading", H6: "heading",
186
- PROGRESS: "progressbar", METER: "meter"
187
- };
188
-
189
- var INPUT_TYPE_ROLE = {
190
- button: "button", submit: "button", reset: "button", checkbox: "checkbox", radio: "radio",
191
- range: "slider", number: "spinbutton", search: "searchbox", email: "textbox", tel: "textbox",
192
- url: "textbox", password: "textbox", text: "textbox", image: "button"
193
- };
194
-
195
- var CONTENT_NAMED_ROLES = {
196
- button: true, link: true, heading: true, option: true, cell: true,
197
- columnheader: true, listitem: true, menuitem: true, tab: true
198
- };
199
-
200
- function implicitRole(el) {
201
- var explicit = el.getAttribute("role");
202
- if (explicit) return explicit;
203
- var tag = el.tagName;
204
- if (tag === "INPUT") {
205
- var type = (el.getAttribute("type") || "text").toLowerCase();
206
- return INPUT_TYPE_ROLE[type] || "textbox";
207
- }
208
- if (tag === "A" && !el.getAttribute("href")) return "";
209
- if (Object.prototype.hasOwnProperty.call(IMPLICIT_ROLE_BY_TAG, tag)) {
210
- return IMPLICIT_ROLE_BY_TAG[tag];
211
- }
212
- // Deliberate divergence: Chrome's real AX tree says "generic" here,
213
- // but "textbox" is the useful signal an agent needs. Chrome is out of
214
- // step, do not "fix" this toward parity.
215
- if (el.isContentEditable) return "textbox";
216
- return "";
217
- }
227
+ ${ACCNAME_HELPERS_SOURCE}
218
228
 
219
229
  function headingLevel(el) {
220
230
  var m = /^H([1-6])$/.exec(el.tagName);