Reputation: 2483
I'm completely new to nodejs.
So I'm using puppeteer to call a webpage, I want to check if Jupyter exists on the webpage.
await page.evaluate((sel) => {
if (typeof Jupyter == 'undefined') {
jupyterundefined = true;
return;
} else {
Jupyter.notebook.clear_all_output();
}
}, 'dummy');
await page.waitFor(60000);
if(jupyterundefined){
//do something else
It seems that the await function doesn't change the jupyterundefined variable, because it's asyn. But how can I check if it returns with the return I have there?
Upvotes: 1
Views: 30
Reputation: 23515
The function page.evaluate(pageFunction[, ...args]) is returning a Promise
that can hold a value, I would advise you to use it.
Like :
const isJupyterUndefined = await page.evaluate((sel) => {
// === void 0 is the same as typeof undefined
if (Jupyter === void 0) {
return true;
}
Jupyter.notebook.clear_all_output();
return false;
}, 'dummy');
await page.waitFor(60000);
if (isJupyterUndefined){
//do something else
Upvotes: 2