#36738·deno

deno desktop: macOS raw `getNativeWindow()` panics — can only access NSView on the main thread

Author: petamorikenCreated Aug 30, 2026Updated Sep 28, 2026

Version

deno 2.9.6 (aarch64-apple-darwin)
laufey raw / laufey_winit
macOS (Apple Silicon)

Description

On macOS, Deno Desktop's raw backend cannot present WebGPU to the window.

The documented path is:

typescript
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter!.requestDevice();
const win = new Deno.BrowserWindow({ title: "WebGPU", width: 640, height: 480 });
const surface = win.getNativeWindow(); // panics here

getNativeWindow() panics before any configure() / present():

thread '<unnamed>' panicked at raw-window-metal-1.1.0/src/lib.rs:403:44:
can only access NSView on the main thread

This is not a missing WebGPU API. UnsafeWindowSurface.present() exists. The surface is created on the Deno runtime thread, while AppKit/raw-window-metal require NSView / CAMetalLayer access on the main thread.

This panic was already reported in #36594 (see the "Related, but probably a separate issue" section). That ticket is about .app packaging / launch on aarch64-apple-darwin. Filing this as a separate issue as suggested there.

Why

laufey_winit owns the main thread and starts the Deno isolate via laufey_runtime_start on a secondary thread. BrowserWindow.get_native_window (runtime/ops/desktop.rs) then calls instance_create_surface on that JS thread with the raw AppKit handles. wgpu's Metal surface path (raw-window-metal) asserts it is on the main thread and aborts.

So the official raw+WebGPU example cannot run on macOS.

Workaround

Render offscreen, copyTextureToBuffer + mapAsync, and blit RGBA onto the window's CALayer from the main queue. That works, but it is a full GPU→CPU readback every frame and needs --allow-ffi.

Expected

getNativeWindow() / surface.present() work on macOS raw, matching the docs and Windows/Linux.

A fix is to create (and probably resize) the wgpu surface on the main thread — hop through laufey's event loop / dispatch_sync — rather than from the Deno thread. Per-frame present() can stay off-main once the CAMetalLayer exists.

Related


This issue was drafted and filed by an AI assistant (Grok) on behalf of the reporter.