I am trying to evaluate a function with puppeteer but the callback is never firing (i am certain the host page is working as expected).
On the host page a listener works like:
DB.when('ready').execute(function(db){
// DB can execute stuff
})
My puppeteer code attempts to fetch the db that is ready:
try {
const dbhandle = await page.evaluate('DB.when("ready")');
const result = await page.evaluate(db => db.execute, function(images) {
console.log(JSON.stringify(images));
//do stuff with callback
}, dbhandle);
console.log('result', JSON.stringify(result));
} catch (e) {
console.log('evaluate', e);
} finally {
console.log('finally');
}
Am having no luck on this.
OMG I figured it out...
try {
function fooBugger() {
return new Promise((resolve, reject) => {
DB.when('ready').execute(function(db) {
if (db) {
resolve(db.some_data);
} else {
reject('nope');
}
});
});
}
const res = await page.evaluate(fooBugger);
console.log('resultHandle', JSON.stringify(res));
} catch (e) {
console.log('evaluateHandle', e);
} finally {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With