Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await is only valid in async function #2

Open
sleepinghead opened this issue Nov 21, 2018 · 1 comment
Open

await is only valid in async function #2

sleepinghead opened this issue Nov 21, 2018 · 1 comment

Comments

@sleepinghead
Copy link

sleepinghead commented Nov 21, 2018

Hi,
so far everything works. Even test.js works.
No I am facing a problem, when I run the following code.
I get following error: SyntaxError: await is only valid in async function

Thank you very much.

****************** CODE *********************

'use strict';

const {expect} = require('chai');
const ChaturbateBrowser = require('../index');

const username = 'XXX';
const cb = new ChaturbateBrowser();

cb.on('init', async (e) => {
console.dir(e.settings);
console.dir(e.chatSettings);
console.dir(e.initializerSettings);
console.log(e.csrftoken);
console.log(e.hasWebsocket);

console.log(await cb.fetch(/api/panel/${e.settings.room}/));
});

cb.on('message', (e) => {
console.log(e.timestamp);
console.log(e.method);
console.dir(e.args);
});

await cb.start();

cb.profile(username);

setTimeout(() => cb.stop(), 10 * 1000);

@Asher-
Copy link

Asher- commented Feb 5, 2021

Top-level await is not allowed by default (it is an experimental Node.js option if you want, but not recommended).

Create an async function where you then call await, then call that function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants