MDN self-hosted library · e01.org

Navigator: gpu property

WebGPU API

Open notebook · 1 cells web-api-instance-property upstream source

WebGPU API

The Navigator.gpu read-only property returns the GPU object for the current browsing context, which is the entry point for the WebGPU API.

Value

A GPU object.

Examples

async function init() {
  if (!navigator.gpu) {
    throw Error("WebGPU not supported.");
  }

  const adapter = await navigator.gpu.requestAdapter();
  if (!adapter) {
    throw Error("Couldn't request WebGPU adapter.");
  }

  const device = await adapter.requestDevice();

  // …
}

Specifications

Browser compatibility

See also

  • WebGPU API