Maybe new browser APIs should all be `import`ed instead of globals

There are new APIs, like WebGPU, but even though ES Modules already exist in all browsers, the vendors are still designing these APIs as augmentations of the global space.

Why not make them imports instead?

For example,

import {gpu} from 'builtin:webgpu'

or similar.

3 Likes

How would feature detection work? It seems that you can’t put import inside try/catch. So I’m not sure how I would check for browser support for a certain API without that API being in the global scope.

try {
  const {foo} = await import(`std:foo`)
} catch (e) { ... }

@joeyparrish I’m not sure if that previous comment notifies you, so tagging you in this one.