WebGPU adapter: `webgpu.install()` does not install the WebGPU global enum objects

Author: mesheltonCreated Sep 4, 2026Updated Sep 4, 2026

Environment: Electrobun 2.0.1 (Hutch 0.25.0), Cottontail main process, macOS 26.5.1 arm64, bundleWGPU: true, system webview.

What happens

webgpu.install() installs navigator.gpu and GPUCanvasContext on globalThis, but not the WebGPU namespace enum objects a browser also defines:

  • GPUBufferUsage
  • GPUTextureUsage
  • GPUShaderStage
  • GPUMapMode
  • GPUColorWrite

Any code that names one throws Can't find variable: GPUBufferUsage. The adapter already has all of these values internally as WGPUBufferUsage_* / WGPUShaderStage_* constants; they are just not exposed under their web names.

Reproduction

typescript
webgpu.install();
device.createBuffer({ size: 16, usage: GPUBufferUsage.UNIFORM });
// ReferenceError: Can't find variable: GPUBufferUsage

Why it matters

These constants appear in essentially every WebGPU snippet, tutorial, and library, because on the web they are ambient. Requiring 0x0040 in place of GPUBufferUsage.UNIFORM means WebGPU code cannot be moved into an Electrobun main process unchanged, and the failure is a bare ReferenceError that gives no hint the globals are the missing piece. typegpu reads GPUBufferUsage and GPUShaderStage directly, so it cannot allocate a buffer at all.

Given that install() is already in the business of populating globalThis (it sets navigator.gpu and GPUCanvasContext), this reads more like an oversight than a deliberate boundary — but if it is deliberate, saying so in the WebGPU docs would save the guesswork.

Suggested fix

Add the five namespace objects to install(), with the spec's bitflag values:

typescript
g.GPUBufferUsage ??= {
  MAP_READ: 0x0001, MAP_WRITE: 0x0002, COPY_SRC: 0x0004, COPY_DST: 0x0008,
  INDEX: 0x0010, VERTEX: 0x0020, UNIFORM: 0x0040, STORAGE: 0x0080,
  INDIRECT: 0x0100, QUERY_RESOLVE: 0x0200,
};
g.GPUTextureUsage ??= {
  COPY_SRC: 0x01, COPY_DST: 0x02, TEXTURE_BINDING: 0x04,
  STORAGE_BINDING: 0x08, RENDER_ATTACHMENT: 0x10,
};
g.GPUShaderStage ??= { VERTEX: 0x1, FRAGMENT: 0x2, COMPUTE: 0x4 };
g.GPUMapMode ??= { READ: 0x1, WRITE: 0x2 };
g.GPUColorWrite ??= { RED: 0x1, GREEN: 0x2, BLUE: 0x4, ALPHA: 0x8, ALL: 0xf };

Verified against 2.0.1 by installing exactly these from application code.