New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Examples of CDP with interactive pages #38
Comments
Hi @zfLQ2qx2, the protocol does allow you to do most of these things but it is quite low-level and some functionality can only be achieved by evaluating JavaScript on the page. I'm a bit short on examples, but I have another project, asdev, that uses cdp to perform some of these things, e.g. submit forms, attach files and click buttons. Feel free to look there for inspiration. To perform actual mouse clicks, you would use the protocol to figure out the position of an element and then use e.g. There are also some examples in the chrome-remote-interface Wiki (e.g. wait for a specific element). These are in JS but should be fairly simple to translate to Go/cdp. Regarding sub-windows, you might have to keep track of frames (see frame related events in Hope this helps! |
@mafredri That is exactly what I was looking for, thank you! |
@mafredri I've made some progress on this, I can detect windows being opened via TargetCreated events. The TargetCreated reply includes a TargetID. Is it correct that in order to interact with this new window I would need to lookup its url from the debugger /json/list URL, open an additional websocket, and create an additional cdp client? |
It's not necessary to use It's also possible to utilize the existing websocket with For now it's probably easiest to open up a new websocket (and client). |
Just for the benefit of anyone who reads this later, I saw a gist elsewhere where someone recommended using Target.SetAutoAttach to attach to new instances and make them wait for a debugger to attach, when a new target opens we would then open a new cdp connection to it, put all of the event handlers in place for it, then do Runtime.RunIfWaitingForDebugger to put the new target in motion. |
Can someone point me to some examples of using the cdp package with an interactive web page? I see a lot of examples of loading a page and querying the DOM, but nothing covering how to move the mouse, click elements, tap elements, fill a form, attach a file to a form, interact with dialogs and subwindows, etc.
The text was updated successfully, but these errors were encountered: