GPUDevice:label 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

安全上下文: 此功能僅在安全上下文(HTTPS)中可用,且支援此功能的瀏覽器數量有限。

注意:此功能在 Web Workers 中可用。

GPUDevice 介面的只讀屬性 label 是一個字串,用於提供一個標籤,方便在 GPUError 訊息或控制檯警告中標識該物件。

一個字串。如果之前沒有設定標籤值,則獲取標籤會返回一個空字串。

示例

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.");
  }

  // Create a GPUDevice
  const device = await adapter.requestDevice();

  // Set a label
  device.label = "my_label";

  // Get a label
  console.log(device.label);

  // …
}

規範

規範
WebGPU
# dom-gpuobjectbase-label

瀏覽器相容性

另見