Short answer
Top-Level Await allows you to use the await keyword outside of async functions in ES modules. It is now fully supported in WebKit (Safari 27) and major browsers, meaning your code can handle asynchronous initialization directly at the module root level without wrapping it in an async IIFE or main() function.
Why it matters
Before Top-Level Await, developers had to wrap module-level initialization in asynchronous functions. This feature simplifies syntax and allows native top-level asynchronous code in ES modules. WebKit recently addressed previous inconsistencies, ensuring Safari now matches the spec compliance of other major engines.
How to test support
You can verify support by checking if your browser executes top-level await in a module context. Most modern browsers support this. However, older WebKit versions or non-module contexts (like classic scripts) will fail. Always ensure your code is served as an ES module (type="module") for this to work.
Browser support status
- Safari 27: Full spec compliance achieved.
- Chromium/Firefox: Supported for several versions.
- Older Browsers: May require polyfills or transpilation.
| Feature | Safari 27 | Chromium |
|---|---|---|
| Top-Level Await | Yes | Yes |
| ES Module Context | Required | Required |
Try it live
See your browser's actual capabilities here: JavaScript Test. Also, explore how devices are detected in What is User Agent? and How to Check Device Type.