Creating a swap chain on the device doesn't make it clear from a web developer point of view that this is going to invalidate the previous one created on a context. I believe moving createSwapChain from GPUDevice to GPUCanvasContext would help a lot removing that potential confusion.
const canvas = document.querySelector('canvas');
const context = canvas.getContext('gpupresent');
// Before
const swapChainDescriptor = { context: context, format: 'bgra8unorm' };
const swapChain = device.createSwapChain(swapChainDescriptor);
const format = await device.getSwapChainPreferredFormat(context);
// After
const swapChainDescriptor = { device: device, format: 'bgra8unorm' };
const swapChain = context.createSwapChain(swapChainDescriptor);
const format = await context.getSwapChainPreferredFormat(device);
Creating a swap chain on the device doesn't make it clear from a web developer point of view that this is going to invalidate the previous one created on a context. I believe moving
createSwapChainfrom GPUDevice to GPUCanvasContext would help a lot removing that potential confusion.