|
2 | 2 |
|
3 | 3 | <h2><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="32"></a> CDP Mode 🐙</h2> |
4 | 4 |
|
5 | | -🐙 <b translate="no">SeleniumBase</b> <b translate="no">CDP Mode</b> is a stealth mode of SeleniumBase that uses the <a href="https://chromedevtools.github.io/devtools-protocol/" translate="no">Chrome Devtools Protocol</a> (via <a href="https://github.com/mdmintz/MyCDP" translate="no"><span translate="no">MyCDP</span></a>) to control the web browser. <b translate="no">CDP Mode</b> can be used either as a subset of <b><a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/uc_mode.md" translate="no"><span translate="no">SeleniumBase UC Mode</span></a></b>, or via <b><a href="#Pure_CDP_Mode" translate="no">Pure CDP Mode</a></b> (<code>sb_cdp</code>), which doesn't use WebDriver at all, and has a slightly different setup. |
| 5 | +🐙 <b translate="no">SeleniumBase</b> <b translate="no">CDP Mode</b> is a stealth mode that uses the <a href="https://chromedevtools.github.io/devtools-protocol/" translate="no">Chrome Devtools Protocol</a> (via <a href="https://github.com/mdmintz/MyCDP" translate="no"><span translate="no">MyCDP</span></a>) to control the web browser. <b translate="no">CDP Mode</b> can be used as a subset of <b><a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/uc_mode.md" translate="no"><span translate="no">UC Mode</span></a></b>, or via <b><a href="#Pure_CDP_Mode" translate="no">Pure CDP Mode</a></b>, which has sync and async formats. From CDP Mode, you can make Playwright stealthy (<a translate="no" href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/ReadMe.md">Stealthy Playwright Mode</a>). |
| 6 | + |
| 7 | +<img src="https://seleniumbase.github.io/other/sb_stealth.png" width="632" alt="High-Level Stealthy Architecture Overview" title="High-Level Stealthy Architecture Overview" /> |
6 | 8 |
|
7 | 9 | -------- |
8 | 10 |
|
| 11 | +### 🎞️ YouTube tutorials that cover CDP Mode: |
| 12 | + |
9 | 13 | <!-- YouTube View --><a href="https://www.youtube.com/watch?v=Mr90iQmNsKM"><img src="https://github.com/user-attachments/assets/91e7ff7b-d155-4ba9-b17b-b097825fcf42" title="SeleniumBase on YouTube" width="320" /></a> |
10 | | -<p>(<b><a href="https://www.youtube.com/watch?v=Mr90iQmNsKM">Watch the CDP Mode tutorial on YouTube! ▶️</a></b>)</p> |
| 14 | +<p>(<b><a href="https://www.youtube.com/watch?v=Mr90iQmNsKM">Watch "Undetectable Automation 4" on YouTube! ▶️</a></b>)</p> |
| 15 | + |
| 16 | +(See `examples/cdp_mode/` for up-to-date examples.) |
11 | 17 |
|
12 | 18 | -------- |
13 | 19 |
|
|
21 | 27 |
|
22 | 28 | -------- |
23 | 29 |
|
24 | | -👤 <b translate="no">UC Mode</b> avoids bot-detection by first disconnecting WebDriver from the browser at strategic times, calling special <code><a href="https://github.com/asweigart/pyautogui">PyAutoGUI</a></code> methods to bypass CAPTCHAs (as needed), and finally reconnecting the <code>driver</code> afterwards so that WebDriver actions can be performed again. Although this approach works for bypassing simple CAPTCHAs, more flexibility is needed for bypassing bot-detection on websites with advanced protection. (That's where <b translate="no">CDP Mode</b> comes in.) |
25 | | - |
26 | | -🐙 <b translate="no">CDP Mode</b> is based on <a href="https://github.com/HyperionGray/python-chrome-devtools-protocol" translate="no">python-cdp</a>, <a href="https://github.com/HyperionGray/trio-chrome-devtools-protocol" translate="no">trio-cdp</a>, and <a href="https://github.com/ultrafunkamsterdam/nodriver" translate="no">nodriver</a>. <code>trio-cdp</code> is an early implementation of <code>python-cdp</code>, and <code>nodriver</code> is a modern implementation of <code>python-cdp</code>. (Refactored <code>Python-CDP</code> code is imported from <a href="https://github.com/mdmintz/MyCDP" translate="no">MyCDP</a>.) |
| 30 | +👤 <b translate="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 <b translate="no">CDP Mode</b> comes in.) |
27 | 31 |
|
28 | 32 | 🐙 <b translate="no">CDP Mode</b> includes multiple updates to the above, such as: |
29 | 33 |
|
30 | | -* Sync methods. (Using `async`/`await` is not necessary!) |
31 | | -* The ability to use WebDriver and CDP-Driver together. |
| 34 | +* Using CDP directly, which is stealthier than WebDriver. |
32 | 35 | * Backwards compatibility for existing UC Mode scripts. |
33 | 36 | * More configuration options when launching browsers. |
34 | | -* More methods. (And bug-fixes for existing methods.) |
35 | | -* `PyAutoGUI` integration for advanced stealth abilities. |
36 | | -* Faster response time for support. (Eg. [Discord Chat](https://discord.gg/EdhQTn3EyE)) |
| 37 | +* The ability to use WebDriver and CDP calls together. |
| 38 | +* Full access to call any advanced CDP library method. |
| 39 | +* Can be used to make the Playwright library stealthy. |
37 | 40 |
|
38 | 41 | -------- |
39 | 42 |
|
@@ -66,28 +69,28 @@ with SB(uc=True, test=True, locale="en") as sb: |
66 | 69 |
|
67 | 70 | -------- |
68 | 71 |
|
69 | | -You can also use `PyAutoGUI` to click on elements with the mouse by calling `sb.cdp.gui_click_element(selector)`. Example: |
| 72 | +Here's another example that calls `sb.solve_captcha()`: |
| 73 | +([SeleniumBase/examples/cdp_mode/raw_planetmc.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_planetmc.py)) |
70 | 74 |
|
71 | 75 | ```python |
72 | 76 | from seleniumbase import SB |
73 | 77 |
|
74 | | -with SB(uc=True, test=True) as sb: |
| 78 | +with SB(uc=True, test=True, guest=True) as sb: |
75 | 79 | url = "www.planetminecraft.com/account/sign_in/" |
76 | 80 | sb.activate_cdp_mode(url) |
77 | 81 | sb.sleep(2) |
78 | | - sb.cdp.gui_click_element("#turnstile-widget div") |
| 82 | + sb.solve_captcha() |
79 | 83 | sb.wait_for_element_absent("input[disabled]") |
80 | 84 | sb.sleep(2) |
81 | 85 | ``` |
82 | 86 |
|
83 | 87 | <img src="https://seleniumbase.github.io/other/planet_mc.png" title="SeleniumBase" width="480"> |
84 | 88 |
|
85 | | -When using `sb.cdp.gui_click_element(selector)` on CF Turnstiles, use the parent `selector` that appears **above** the `#shadow-root` element: |
86 | | -Eg. `sb.cdp.gui_click_element("#turnstile-widget div")` |
| 89 | +In many cases, the CAPTCHA will be solved automatically without needing to call `solve_captcha()`. |
87 | 90 |
|
88 | | -<img src="https://seleniumbase.github.io/other/above_shadow.png" title="SeleniumBase" width="480"> |
| 91 | +-------- |
89 | 92 |
|
90 | | -In most cases, `sb.solve_captcha()` is good enough for CF Turnstiles without needing `sb.cdp.gui_click_element(selector)`. (See [SeleniumBase/examples/cdp_mode/raw_planetmc.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_planetmc.py)) |
| 93 | +You can also use `PyAutoGUI` to click on elements with the mouse by calling `sb.cdp.gui_click_element(selector)`. |
91 | 94 |
|
92 | 95 | ℹ️ Note that `PyAutoGUI` is an optional dependency. If calling a method that uses it when not already installed, then `SeleniumBase` installs `PyAutoGUI` at runtime. |
93 | 96 |
|
@@ -116,7 +119,7 @@ To disconnect again, call: |
116 | 119 |
|
117 | 120 | * **`sb.disconnect()`** |
118 | 121 |
|
119 | | -While disconnected, if you accidentally call a WebDriver method, then <b translate="no">SeleniumBase</b> will attempt to use the <b translate="no">CDP Mode</b> version of that method (if available). For example, if you accidentally call `sb.click(selector)` instead of `sb.cdp.click(selector)`, then your WebDriver call will automatically be redirected to the <b translate="no">CDP Mode</b> version. Not all WebDriver methods have a matching <b translate="no">CDP Mode</b> method. In that scenario, calling a WebDriver method while disconnected could raise an error, or make WebDriver automatically reconnect first. |
| 122 | +While disconnected, if you call a WebDriver method, then <b translate="no">SeleniumBase</b> will attempt to use the <b translate="no">CDP Mode</b> version of that method (if available). For example, if you call `sb.click(selector)` instead of `sb.cdp.click(selector)`, then your WebDriver call will automatically be redirected to the <b translate="no">CDP Mode</b> version. Not all WebDriver methods have a matching <b translate="no">CDP Mode</b> method. In that scenario, calling a WebDriver method while disconnected could raise an error, or make WebDriver automatically reconnect first. |
120 | 123 |
|
121 | 124 | To find out if WebDriver is connected or disconnected, call: |
122 | 125 |
|
|
0 commit comments