Skip to content

Commit

Permalink
Merge pull request #228 from kaliiiiiiiiii/dev
Browse files Browse the repository at this point in the history
1.9.3
  • Loading branch information
kaliiiiiiiiii authored May 23, 2024
2 parents f55ed47 + ccc5a42 commit 8db5ac8
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 21 deletions.
Binary file modified docs/.doctrees/api/ChromeOptions.doctree
Binary file not shown.
Binary file modified docs/.doctrees/environment.pickle
Binary file not shown.
24 changes: 16 additions & 8 deletions docs/_modules/selenium_driverless/types/options/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ <h1>Source code for selenium_driverless.types.options</h1><div class="highlight"
<span class="kn">from</span> <span class="nn">abc</span> <span class="kn">import</span> <span class="n">ABCMeta</span>
<span class="kn">import</span> <span class="nn">typing</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Union</span><span class="p">,</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">List</span>

<span class="kn">from</span> <span class="nn">selenium_driverless.utils.utils</span> <span class="kn">import</span> <span class="n">sel_driverless_path</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.scripts.prefs</span> <span class="kn">import</span> <span class="n">prefs_to_json</span>


Expand All @@ -119,19 +117,28 @@ <h1>Source code for selenium_driverless.types.options</h1><div class="highlight"

<span class="sd"> options should not be reused</span>

<span class="sd"> &quot;&quot;&quot;</span>

<span class="n">use_extension</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> don&#39;t add the chrome-extension by default</span>
<span class="sd"> </span>
<span class="sd"> .. warning::</span>
<span class="sd"> setting proxies and auth while running requires the extension to be added. </span>
<span class="sd"> As an alternative, you might use ``--proxy-server=host:port`` and `Requests-interception &lt;https://kaliiiiiiiiii.github.io/Selenium-Driverless/api/RequestInterception/#request-interception&gt;`_ to provide auth</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_single_proxy</span> <span class="o">=</span> <span class="kc">None</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.utils.utils</span> <span class="kn">import</span> <span class="n">find_chrome_executable</span><span class="p">,</span> <span class="n">IS_POSIX</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.utils.utils</span> <span class="kn">import</span> <span class="n">IS_POSIX</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_proxy</span> <span class="o">=</span> <span class="kc">None</span>
<span class="c1"># self.set_capability(&quot;pageLoadStrategy&quot;, &quot;normal&quot;)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mobile_options</span> <span class="o">=</span> <span class="kc">None</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_binary_location</span> <span class="o">=</span> <span class="n">find_chrome_executable</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_binary_location</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_env</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_extension_paths</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_extensions</span> <span class="o">=</span> <span class="p">[]</span>
Expand Down Expand Up @@ -185,16 +192,14 @@ <h1>Source code for selenium_driverless.types.options</h1><div class="highlight"
<span class="s2">&quot;--no-default-browser-check&quot;</span><span class="p">,</span> <span class="c1"># disable default browser message</span>
<span class="s1">&#39;--homepage=about:blank&#39;</span> <span class="c1"># set homepage</span>
<span class="s2">&quot;--wm-window-animations-disabled&quot;</span><span class="p">,</span> <span class="s2">&quot;--animation-duration-scale=0&quot;</span><span class="p">,</span> <span class="c1"># disable animations</span>
<span class="s2">&quot;--enable-privacy-sandbox-ads-apis&quot;</span> <span class="c1"># ensure window.Fence, window.SharedStorage etc. exist, looks like chrome disables them when using automation</span>
<span class="s2">&quot;--enable-privacy-sandbox-ads-apis&quot;</span>
<span class="c1"># ensure window.Fence, window.SharedStorage etc. exist, looks like chrome disables them when using automation</span>
<span class="p">)</span>
<span class="k">if</span> <span class="n">IS_POSIX</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--password-store=basic&quot;</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span> <span class="o">=</span> <span class="kc">True</span>

<span class="c1"># extension</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add_extension</span><span class="p">(</span><span class="n">sel_driverless_path</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot;files/mv3_extension&quot;</span><span class="p">)</span>

<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">arguments</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
Expand Down Expand Up @@ -365,6 +370,9 @@ <h1>Source code for selenium_driverless.types.options</h1><div class="highlight"
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> path to the Chromium binary</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.utils.utils</span> <span class="kn">import</span> <span class="n">find_chrome_executable</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_binary_location</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_binary_location</span> <span class="o">=</span> <span class="n">find_chrome_executable</span><span class="p">()</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_binary_location</span>

