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 : IAsyncDisposableRemarks
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
| Name | Description |
|---|---|
| DevToolsServer(DevToolsServerOptions?) | Creates a server. Call DevToolsServer.StartAsync to listen. |
DevToolsServer(DevToolsServerOptions?)
DevToolsServer.csCreates a server. Call DevToolsServer.StartAsync to listen.
public DevToolsServer(DevToolsServerOptions? options = null)Parameters
optionsDevToolsServerOptions?- The options, or null for the default options.
Properties
| Name | Description |
|---|---|
| HttpEndpoint | 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. |
| Port | Gets the TCP port the server listens on, once it is started. |
| WebSocketEndpoint | 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. |
HttpEndpoint
DevToolsServer.csWebSocketEndpoint
DevToolsServer.csMethods
| Name | Description |
|---|---|
| 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.csHandleConnectionAsync(WebSocket, CancellationToken)
DevToolsServer.csRuns 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
webSocketWebSocket- The WebSocket of the client.
cancellationTokenCancellationToken- Closes the connection.
Returns
StartAsync(CancellationToken)
DevToolsServer.csStarts listening for the connections of the clients.
public Task StartAsync(CancellationToken cancellationToken = default)Constants
| Name | Description |
|---|---|
| ChromiumVersion | The version of Chromium reported to the clients (Browser.getVersion). |
| ProtocolVersion | The 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"