Home > assistive-playwright-client > ScreenReaderClient
Class giving access to messages from the screen reader. It is a simple wrapper around websocket that stores each incoming message and gives utility functions to wait for specific messages to come.
Signature:
export declare class ScreenReaderClient
Property | Modifiers | Type | Description |
---|---|---|---|
connected | boolean | Whether the websocket object is still connected. | |
messages | string[] | Array of stored messages. Messages are added to this array as soon as they arrive on the websocket, and can be removed by ScreenReaderClient.clearMessages() and ScreenReaderClient.waitForMessage(). | |
socket | Websocket | Websocket object from which messages are received. |
Method | Modifiers | Description |
---|---|---|
clearMessages() | Empties the messages array and returns its previous content. | |
create(url) | static |
Connects to a websocket url and returns a corresponding instance of ScreenReaderClient as soon as it is connected. |
disconnect() | Disconnects the underlying websocket, thus preventing any further message from being received. | |
off(event, listener) | Unregisters a listener for the given event. | |
on(event, listener) | Registers a listener for the message event, that will be called each time a message is received from the screen reader. |
|
on(event, listener) | Registers a listener for the error event, that will be called if an error happens in the connection with the screen reader. |
|
on(event, listener) | Registers a listener for the close event, that will be called when the connection to the screen reader is closed |
|
once(event, listener) | Registers a one-time listener for the message event, that will be called the next time a message is received from the screen reader. |
|
once(event, listener) | Registers a one-time listener for the error event, that will be called if an error happens in the connection with the screen reader. |
|
once(event, listener) | Registers a one-time listener for the close event, that will be called when the connection to the screen reader is closed |
|
waitForMessage(expectedText, options) | Waits for a specific message from the screen reader. | |
waitForMessageCondition(condition, options) | Execute the condition function on each received message until it returns a truthy value or the specified timeout occurs. If there is a timeout, the promise returned by this function is rejected. |