<span class="nd">@binary_location</span><span class="o">.</span><span class="n">setter</span>
Expand Down
5 changes: 5 additions & 0 deletions docs/_modules/selenium_driverless/webdriver/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ <h1>Source code for selenium_driverless.webdriver</h1><div class="highlight"><pr
<span class="c1"># others</span>
<span class="kn">from</span> <span class="nn">cdp_socket.utils.conn</span> <span class="kn">import</span> <span class="n">get_json</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.types.options</span> <span class="kn">import</span> <span class="n">Options</span> <span class="k">as</span> <span class="n">ChromeOptions</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.utils.utils</span> <span class="kn">import</span> <span class="n">sel_driverless_path</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.types</span> <span class="kn">import</span> <span class="n">JSEvalException</span>
<span class="kn">from</span> <span class="nn">selenium_driverless</span> <span class="kn">import</span> <span class="n">EXC_HANDLER</span>

Expand Down Expand Up @@ -229,6 +230,10 @@ <h1>Source code for selenium_driverless.webdriver</h1><div class="highlight"><pr
<span class="k">await</span> <span class="n">is_first_run</span><span class="p">()</span>
<span class="n">user_agent</span> <span class="o">=</span> <span class="k">await</span> <span class="n">get_default_ua</span><span class="p">()</span>

<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">use_extension</span><span class="p">:</span>
<span class="c1"># extension</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">add_extension</span><span class="p">(</span><span class="n">sel_driverless_path</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot;files/mv3_extension&quot;</span><span class="p">)</span>

<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">debugger_address</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.utils.utils</span> <span class="kn">import</span> <span class="n">random_port</span>
<span class="n">port</span> <span class="o">=</span> <span class="n">random_port</span><span class="p">()</span>
Expand Down
12 changes: 12 additions & 0 deletions docs/api/ChromeOptions/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<li class="toctree-l1"><a class="reference internal" href="../Chrome/">webdriver.Chrome</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">ChromeOptions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#selenium_driverless.types.options.Options"><code class="docutils literal notranslate"><span class="pre">Options</span></code></a><ul>
<li class="toctree-l3"><a class="reference internal" href="#selenium_driverless.types.options.Options.use_extension"><code class="docutils literal notranslate"><span class="pre">Options.use_extension</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#selenium_driverless.types.options.Options.arguments"><code class="docutils literal notranslate"><span class="pre">Options.arguments</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#selenium_driverless.types.options.Options.add_argument"><code class="docutils literal notranslate"><span class="pre">Options.add_argument()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#selenium_driverless.types.options.Options.add_arguments"><code class="docutils literal notranslate"><span class="pre">Options.add_arguments()</span></code></a></li>
Expand Down Expand Up @@ -113,6 +114,17 @@ <h1>ChromeOptions<a class="headerlink" href="#chromeoptions" title="Link to this
<p class="admonition-title">Warning</p>
<p>options should not be reused</p>
</div>
<dl class="py attribute">
<dt class="sig sig-object py" id="selenium_driverless.types.options.Options.use_extension">
<span class="sig-name descname"><span class="pre">use_extension</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">True</span></em><a class="headerlink" href="#selenium_driverless.types.options.Options.use_extension" title="Link to this definition"></a></dt>
<dd><p>don’t add the chrome-extension by default</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>setting proxies and auth while running requires the extension to be added.
As an alternative, you might use <code class="docutils literal notranslate"><span class="pre">--proxy-server=host:port</span></code> and <a class="reference external" href="https://kaliiiiiiiiii.github.io/Selenium-Driverless/api/RequestInterception/#request-interception">Requests-interception</a> to provide auth</p>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="selenium_driverless.types.options.Options.arguments">
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">arguments</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">List</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#selenium_driverless.types.options.Options.arguments" title="Link to this definition"></a></dt>
Expand Down
6 changes: 4 additions & 2 deletions docs/genindex/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1227,13 +1227,15 @@ <h2 id="U">U</h2>
<li><a href="../api/Input/#selenium_driverless.input.pointer.Pointer.up">(selenium_driverless.input.pointer.Pointer method)</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="../api/ChromeOptions/#selenium_driverless.types.options.Options.update_pref">update_pref() (selenium_driverless.types.options.Options method)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="../api/RequestInterception/#selenium_driverless.scripts.network_interceptor.Request.url">url (selenium_driverless.scripts.network_interceptor.Request property)</a>
</li>
<li><a href="../api/RequestInterception/#selenium_driverless.scripts.network_interceptor.Request.url_fragment">url_fragment (selenium_driverless.scripts.network_interceptor.Request property)</a>
</li>
<li><a href="../api/ChromeOptions/#selenium_driverless.types.options.Options.use_extension">use_extension (selenium_driverless.types.options.Options attribute)</a>
</li>
<li><a href="../api/ChromeOptions/#selenium_driverless.types.options.Options.user_data_dir">user_data_dir (selenium_driverless.types.options.Options property)</a>
</li>
Expand Down
Binary file modified docs/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/selenium_driverless/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import traceback

