Back to Content

Navigator: gpu property

files/en-us/web/api/navigator/gpu/index.md

latest750 B
Original Source

{{APIRef("WebGPU API")}}{{SecureContext_Header}}

The Navigator.gpu read-only property returns the {{domxref("GPU")}} object for the current browsing context, which is the entry point for the {{domxref("WebGPU_API", "WebGPU API", "", "nocode")}}.

Value

A {{domxref("GPU")}} object.

Examples

js
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

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("WebGPU_API", "WebGPU API", "", "nocode")}}