M
M
Master Ruby2021-10-24 18:43:20
Node.js
Master Ruby, 2021-10-24 18:43:20

How to fix SyntaxError: missing ) after argument list error?

const puppeteer = require('puppeteer')
const results = [];

(async () => {
    const browser = await puppeteer.launch({
        headless: false
    })
    const page = await browser.newPage()
    await page.goto("https://capuk.org/i-want-help/courses/cap-money-course/introduction", {
        waitUntil: 'networkidle2'
    });

    await page.type('#search-form > input[type="text"]', 'bd14ew')
    await page.click('#search-form > input[type="submit"]')

    await page.on('response', response => {
        if (response.url() == "https://capuk.org/ajax_search/capmoneycourses") {
            console.log('XHR response received');
            console.log(await response.json());
        }
    });
}
)()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-10-24
@Dunaevlad

await page.on('response', response => {
-> . does not return , it subscribes to events. This is obvious, but just in case: what happens in the callback will already be a separate asynchronous (pseudo) thread that will run parallel to the main one. If you are sure that this event will fire only once, and you need to wait for it in the main "thread", then you should manually wrap it in , conditionally like this:
page.on('response', async response => {
page.onPromise
Promise

const json = await new Promise(resolve => page.on('response', function onResponse(response) {
  if (response.url() == "https://capuk.org/ajax_search/capmoneycourses") {
    page.off('response', onResponse);
    resolve(response.json());
  }
})); 
console.log('XHR response received');
console.log(json);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question