You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p><ahref="https://github.com/seleniumbase/SeleniumBase/"><btranslate="no">SeleniumBase</b></a> is an all-in-one Python framework designed to make browser automation, scraping, and testing significantly easier than using standard Selenium. With stealth options (eg. <atranslate="no"href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/ReadMe.md"><btranslate="no">CDP Mode</b></a>) you'll avoid the usual restrictions imposed by websites with bot-detection. Includes a feature that <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/ReadMe.md"><b>makes <spantranslate="no">Playwright</span> stealthy</b>.</p>
55
+
<p><ahref="https://github.com/seleniumbase/SeleniumBase/"><btranslate="no">SeleniumBase</b></a> is an all-in-one Python framework for making browser automation, scraping, and testing significantly easier. Stealth options (like <atranslate="no"href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/ReadMe.md"><btranslate="no">CDP Mode</b></a>) let you avoid bot-detection. Includes <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/ReadMe.md"><b><spantranslate="no">Stealthy Playwright Mode</span></b>.</p>
56
56
57
57
--------
58
58
59
59
📚 Learn from [**over 200 examples** in the **SeleniumBase/examples/** folder](https://github.com/seleniumbase/SeleniumBase/tree/master/examples).
60
60
61
61
🐙 Stealth modes: <atranslate="no"href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/uc_mode.md"><b>UC Mode</b></a> and <atranslate="no"href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/ReadMe.md"><b>CDP Mode</b></a> can bypass bot-detection, solve CAPTCHAs, and call advanced methods from the <ahref="https://chromedevtools.github.io/devtools-protocol/"translate="no">Chrome Devtools Protocol</a>.
62
62
63
-
ℹ️ Many examples run with raw <codetranslate="no"><b>python</b></code>, although some <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md">Syntax Formats</a> expect <ahref="https://docs.pytest.org/en/latest/how-to/usage.html"translate="no"><b>pytest</b></a> (a Python unit-testing framework included with SeleniumBase that can discover, collect, and run tests automatically).
63
+
ℹ️ Some <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md">Syntax Formats</a> use <ahref="https://docs.pytest.org/en/latest/how-to/usage.html"translate="no"><b>pytest</b></a> (a Python unit-testing framework included with SeleniumBase that can discover, collect, and run tests automatically).
Copy file name to clipboardExpand all lines: examples/cdp_mode/ReadMe.md
+22-18Lines changed: 22 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,13 @@
4
4
5
5
🐙 <btranslate="no">SeleniumBase</b> <btranslate="no">CDP Mode</b> is a stealth mode that uses the <ahref="https://chromedevtools.github.io/devtools-protocol/"translate="no">Chrome Devtools Protocol</a> (via <ahref="https://github.com/mdmintz/MyCDP"translate="no"><spantranslate="no">MyCDP</span></a>) to control the web browser. <btranslate="no">CDP Mode</b> can be used as a subset of <b><ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/uc_mode.md"translate="no"><spantranslate="no">UC Mode</span></a></b>, or via <b><ahref="#Pure_CDP_Mode"translate="no">Pure CDP Mode</a></b>, which has sync and async formats. From CDP Mode, you can make Playwright stealthy (<atranslate="no"href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/ReadMe.md">Stealthy Playwright Mode</a>).
(See `examples/cdp_mode/` for up-to-date examples.)
17
21
18
-
--------
22
+
----
19
23
20
24
<!-- YouTube View --><ahref="https://www.youtube.com/watch?v=vt2zsdiNh3U"><imgsrc="https://github.com/user-attachments/assets/82ab2715-727e-4d09-9314-b8905795dc43"title="SeleniumBase on YouTube"width="320" /></a>
21
25
<p>(<b><ahref="https://www.youtube.com/watch?v=vt2zsdiNh3U">Watch "Hacking websites with CDP" on YouTube! ▶️</a></b>)</p>
22
26
23
-
--------
27
+
----
24
28
25
29
<!-- YouTube View --><ahref="https://www.youtube.com/watch?v=gEZhTfaIxHQ"><imgsrc="https://github.com/user-attachments/assets/656977e1-5d66-4d1c-9eec-0aaa41f6522f"title="SeleniumBase on YouTube"width="320" /></a>
26
30
<p>(<b><ahref="https://www.youtube.com/watch?v=gEZhTfaIxHQ">Watch "Web-Scraping with GitHub Actions" on YouTube! ▶️</a></b>)</p>
27
31
28
-
--------
32
+
----
33
+
34
+
ℹ️ Note the differences between <b>UC Mode</b> and <b>CDP Mode</b>:
29
35
30
36
👤 <btranslate="no">UC Mode</b>'s stealth is based on a modified chromedriver (<code>uc_driver</code>) that avoids bot-detection by disconnecting and reconnecting WebDriver from the browser at strategic times. Due to advancements in anti-bot technology, more stealth was needed to bypass advanced bot-detection. (That's where <btranslate="no">CDP Mode</b> comes in.)
31
37
@@ -38,14 +44,12 @@
38
44
* Full access to call any advanced CDP library method.
39
45
* Can be used to make the Playwright library stealthy.
40
46
41
-
--------
47
+
----
42
48
43
-
### 🐙 <btranslate="no">CDP Mode</b> Usage:
49
+
### 🐙 <btranslate="no">CDP Mode</b> Usage (when used as a subset of UC Mode):
44
50
45
51
***`sb.activate_cdp_mode(url)`**
46
52
47
-
> (Call that from a **UC Mode** script)
48
-
49
53
That disconnects WebDriver from Chrome (which prevents detection), and gives you access to `sb.cdp` methods (which don't trigger anti-bot checks).
50
54
51
55
> (**New:** Calling **`sb.open(url)`** from UC Mode also activates CDP Mode now.)
@@ -67,7 +71,7 @@ with SB(uc=True, test=True, locale="en") as sb:
67
71
68
72
(If the CAPTCHA wasn't bypassed automatically when going to the URL, then `sb.solve_captcha()` gets the job done.)
69
73
70
-
--------
74
+
----
71
75
72
76
Here's another example that calls `sb.solve_captcha()`:
@@ -88,13 +92,13 @@ with SB(uc=True, test=True, guest=True) as sb:
88
92
89
93
In many cases, the CAPTCHA will be solved automatically without needing to call `solve_captcha()`.
90
94
91
-
--------
95
+
----
92
96
93
97
You can also use `PyAutoGUI` to click on elements with the mouse by calling `sb.cdp.gui_click_element(selector)`.
94
98
95
99
ℹ️ Note that `PyAutoGUI` is an optional dependency. If calling a method that uses it when not already installed, then `SeleniumBase` installs `PyAutoGUI` at runtime.
96
100
97
-
--------
101
+
----
98
102
99
103
### 🐙 Here are a few common `sb.cdp` methods:
100
104
@@ -127,7 +131,7 @@ To find out if WebDriver is connected or disconnected, call:
127
131
128
132
<b>Note:</b> When <btranslate="no">CDP Mode</b> is initialized from <btranslate="no">UC Mode</b>, the WebDriver is disconnected from the browser. (The stealthy <btranslate="no">CDP-Driver</b> takes over.)
@@ -371,7 +375,7 @@ with SB(uc=True, test=True, locale="en", pls="none") as sb:
371
375
372
376
(<b>Note:</b> Some sites may IP-block you for 36 hours or more if they catch you using regular <spantranslate="no">Selenium WebDriver</span>. Be extra careful when creating and/or modifying automation scripts that run on them.)
ℹ️ When available, calling `sb.METHOD()` redirects to `sb.cdp.METHOD()` when CDP Mode is active. From Pure CDP Mode, always call these methods with `sb.METHOD()` instead of `sb.cdp.METHOD()`.
573
577
574
-
--------
578
+
----
575
579
576
580
<aid="Pure_CDP_Mode"></a>
577
581
@@ -625,7 +629,7 @@ sb.driver.stop()
625
629
626
630
ℹ️ Even if you don't call `sb.driver.stop()`, the browser still quits after the script goes out-of-scope.
627
631
628
-
--------
632
+
----
629
633
630
634
### 🐙 <btranslate="no">CDP Mode</b> Async API / Methods
631
635
@@ -710,7 +714,7 @@ await tab.get_local_storage()
710
714
await tab.set_local_storage(items)
711
715
```
712
716
713
-
--------
717
+
----
714
718
715
719
### 🐙 <btranslate="no">CDP Mode</b> WebElement API / Methods
0 commit comments