Bidi#

Manages interactions using Bidi. At the moment this only works for Firefox but Chrome and maybe other browsers will support it in the future.

Classes#

Bidi

Methods#

getRawClient() → {Promise.<Object>}#

Retrieves the raw client for Bidi.
Throws:
Throws an error if the browser is not supported.
Type
Error
Returns:
A promise that resolves to the Bidi client.
Type: 
Promise.<Object>
Example
CODE
const bidi = commands.bidi.getRawClient();

(async) onMessage(f)#

Add a fanction that will get the events that you subscribes.
Parameters:
NameTypeDescription
ffunctionThe callback function to handle incoming messages. The function will get an event passed on to it. Remember to subscribe to the event.
Throws:
Throws an error if the method is called in a browser other than Firefox.
Type
Error
Example
CODE
await commands.bidi.onMessage(function(event) {
const myEvent = JSON.parse(Buffer.from(event.toString()));
console.log(myEvent);
});

(async) send(parameters) → {Promise.<Object>}#

Sends a command using Bidi.
Parameters:
NameTypeDescription
parametersObjectThe paramaters for the command.
Throws:
Throws an error if the browser is not supported or if the command fails.
Type
Error
Returns:
A promise that resolves when the command has been sent.
Type: 
Promise.<Object>
Example
CODE
const params = {
method: 'script.addPreloadScript',
params: {
functionDeclaration: "function() {alert('hello')}"
}
};
await commands.bidi.send(params);

(async) subscribe(messageType) → {Promise.<Object>}#

Subscribe to a event.
Parameters:
NameTypeDescription
messageTypestringThe type of message to subscribe to.
Throws:
Throws an error if the method is called in a browser other than Firefox.
Type
Error
Returns:
A promise that resolves you have subscribed.
Type: 
Promise.<Object>
Example
CODE
// Subscribe to requests before they are sent
await commands.bidi.subscribe('network.beforeRequestSent');

(async) unsubscribe(messageType) → {Promise.<Object>}#

Unsubscribe to an event.
Parameters:
NameTypeDescription
messageTypestringThe type of message to unsubscribe to.
Throws:
Throws an error if the method is called in a browser other than Firefox.
Type
Error
Returns:
A promise that resolves you have unsubscribed.
Type: 
Promise.<Object>
Example
CODE
// Unsubscribe to requests before they are sent
await commands.bidi.unsubscribe('network.beforeRequestSent');