GPUUncapturedErrorEvent

可用性有限

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

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

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

GPUUncapturedErrorEvent 介面是 WebGPU API 中的事件物件型別,用於 GPUDeviceuncapturederror 事件,用於遙測和報告意外錯誤。

已知錯誤情況應使用 pushErrorScope()popErrorScope() 進行處理。

Event GPUUncapturedErrorEvent

建構函式

GPUUncapturedErrorEvent()

建立一個新的 GPUUncapturedErrorEvent 物件例項。

例項屬性

繼承其父級 Event 的屬性。

error 只讀

一個 GPUError 物件例項,提供對錯誤詳情的訪問。

示例

您可以使用類似以下的機制來捕獲未被錯誤範圍處理的任何錯誤。

js
// …

device.addEventListener("uncapturederror", (event) => {
  // Re-surface the error
  console.error("A WebGPU error was not captured:", event.error.message);
  reportErrorToServer({
    type: event.error.constructor.name,
    message: event.error.message,
  });
});

// …

規範

規範
WebGPU
# gpuuncapturederrorevent

瀏覽器相容性

另見