Answer the question
In order to leave comments, you need to log in
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
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.on
Promise
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 questionAsk a Question
731 491 924 answers to any question