Reputation: 202
I understand that the Chrome Devtools protocol exposes the Google Chrome DevTools via APIs to be controlled programmatically, and puppeteer provides a Node.js implementation to do so. However, if I am not wrong, puppeteer doesn't allow us to do everything that the DevTools protocol can do.
If I want to remotely debug my android chrome browser, like I can do manually, by going to "Remote Devices" section of my DevTools, is there a way to do so bypassing puppeteer? Is there a package that lets us access more core functionalities of the DevTools protocol?
Upvotes: 4
Views: 1839
Reputation: 25270
Yes, you can do that. puppeteer is just a wrapper around the Chrome DevTools Protocol. To understand how the protocol works, you might want to have a look at Protocol Fundamentals, where the basics are explained.
To communicate on this lower level, you can also use puppeteer. Check out the CDPSession
documentation, which exposes the "low level" part of the API.
const client = await page.target().createCDPSession(); // creates a "low level" session
await client.send('COMMAND'); // sends the command to the browser
client.on('MESSAGE', () => { /* message from the browser received */ });
If you don't want to use puppeteer, there are multiple other libraries. The most used one for Node.js is chrome-remote-interface, which is more low-level than puppeteer. According to the docs:
chrome-remote-interface [...] is a general purpose 1:1 Node.js binding for the Chrome Debugging Protocol. Use it if you need all the power of the raw protocol, e.g., to implement your own high-level API.
There are also multiple other libraries (also for other languages). You can find a full list here.
Upvotes: 5