mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: add a11y to bidi over bidi+ (#10338)
This commit is contained in:
parent
b8782fd7a2
commit
edb03d695b
@ -18,8 +18,6 @@ import {Protocol} from 'devtools-protocol';
|
||||
|
||||
import {ElementHandle} from '../api/ElementHandle.js';
|
||||
|
||||
import {CDPSession} from './Connection.js';
|
||||
|
||||
/**
|
||||
* Represents a Node and the properties of it that are relevant to Accessibility.
|
||||
* @public
|
||||
@ -109,6 +107,11 @@ export interface SnapshotOptions {
|
||||
root?: ElementHandle<Node>;
|
||||
}
|
||||
|
||||
interface DataProvider {
|
||||
getFullAXTree(): Promise<Protocol.Accessibility.GetFullAXTreeResponse>;
|
||||
describeNode(id: string): Promise<Protocol.DOM.DescribeNodeResponse>;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Accessibility class provides methods for inspecting the browser's
|
||||
* accessibility tree. The accessibility tree is used by assistive technology
|
||||
@ -132,13 +135,13 @@ export interface SnapshotOptions {
|
||||
* @public
|
||||
*/
|
||||
export class Accessibility {
|
||||
#client: CDPSession;
|
||||
#dataProvider: DataProvider;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(client: CDPSession) {
|
||||
this.#client = client;
|
||||
constructor(dataProvider: DataProvider) {
|
||||
this.#dataProvider = dataProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -184,12 +187,10 @@ export class Accessibility {
|
||||
options: SnapshotOptions = {}
|
||||
): Promise<SerializedAXNode | null> {
|
||||
const {interestingOnly = true, root = null} = options;
|
||||
const {nodes} = await this.#client.send('Accessibility.getFullAXTree');
|
||||
const {nodes} = await this.#dataProvider.getFullAXTree();
|
||||
let backendNodeId: number | undefined;
|
||||
if (root) {
|
||||
const {node} = await this.#client.send('DOM.describeNode', {
|
||||
objectId: root.id,
|
||||
});
|
||||
if (root && root.id) {
|
||||
const {node} = await this.#dataProvider.describeNode(root.id);
|
||||
backendNodeId = node.backendNodeId;
|
||||
}
|
||||
const defaultRoot = AXNode.createTree(nodes);
|
||||
|
@ -167,7 +167,16 @@ export class CDPPage extends Page {
|
||||
this.#keyboard = new Keyboard(client);
|
||||
this.#mouse = new Mouse(client, this.#keyboard);
|
||||
this.#touchscreen = new Touchscreen(client, this.#keyboard);
|
||||
this.#accessibility = new Accessibility(client);
|
||||
this.#accessibility = new Accessibility({
|
||||
describeNode(id: string) {
|
||||
return client.send('DOM.describeNode', {
|
||||
objectId: id,
|
||||
});
|
||||
},
|
||||
getFullAXTree() {
|
||||
return client.send('Accessibility.getFullAXTree');
|
||||
},
|
||||
});
|
||||
this.#frameManager = new FrameManager(
|
||||
client,
|
||||
this,
|
||||
|
@ -281,20 +281,20 @@ export class BrowsingContext extends EventEmitter {
|
||||
return await this.evaluate(getPageContent);
|
||||
}
|
||||
|
||||
async sendCDPCommand(
|
||||
method: keyof ProtocolMapping.Commands,
|
||||
params: object = {}
|
||||
): Promise<unknown> {
|
||||
async sendCDPCommand<T extends keyof ProtocolMapping.Commands>(
|
||||
method: T,
|
||||
params: ProtocolMapping.Commands[T]['paramsType'][0] = {}
|
||||
): Promise<ProtocolMapping.Commands[T]['returnType']> {
|
||||
const session = await this.connection.send('cdp.getSession', {
|
||||
context: this.#id,
|
||||
});
|
||||
// TODO: remove any once chromium-bidi types are updated.
|
||||
const sessionId = (session.result as any).cdpSession;
|
||||
return await this.connection.send('cdp.sendCommand', {
|
||||
const sessionId = session.result.cdpSession;
|
||||
const result = await this.connection.send('cdp.sendCommand', {
|
||||
cdpMethod: method,
|
||||
cdpParams: params,
|
||||
cdpSession: sessionId,
|
||||
});
|
||||
return result.result;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
@ -26,6 +26,7 @@ import {
|
||||
} from '../../api/Page.js';
|
||||
import {assert} from '../../util/assert.js';
|
||||
import {Deferred} from '../../util/Deferred.js';
|
||||
import {Accessibility} from '../Accessibility.js';
|
||||
import {ConsoleMessage, ConsoleMessageLocation} from '../ConsoleMessage.js';
|
||||
import {TargetCloseError} from '../Errors.js';
|
||||
import {Handler} from '../EventEmitter.js';
|
||||
@ -58,6 +59,7 @@ import {BidiSerializer} from './Serializer.js';
|
||||
* @internal
|
||||
*/
|
||||
export class Page extends PageBase {
|
||||
#accessibility: Accessibility;
|
||||
#timeoutSettings = new TimeoutSettings();
|
||||
#browserContext: BrowserContext;
|
||||
#connection: Connection;
|
||||
@ -135,6 +137,24 @@ export class Page extends PageBase {
|
||||
for (const [event, subscriber] of this.#networkManagerEvents) {
|
||||
this.#networkManager.on(event, subscriber);
|
||||
}
|
||||
|
||||
// TODO: https://github.com/w3c/webdriver-bidi/issues/443
|
||||
this.#accessibility = new Accessibility({
|
||||
describeNode: (id: string) => {
|
||||
return this.mainFrame().context().sendCDPCommand('DOM.describeNode', {
|
||||
objectId: id,
|
||||
});
|
||||
},
|
||||
getFullAXTree: () => {
|
||||
return this.mainFrame()
|
||||
.context()
|
||||
.sendCDPCommand('Accessibility.getFullAXTree');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
override get accessibility(): Accessibility {
|
||||
return this.#accessibility;
|
||||
}
|
||||
|
||||
override browser(): Browser {
|
||||
@ -374,7 +394,7 @@ export class Page extends PageBase {
|
||||
const width = viewport.width;
|
||||
const height = viewport.height;
|
||||
const deviceScaleFactor = 1;
|
||||
const screenOrientation = {angle: 0, type: 'portraitPrimary'};
|
||||
const screenOrientation = {angle: 0, type: 'portraitPrimary' as const};
|
||||
|
||||
await this.mainFrame()
|
||||
.context()
|
||||
|
@ -209,6 +209,12 @@
|
||||
"parameters": ["cdp", "firefox"],
|
||||
"expectations": ["SKIP", "TIMEOUT"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[accessibility.spec] *",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["chrome", "webDriverBiDi"],
|
||||
"expectations": ["PASS"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[ariaqueryhandler.spec] *",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
@ -2363,6 +2369,24 @@
|
||||
"parameters": ["cdp", "firefox"],
|
||||
"expectations": ["SKIP"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[accessibility.spec] Accessibility get snapshots while the tree is re-calculated",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["chrome", "webDriverBiDi"],
|
||||
"expectations": ["FAIL"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[accessibility.spec] Accessibility should report uninteresting nodes",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["chrome", "webDriverBiDi"],
|
||||
"expectations": ["FAIL"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[accessibility.spec] Accessibility should work",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["chrome", "webDriverBiDi"],
|
||||
"expectations": ["FAIL"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[CDPSession.spec] Target.createCDPSession should send events",
|
||||
"platforms": ["win32"],
|
||||
|
Loading…
Reference in New Issue
Block a user