server module

TCPConnection

class TCPConnection(connID, transport, driverFactory)

Marionette client connection.

Dispatches packets received to their correct service destinations and sends back the service endpoint’s return values.

Arguments
  • connID (number) – Unique identifier of the connection this dispatcher should handle.

  • transport (DebuggerTransport) – Debugger transport connection to the client.

  • driverFactory (function) – Factory function that produces a {@link GeckoDriver}.

TCPConnection.createResponse(msgID)

Fail-safe creation of a new instance of {@link Response}.

Arguments
  • msgID (number) – Message ID to respond to. If it is not a number, -1 is used.

Returns

Response – Response to the message with msgID.

TCPConnection.despatch(cmd, resp)

Despatches command to appropriate Marionette service.

Arguments
  • cmd (Command) – Command to run.

  • resp (Response) – Mutable response where the command’s return value will be assigned.

Throws

Error – A command’s implementation may throw at any time.

TCPConnection.execute(cmd)

Executes a Marionette command and sends back a response when it has finished executing.

If the command implementation sends the response itself by calling <code>resp.send()</code>, the response is guaranteed to not be sent twice.

Errors thrown in commands are marshaled and sent back, and if they are not {@link WebDriverError} instances, they are additionally propagated and reported to {@link Components.utils.reportError}.

Arguments
  • cmd (Command) – Command to execute.

TCPConnection.onClosed()

Debugger transport callback that cleans up after a connection is closed.

TCPConnection.onPacket(data)

Callback that receives data packets from the client.

If the message is a Response, we look up the command previously issued to the client and run its callback, if any. In case of a Command, the corresponding is executed.

Arguments
  • number, ?, ?> data (Array.<number,) – A four element array where the elements, in sequence, signifies message type, message ID, method name or error, and parameters or result.

TCPConnection.sayHello()

When a client connects we send across a JSON Object defining the protocol level.

This is the only message sent by Marionette that does not follow the regular message format.

TCPConnection.send(msg)

Delegates message to client based on the provided {@code cmdID}. The message is sent over the debugger transport socket.

The command ID is a unique identifier assigned to the client’s request that is used to distinguish the asynchronous responses.

Whilst responses to commands are synchronous and must be sent in the correct order.

Arguments
  • msg (Message) – The command or response to send.

TCPConnection.sendMessage(msg)

Marshal message to the Marionette message format and send it.

Arguments
  • msg (Message) – The message to send.

TCPConnection.sendRaw(payload)

Send the given payload over the debugger transport socket to the connected client.

Arguments
  • ?> payload (Object.<string,) – The payload to ship.

TCPConnection.sendToClient(resp)

Send given response to the client over the debugger transport socket.

Arguments
  • resp (Response) – The response to send back to the client.

TCPListener

class TCPListener(port)

Bootstraps Marionette and handles incoming client connections.

Starting the Marionette server will open a TCP socket sporting the debugger transport interface on the provided port. For every new connection, a {@link TCPConnection} is created.

Arguments
  • port (number) – Port for server to listen to.

TCPListener.driverFactory()

Function produces a {@link GeckoDriver}.

Determines the application to initialise the driver with.

Returns

GeckoDriver – A driver instance.

TCPListener.start()

Bind this listener to {@link #port} and start accepting incoming socket connections on {@link #onSocketAccepted}.

The marionette.port preference will be populated with the value of {@link #port}.