Is it possible to listen for client side events? I'd like to listen for an event that was fired on a page inside my Chrome instance and react accordingly.
See #167 and this wiki recipe. The general approach is to use Runtime.evaluate to wait for a promise:
await Runtime.evaluate({
awaitPromise: true,
expression: `new Promise((fulfill, reject) => {
document.body.addEventListener('click', fulfill, {
once: true
});
})`
});
@cyrus-and hello. I'm trying this code to wait for event and it always fails with message "Promise was collected" before event is fired.
Runtime.evaluate({
awaitPromise: true,
expression: `new Promise((fulfill, reject) => {
document.addEventListener('page_rendered', fulfill, {
once: true
});
})`
}).then(() => {
console.log('ok');
}).catch((ex) => {
console.log('fail', ex);
});
@SkeLLLa take a look at this FAQ entry. If that doesn't solve your problem please file a new issue with all the details (that piece of code alone is not enough to explain the behavior).
Most helpful comment
See #167 and this wiki recipe. The general approach is to use
Runtime.evaluateto wait for a promise: