Search code examples
javascriptgoogle-chromegoogle-chrome-devtoolspuppeteerdevtools

How to simulate clicks in a Chrome window via the DevTools Protocol without Puppeteer?


I recently made a Chrome auto-clicker using Puppeteer and Electron, but this creates a 40 megabyte executable, which seems like extreme overkill for a simple auto-clicker.

I've spent hours trying to figure out what exactly Puppeteer does to send clicks, but the closest I got was this link.

However, it is JavaScript. My Puppeteer auto-clicker controls an external, pre-installed chrome.exe. So is it sending JavaScript strings to be evaluated by the browser?

I would like to rework my auto-clicker without Node, Puppeteer or Electron, as a standalone executable as opposed to a Chrome extension.

I will probably be using C++ or Pascal but I'm not necessarily asking for code (although that would be nice), but more for how to communicate with whatever API Puppeteer is talking to.


Solution

  • I think you're looking for the Chrome Devtools API.

    as a standalone executable as opposed to a Chrome extension

    I'm not sure exactly what you mean here, if you mean without the dependancy of chrome, then you're just creating an autoclicker and hoping that the chrome window and URL is the correct one. But that is less about chrome devtools.

    As far as I know, the chrome.exe that ships with puppiteer is injected with the extension from puppiteer or selenium for example (but don't quote me on that).

    https://chromedevtools.github.io/devtools-protocol/

    Using the API, I would suggest going for the inspectedWindow maybe, to execute some JS using the eval.

    chrome.devtools.inspectedWindow.eval(
              "document.getElementById('someEl').click();",
               function(eventRes, isException) {
                 // callback ?
               });
    

    Go right from the start though and create a basic extension first.. https://developer.chrome.com/extensions/getstarted

    From there you can add your extension to a standalone chrome.exe using the startup command params.

    Path\To\Google\Chrome\Application\chrome.exe" --load-extension="C:\PAthOfExtension"

    Should get you going.

    Further option

    Alternatively or rather some further options.. Would be to package your current autoclicker application including the node and puppiteer into an electron application which could run as a standalone exe..

    Direct to CDP without 3rd Party : https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md