Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

how to send message to websocket connection via cpd? #3897

Answered by mdmintz
dima23113 asked this question in Q&A
Discussion options

Hi! Please share the method of sending a message to a websocket connection.
I open a site, it has a websocket connection and I want to send something there, I just don't understand how

You must be logged in to vote

For non-UI actions using CDP, you'll first need to find a valid CDP method for it here: https://chromedevtools.github.io/devtools-protocol/ (Eg. in https://chromedevtools.github.io/devtools-protocol/tot/Network/ or https://chromedevtools.github.io/devtools-protocol/tot/Page/). And then find the Python CDP version for it available here: https://github.com/mdmintz/MyCDP.

Here's an example of calling a CDP method directly from a script:

res = await page.send(mycdp.network.get_response_body(request[1]))

There are also examples of connection.send() as part of internal methods. Eg:

Replies: 1 comment

Comment options

For non-UI actions using CDP, you'll first need to find a valid CDP method for it here: https://chromedevtools.github.io/devtools-protocol/ (Eg. in https://chromedevtools.github.io/devtools-protocol/tot/Network/ or https://chromedevtools.github.io/devtools-protocol/tot/Page/). And then find the Python CDP version for it available here: https://github.com/mdmintz/MyCDP.

Here's an example of calling a CDP method directly from a script:

res = await page.send(mycdp.network.get_response_body(request[1]))

There are also examples of connection.send() as part of internal methods. Eg:

await connection.send(cdp.page.navigate("about:blank"))

From within a script, you can access the send() method from a Tab object. Eg:

tab = sb.cdp.get_active_tab()
tab.send(mycdp.DOMAIN.METHOD_NAME(ARGS))

For example, mycdp.page.navigate(URL) is a CDP call that can be sent via the send() method.

To use mycdp directly in a SeleniumBase script, be sure to import it first:

import mycdp
You must be logged in to vote
0 replies
Answer selected by mdmintz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /