Skip to content

Commit 05cfaf4

Browse files
committed
chore: make refs & emitGeneric private for mcp
1 parent 2dab895 commit 05cfaf4

File tree

17 files changed

+44
-85
lines changed

17 files changed

+44
-85
lines changed

docs/src/api/class-locator.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,6 @@ Below is the HTML markup and the respective ARIA snapshot:
206206
- link "About"
207207
```
208208
209-
### option: Locator.ariaSnapshot.emitGeneric
210-
* since: v1.53
211-
- `emitGeneric` <[boolean]>
212-
213-
Generate `generic` aria nodes for elements w/o roles (similar to Chrome DevTools).
214-
215-
### option: Locator.ariaSnapshot.ref
216-
* since: v1.52
217-
- `ref` <[boolean]>
218-
219-
Generate symbolic reference for each element. One can use `aria-ref=<ref>` locator immediately after capturing the
220-
snapshot to perform actions on the element.
221-
222209
### option: Locator.ariaSnapshot.timeout = %%-input-timeout-%%
223210
* since: v1.49
224211

docs/src/release-notes-csharp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ toc_max_heading_level: 2
3030
### Miscellaneous
3131

3232
- New option [`option: APIRequest.newContext.maxRedirects`] in [`method: APIRequest.newContext`] to control the maximum number of redirects.
33-
- New option [`option: Locator.ariaSnapshot.ref`] in [`method: Locator.ariaSnapshot`] to generate reference for each element in the snapshot which can later be used to locate the element.
33+
- New option `ref` in [`method: Locator.ariaSnapshot`] to generate reference for each element in the snapshot which can later be used to locate the element.
3434

3535
### Breaking Changes
3636

docs/src/release-notes-java.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ toc_max_heading_level: 2
3030
### Miscellaneous
3131
3232
- New option [`option: APIRequest.newContext.maxRedirects`] in [`method: APIRequest.newContext`] to control the maximum number of redirects.
33-
- New option [`option: Locator.ariaSnapshot.ref`] in [`method: Locator.ariaSnapshot`] to generate reference for each element in the snapshot which can later be used to locate the element.
33+
- New option `ref` in [`method: Locator.ariaSnapshot`] to generate reference for each element in the snapshot which can later be used to locate the element.
3434
3535
### Breaking Changes
3636

docs/src/release-notes-js.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import LiteYouTube from '@site/src/components/LiteYouTube';
3838
### Miscellaneous
3939

4040
- New option [`option: APIRequest.newContext.maxRedirects`] in [`method: APIRequest.newContext`] to control the maximum number of redirects.
41-
- New option [`option: Locator.ariaSnapshot.ref`] in [`method: Locator.ariaSnapshot`] to generate reference for each element in the snapshot which can later be used to locate the element.
41+
- New option `ref` in [`method: Locator.ariaSnapshot`] to generate reference for each element in the snapshot which can later be used to locate the element.
4242
- HTML reporter now supports *NOT filtering* via `!@my-tag` or `!my-file.spec.ts` or `!p:my-project`.
4343

4444
### Breaking Changes

docs/src/release-notes-python.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ toc_max_heading_level: 2
3030
### Miscellaneous
3131

3232
- New option [`option: APIRequest.newContext.maxRedirects`] in [`method: APIRequest.newContext`] to control the maximum number of redirects.
33-
- New option [`option: Locator.ariaSnapshot.ref`] in [`method: Locator.ariaSnapshot`] to generate reference for each element in the snapshot which can later be used to locate the element.
33+
- New option `ref` in [`method: Locator.ariaSnapshot`] to generate reference for each element in the snapshot which can later be used to locate the element.
3434

3535
### Breaking Changes
3636

packages/injected/src/ariaSnapshot.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type AriaSnapshot = {
4040
ids: Map<Element, number>;
4141
};
4242

43-
export function generateAriaTree(rootElement: Element, generation: number, options?: { emitGeneric?: boolean }): AriaSnapshot {
43+
export function generateAriaTree(rootElement: Element, generation: number, options?: { forAI?: boolean }): AriaSnapshot {
4444
const visited = new Set<Node>();
4545

4646
const snapshot: AriaSnapshot = {
@@ -147,11 +147,11 @@ export function generateAriaTree(rootElement: Element, generation: number, optio
147147
return snapshot;
148148
}
149149

150-
function toAriaNode(element: Element, options?: { emitGeneric?: boolean }): AriaNode | null {
150+
function toAriaNode(element: Element, options?: { forAI?: boolean }): AriaNode | null {
151151
if (element.nodeName === 'IFRAME')
152152
return { role: 'iframe', name: '', children: [], props: {}, element, box: box(element), receivesPointerEvents: true };
153153

154-
const defaultRole = options?.emitGeneric ? 'generic' : null;
154+
const defaultRole = options?.forAI ? 'generic' : null;
155155
const role = roleUtils.getAriaRole(element) ?? defaultRole;
156156
if (!role || role === 'presentation' || role === 'none')
157157
return null;
@@ -363,7 +363,7 @@ function matchesNodeDeep(root: AriaNode, template: AriaTemplateNode, collectAll:
363363
return results;
364364
}
365365

366-
export function renderAriaTree(ariaSnapshot: AriaSnapshot, options?: { mode?: 'raw' | 'regex', ref?: boolean }): string {
366+
export function renderAriaTree(ariaSnapshot: AriaSnapshot, options?: { mode?: 'raw' | 'regex', forAI?: boolean }): string {
367367
const lines: string[] = [];
368368
const includeText = options?.mode === 'regex' ? textContributesInfo : () => true;
369369
const renderString = options?.mode === 'regex' ? convertToBestGuessRegex : (str: string) => str;
@@ -402,7 +402,7 @@ export function renderAriaTree(ariaSnapshot: AriaSnapshot, options?: { mode?: 'r
402402
key += ` [pressed]`;
403403
if (ariaNode.selected === true)
404404
key += ` [selected]`;
405-
if (options?.ref && canRef(ariaNode)) {
405+
if (options?.forAI && canRef(ariaNode)) {
406406
const id = ariaSnapshot.ids.get(ariaNode.element);
407407
if (id)
408408
key += ` [ref=s${ariaSnapshot.generation}e${id}]`;

packages/injected/src/consoleApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class ConsoleAPI {
9191
inspect: (selector: string) => this._inspect(selector),
9292
selector: (element: Element) => this._selector(element),
9393
generateLocator: (element: Element, language?: Language) => this._generateLocator(element, language),
94-
ariaSnapshot: (element?: Element, options?: { ref?: boolean }) => {
94+
ariaSnapshot: (element?: Element, options?: { forAI?: boolean }) => {
9595
return this._injectedScript.ariaSnapshot(element || this._injectedScript.document.body, options);
9696
},
9797
resume: () => this._resume(),

packages/injected/src/injectedScript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export class InjectedScript {
297297
return new Set<Element>(result.map(r => r.element));
298298
}
299299

300-
ariaSnapshot(node: Node, options?: { mode?: 'raw' | 'regex', ref?: boolean, emitGeneric?: boolean }): string {
300+
ariaSnapshot(node: Node, options?: { mode?: 'raw' | 'regex', forAI?: boolean }): string {
301301
if (node.nodeType !== Node.ELEMENT_NODE)
302302
throw this.createStacklessError('Can only capture aria snapshot of Element nodes.');
303303
const generation = (this._lastAriaSnapshot?.generation || 0) + 1;

packages/playwright-client/types/types.d.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12500,17 +12500,6 @@ export interface Locator {
1250012500
* @param options
1250112501
*/
1250212502
ariaSnapshot(options?: {
12503-
/**
12504-
* Generate `generic` aria nodes for elements w/o roles (similar to Chrome DevTools).
12505-
*/
12506-
emitGeneric?: boolean;
12507-
12508-
/**
12509-
* Generate symbolic reference for each element. One can use `aria-ref=<ref>` locator immediately after capturing the
12510-
* snapshot to perform actions on the element.
12511-
*/
12512-
ref?: boolean;
12513-
1251412503
/**
1251512504
* Maximum time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `actionTimeout`
1251612505
* option in the config, or by using the

packages/playwright-core/src/client/locator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ export class Locator implements api.Locator {
303303
return await this._withElement((h, timeout) => h.screenshot({ ...options, mask, timeout }), options.timeout);
304304
}
305305

306-
async ariaSnapshot(options?: { ref?: boolean, emitGeneric?: boolean, _mode?: 'raw' | 'regex' } & TimeoutOptions): Promise<string> {
307-
const result = await this._frame._channel.ariaSnapshot({ ...options, mode: options?._mode, selector: this._selector });
306+
async ariaSnapshot(options?: { _forAI?: boolean } & TimeoutOptions): Promise<string> {
307+
const result = await this._frame._channel.ariaSnapshot({ ...options, forAI: options?._forAI, selector: this._selector });
308308
return result.snapshot;
309309
}
310310

0 commit comments

Comments
 (0)