# Invoking WebGPU mode

**URL:** <https://forum.babylonjs.com/t/invoking-webgpu-mode/48826>\
**Category:** Questions\
**Created:** [March 16, 2024, 10:11pm UTC](https://forum.babylonjs.com/t/invoking-webgpu-mode/48826 "2024-03-16T22:11:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hayden](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/hayden/32/21310_2.png) [@Hayden](https://forum.babylonjs.com/u/Hayden)\
**Post date:** [March 16, 2024, 10:11pm UTC](https://forum.babylonjs.com/t/invoking-webgpu-mode/48826/1 "2024-03-16T22:11:11Z")

</div>

Hello,

so far the WebGPU support for browsers running on Linux is only experimental. But I wanted to try it out to see its effect on the performance of a rather complex scene. I tried to start the engine with the following code, as described in the documentation:

var renderCanvas = document.getElementById(“renderCanvas”);  
var engine = new BABYLON.WebGPUEngine(renderCanvas);  
await engine.initAsync();

But I receive this error message:

Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules

Any idea what I’m doing wrong?

Thanks in advance  
Hayden

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [March 16, 2024, 10:57pm UTC](https://forum.babylonjs.com/t/invoking-webgpu-mode/48826/2 "2024-03-16T22:57:00Z")

</div>

According to the message, you need to make the function, where you use `await` expression, to be an async function.  
The simplest way to do it is to add `async` before `function`.  
Example: the basic PG made async - [Babylon.js Playground](https://playground.babylonjs.com/#ZXPHQ6)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 19, 2024, 5:22pm UTC](https://forum.babylonjs.com/t/invoking-webgpu-mode/48826/3 "2024-03-19T17:22:11Z")

</div>

You can also use the infamous `engine.initAsync().then(() => { ... }) ` instead and remove await

---

<div class="post-metadata">

**Author:** ![akevin498](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akevin498](https://forum.babylonjs.com/u/akevin498)\
**Post date:** [March 21, 2024, 11:14am UTC](https://forum.babylonjs.com/t/invoking-webgpu-mode/48826/4 "2024-03-21T11:14:35Z")

</div>

The error message you’re seeing, “Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules,” indicates that the “await” keyword needs to be used within an  
[dg customer service](https://www.dg-customerfirst.com) async function or a module’s top-level body. To fix this, wrap your code in an async function like so:

```auto
async function startEngine() {
    var renderCanvas = document.getElementById("renderCanvas");
    var engine = new BABYLON.WebGPUEngine(renderCanvas);
    await engine.initAsync();
}

startEngine();

```

By doing this, “await” will be properly used within an async function, resolving the error.
