Chrome-remote-interface: Listen for Client Side Events

Created on 16 Jun 2017  路  3Comments  路  Source: cyrus-and/chrome-remote-interface

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.

question

Most helpful comment

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
        });
    })`
});

All 3 comments

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).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

puppeteer701 picture puppeteer701  路  4Comments

Bnaya picture Bnaya  路  4Comments

zirill picture zirill  路  6Comments

benjamingr picture benjamingr  路  4Comments

vbisbest picture vbisbest  路  5Comments