2

I have the following code example from the CDP page

https://github.com/cyrus-and/chrome-remote-interface/wiki/Async-await-example

const CDP = require('chrome-remote-interface');

async function example() {
    let client;
    try {
        // connect to endpoint
        client = await CDP();
        // extract domains
     
        const {Network, Page} = client;
        // setup handlers
        Network.requestWillBeSent((params) => {
            console.log(params.request.url);
        });
        // enable events then start!
        await Network.enable();
        await Page.enable();
        await Page.navigate({url: 'https://github.com'});
        await Page.loadEventFired();
    } catch (err) {
        console.error(err);
    } finally {
        if (client) {
            await client.close();
        }
    }
}

example();

but when i run it with: node --inspect=9222 getLogs.js

it throws an error: TypeError: Cannot read property 'requestWillBeSent' of undefined

I am completely new to this, so I don't know what else should I do, Network and Page they both are undefined.

Limbo
  • 623
  • 8
  • 24
  • Have you launched chrome like like this? "chrome.exe --remote-debugging-port=9222" – Orion Cygnus Sep 15 '20 at 08:28
  • no, I used node --inspect=9222 getLogs.js, where should I put your command? – Limbo Sep 16 '20 at 05:34
  • well, in the terminal? If you are using windows, open cmd and put it there. If you are using linux/mac, instead of chrome.exe you would have to use whatever alias chrome uses for your OS. – Orion Cygnus Sep 17 '20 at 14:14

1 Answers1

0

Try running node getLogs.jsinstead...

Found a similar issue on https://github.com/cyrus-and/chrome-remote-interface/issues/407

Anush B M
  • 91
  • 1
  • 6