EXC_HANDLER = (lambda e: traceback.print_exc())
__version__ = "1.9.2"
__version__ = "1.9.3"
24 changes: 16 additions & 8 deletions src/selenium_driverless/types/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
from abc import ABCMeta
import typing
from typing import Union, Optional, List

from selenium_driverless.utils.utils import sel_driverless_path
from selenium_driverless.scripts.prefs import prefs_to_json


Expand All @@ -40,17 +38,26 @@ class Options(metaclass=ABCMeta):
"""

use_extension: bool = True
"""
don't add the chrome-extension by default
.. warning::
setting proxies and auth while running requires the extension to be added.
As an alternative, you might use ``--proxy-server=host:port`` and `Requests-interception <https://kaliiiiiiiiii.github.io/Selenium-Driverless/api/RequestInterception/#request-interception>`_ to provide auth
"""

def __init__(self) -> None:

self._single_proxy = None
from selenium_driverless.utils.utils import find_chrome_executable, IS_POSIX
from selenium_driverless.utils.utils import IS_POSIX
super().__init__()

self._proxy = None
# self.set_capability("pageLoadStrategy", "normal")
self.mobile_options = None

self._binary_location = find_chrome_executable()
self._binary_location = None
self._env = os.environ
self._extension_paths = []
self._extensions = []
Expand Down Expand Up @@ -104,16 +111,14 @@ def __init__(self) -> None:
"--no-default-browser-check", # disable default browser message
'--homepage=about:blank' # set homepage
"--wm-window-animations-disabled", "--animation-duration-scale=0", # disable animations
"--enable-privacy-sandbox-ads-apis" # ensure window.Fence, window.SharedStorage etc. exist, looks like chrome disables them when using automation
"--enable-privacy-sandbox-ads-apis"
# ensure window.Fence, window.SharedStorage etc. exist, looks like chrome disables them when using automation
)
if IS_POSIX:
self.add_argument("--password-store=basic")

self._is_remote = True

# extension
self.add_extension(sel_driverless_path() + "files/mv3_extension")

@property
def arguments(self) -> typing.List[str]:
"""
Expand Down Expand Up @@ -275,6 +280,9 @@ def binary_location(self) -> str:
"""
path to the Chromium binary
"""
from selenium_driverless.utils.utils import find_chrome_executable
if self._binary_location is None:
self._binary_location = find_chrome_executable()
return self._binary_location

@binary_location.setter
Expand Down
3 changes: 2 additions & 1 deletion src/selenium_driverless/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def find_chrome_executable():
"""
candidates = set()
if IS_POSIX:
for item in os.environ.get("PATH").split(os.pathsep):
for item in os.environ.get("PATH", "").split(os.pathsep):
for subitem in (
"google-chrome",
"chromium",
Expand Down Expand Up @@ -64,6 +64,7 @@ def find_chrome_executable():
for candidate in candidates:
if os.path.exists(candidate) and os.access(candidate, os.X_OK):
return os.path.normpath(candidate)
raise FileNotFoundError("Couldn't find installed Chrome or Chromium executable")


def sel_driverless_path():
Expand Down
5 changes: 5 additions & 0 deletions src/selenium_driverless/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
# others
from cdp_socket.utils.conn import get_json
from selenium_driverless.types.options import Options as ChromeOptions
from selenium_driverless.utils.utils import sel_driverless_path
from selenium_driverless.types import JSEvalException
from selenium_driverless import EXC_HANDLER

Expand Down Expand Up @@ -148,6 +149,10 @@ async def start_session(self):
await is_first_run()
user_agent = await get_default_ua()

if self._options.use_extension:
# extension
self._options.add_extension(sel_driverless_path() + "files/mv3_extension")

if not self._options.debugger_address:
from selenium_driverless.utils.utils import random_port
port = random_port()
Expand Down

0 comments on commit 8db5ac8

Please sign in to comment.