A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

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

trusktr
2020-02-28

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.

joeyparrish
2020-03-04

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.

trusktr
2020-03-06
try {
  const {foo} = await import(`std:foo`)
} catch (e) { ... }
trusktr
2020-03-06

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