I want to wait for async testBrowser function to return from my async run() function. I want the run() function to be called immediately, so its in the main Javascript file
async function run() {
tests.forEach(test => {
var result = await testBrowser(test.id, test.testFunction);
if (result == true) {
alert("proceed");
}
});
}
(async function() {
await run();
})();
The error I get is "await is only valid in async functions, async generators and modules". Ive tried to do an async anonymous function that calls my function and itself, which is the solution for the same question (Calling async function in main file), but I keep getting the error.
I also tried turning my javascript file into a module as suggested by the error message by exporting the run() function, but then I get the error "await is a reserved identifier"
export async function run() {
tests.forEach(test => {
var result = await testBrowser(test.id, test.testFunction);
if (result == true) {
alert("proceed");
}
});
}
Calling the module:
<script type="module" type="text/javascript">
import {run} from './detect-headless.js';
</script>
How can i call this function from my javascript file?