DevToolsServer Class

A Chrome DevTools Protocol (CDP) server whose browser is the managed browser engine of Meziantou.Framework.WebPlatform: the CDP clients see a headless Chromium browser. Playwright connects to DevToolsServer.HttpEndpoint with BrowserType.ConnectOverCDPAsync (chromium.connectOverCDP() in Node.js), Puppeteer to DevToolsServer.WebSocketEndpoint with puppeteer.connect({ browserWSEndpoint }).

public sealed class DevToolsServer : IAsyncDisposable

Remarks

Each connection gets its own browser: its default browser context and the browser contexts it creates (Target.createBrowserContext). Each browser context runs its pages on its own thread, with its own script engine, cookies and storage. The browser contexts are closed when the client disconnects.

The scripts of the pages run in the process (see the threat model of the script engine), and the documents are fetched by DevToolsServerOptions.DocumentLoader: expose the server to trusted clients only.

Implements

Constructors

NameDescription
DevToolsServer(DevToolsServerOptions?)Creates a server. Call DevToolsServer.StartAsync to listen.

DevToolsServer(DevToolsServerOptions?)

DevToolsServer.cs

Creates a server. Call DevToolsServer.StartAsync to listen.

public DevToolsServer(DevToolsServerOptions? options = null)

Parameters

options DevToolsServerOptions?
The options, or null for the default options.

Properties

NameDescription
HttpEndpointGets the HTTP endpoint of the server, once it is started (e.g. http://127.0.0.1:9222/), to give to BrowserType.ConnectOverCDPAsync: the clients read the WebSocket endpoint from /json/version.
PortGets the TCP port the server listens on, once it is started.
WebSocketEndpointGets the WebSocket endpoint of the browser, once the server is started (e.g. ws://127.0.0.1:9222/devtools/browser/<id>), the webSocketDebuggerUrl of /json/version. Its path is random: the clients that do not know it cannot connect.

HttpEndpoint

DevToolsServer.cs

Gets the HTTP endpoint of the server, once it is started (e.g. http://127.0.0.1:9222/), to give to BrowserType.ConnectOverCDPAsync: the clients read the WebSocket endpoint from /json/version.

public Uri HttpEndpoint { get; }

Property value

Uri

Gets the TCP port the server listens on, once it is started.

public int Port { get; }

Property value

int

WebSocketEndpoint

DevToolsServer.cs

Gets the WebSocket endpoint of the browser, once the server is started (e.g. ws://127.0.0.1:9222/devtools/browser/<id>), the webSocketDebuggerUrl of /json/version. Its path is random: the clients that do not know it cannot connect.

public Uri WebSocketEndpoint { get; }

Property value

Uri

Methods

NameDescription
DisposeAsync()Stops listening, and closes the connections (their browser contexts are closed).
HandleConnectionAsync(WebSocket, CancellationToken)Runs the connection of a client on a WebSocket accepted by the host (e.g. by ASP.NET Core), until the client disconnects or cancellationToken is canceled.
StartAsync(CancellationToken)Starts listening for the connections of the clients.

DisposeAsync()

DevToolsServer.cs

Stops listening, and closes the connections (their browser contexts are closed).

net10.0

public ValueTask DisposeAsync()

net11.0

public ValueTask DisposeAsync()

Returns

ValueTask

HandleConnectionAsync(WebSocket, CancellationToken)

DevToolsServer.cs

Runs the connection of a client on a WebSocket accepted by the host (e.g. by ASP.NET Core), until the client disconnects or cancellationToken is canceled.

public Task HandleConnectionAsync(WebSocket webSocket, CancellationToken cancellationToken = default)

Parameters

webSocket WebSocket
The WebSocket of the client.
cancellationToken CancellationToken
Closes the connection.

Returns

Task

StartAsync(CancellationToken)

DevToolsServer.cs

Starts listening for the connections of the clients.

public Task StartAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken
A token to cancel the operation.

Returns

Task

Constants

NameDescription
ChromiumVersionThe version of Chromium reported to the clients (Browser.getVersion).
ProtocolVersionThe version of the protocol reported to the clients.

ChromiumVersion

The version of Chromium reported to the clients (Browser.getVersion).

public const string ChromiumVersion = "146.0.0.0"

ProtocolVersion

The version of the protocol reported to the clients.

public const string ProtocolVersion = "1.3"