W3cubDocs

/Web APIs

WebTransport: WebTransport() constructor

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The WebTransport() constructor creates a new WebTransport object instance.

Note: This feature is available in Web Workers

Syntax

new WebTransport(url, options)

Parameters

url

A string representing the URL of the HTTP/3 server to connect to. The scheme needs to be HTTPS, and the port number needs to be explicitly specified.

options Optional

An object containing the following properties:

serverCertificateHashes Optional

An array of WebTransportHash objects. If specified, it allows the website to connect to a server by authenticating the certificate against the expected certificate hash instead of using the Web public key infrastructure (PKI). This feature allows Web developers to connect to WebTransport servers that would normally find obtaining a publicly trusted certificate challenging, such as hosts that are not publicly routable, or ephemeral hosts like virtual machines.

WebTransportHash objects contain two properties:

algorithm

A string representing the algorithm to use to verify the hash. Any hash using an unknown algorithm will be ignored.

value

A BufferSource representing the hash value.

Exceptions

NotSupportedError DOMException

Thrown if serverCertificateHashes is specified but the transport protocol does not support this feature.

SyntaxError DOMException

Thrown if the specified url is invalid, if the scheme is not HTTPS, or if the URL includes a fragment.

Examples

const url = "https://example.com:4999/wt";

async function initTransport(url) {
  // Initialize transport connection
  const transport = new WebTransport(url);

  // The connection can be used once ready fulfills
  await transport.ready;

  // ...
}

// ...

async function closeTransport(transport) {
  // Respond to connection closing
  try {
    await transport.closed;
    console.log(`The HTTP/3 connection to ${url} closed gracefully.`);
  } catch (error) {
    console.error(`The HTTP/3 connection to ${url} closed due to ${error}.`);
  }
}

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
WebTransport 97 97 No No 83 No 97 97 No 68 No 18.0
serverCertificateHashes 100 100 No No 86 No 100 100 No 69 No 19.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WebTransport/WebTransport