简体   繁体   English

如何在没有 Puppeteer 的情况下通过 DevTools 协议模拟 Chrome window 中的点击?

[英]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.我最近使用 Puppeteer 和 Electron 制作了一个 Chrome 自动点击器,但这会创建一个 40 兆字节的可执行文件,这对于一个简单的自动点击器来说似乎太过分了。

I've spent hours trying to figure out what exactly Puppeteer does to send clicks, but the closest I got was this link.我花了好几个小时试图弄清楚 Puppeteer 究竟做了什么来发送点击,但我得到的最接近的是这个链接。

However, it is JavaScript.但是,它是 JavaScript。 My Puppeteer auto-clicker controls an external, pre-installed chrome.exe .我的 Puppeteer 自动点击器控制外部预安装的chrome.exe So is it sending JavaScript strings to be evaluated by the browser?那么它是否发送 JavaScript 字符串以供浏览器评估?

I would like to rework my auto-clicker without Node, Puppeteer or Electron, as a standalone executable as opposed to a Chrome extension.我想在没有 Node、Puppeteer 或 Electron 的情况下重新设计我的自动点击器,作为独立的可执行文件,而不是 Chrome 扩展。

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.我可能会使用 C++ 或 Pascal,但我不一定要代码(尽管那会很好),而是更多关于如何与 API Puppeteer 正在交谈的任何东西进行通信。

I think you're looking for the Chrome Devtools API.我认为您正在寻找 Chrome Devtools API。

as a standalone executable as opposed to a Chrome extension作为独立的可执行文件,而不是 Chrome 扩展

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.我不确定您在这里的确切含义,如果您的意思是不依赖 chrome,那么您只是在创建一个自动点击器,并希望 chrome window 和 URL 是正确的。 But that is less about chrome devtools.但这与 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).据我所知,puppiteer 附带的 chrome.exe 注入了来自 puppiteer 或 selenium 的扩展名(但不要引用我的话)。

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

Using the API, I would suggest going for the inspectedWindow maybe, to execute some JS using the eval .使用 API,我建议使用inspectedWindow来使用eval执行一些 JS。

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 Go 从一开始就创建一个基本的扩展首先.. https://developer.chrome.com/extensions/getstarted

From there you can add your extension to a standalone chrome.exe using the startup command params.从那里您可以使用启动命令参数将您的扩展添加到独立的 chrome.exe。

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..或者或者更确切地说是一些进一步的选择.. 将 package 您当前的自动点击器应用程序包括节点和木偶到electron应用程序中,该应用程序可以作为独立的 exe 运行。

Direct to CDP without 3rd Party: https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md直接到 CDP 没有第 3 方: https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在单独的 window(分离)上自动打开带有 chrome window 和 devtools 的 puppeteer? - How to open puppeteer with chrome window and devtools on a separate window (detached) automatically? 如何使用 Puppeteer 和 Chrome DevTools 协议修改请求标头? (可能是JS语法问题) - How to modify request headers using Puppeteer & Chrome DevTools Protocol? (Possibly a JS syntax issue) 如何重定向到chrome-devtools://协议? - How to redirect to the chrome-devtools:// protocol? 在Chrome Devtools协议中,什么是`injectScriptId`? - In Chrome Devtools Protocol, what is `injectedScriptId`? Chrome DevTools 协议:如何获取节点的单击事件处理程序名称 - Chrome DevTools Protocol: How to get click event handler name of a Node Chrome DevTools 协议:如何取消订阅 Page.javascriptDialogOpening 事件 - Chrome DevTools Protocol: How to unsubscribe Page.javascriptDialogOpening event Chrome devtools无法模拟推送事件 - Chrome devtools can't simulate push event Chrome devtools扩展检查窗口 - Chrome devtools extension inspect window 弄清楚如何通过 Chrome DevTools 在网页中加载元素? - Figure out how an element is loaded in webpage via Chrome DevTools? 在 Puppeteer 中如何从默认配置文件切换到 chrome 窗口到所需的配置文件 - In Puppeteer how to switch to chrome window from default profile to desired profile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM