Skip to content

Commit

Permalink
fixed european search engine nag screen, added tab.get_local_storage …
Browse files Browse the repository at this point in the history
…and tab.set_local_storage methods
  • Loading branch information
ultrafunkamsterdam committed Aug 10, 2024
1 parent 3dc3ec8 commit 2019f9f
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/_build/html/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ <h1>All modules for which code is available</h1>
<li><a href="nodriver/core/_contradict.html">nodriver.core._contradict</a></li>
<li><a href="nodriver/core/browser.html">nodriver.core.browser</a></li>
<li><a href="nodriver/core/config.html">nodriver.core.config</a></li>
<li><a href="nodriver/core/connection.html">nodriver.core.connection</a></li>
<li><a href="nodriver/core/element.html">nodriver.core.element</a></li>
<li><a href="nodriver/core/tab.html">nodriver.core.tab</a></li>
</ul>
Expand Down
56 changes: 56 additions & 0 deletions docs/_build/html/_modules/nodriver/core/tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,62 @@ <h1>Source code for nodriver.core.tab</h1><div class="highlight"><pre>
<span class="k">await</span> <span class="n">checkbox</span><span class="o">.</span><span class="n">mouse_click</span><span class="p">()</span></div>


<div class="viewcode-block" id="Tab.get_local_storage">
<a class="viewcode-back" href="../../../nodriver/classes/tab.html#nodriver.Tab.get_local_storage">[docs]</a>
<span class="k">async</span> <span class="k">def</span> <span class="nf">get_local_storage</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> get local storage items as dict of strings (careful!, proper deserialization needs to be done if needed)</span>

<span class="sd"> :return:</span>
<span class="sd"> :rtype:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">target</span><span class="o">.</span><span class="n">url</span><span class="p">:</span>
<span class="k">await</span> <span class="bp">self</span>

<span class="c1"># there must be a better way...</span>
<span class="n">origin</span> <span class="o">=</span> <span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">url</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

<span class="n">items</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">send</span><span class="p">(</span>
<span class="n">cdp</span><span class="o">.</span><span class="n">dom_storage</span><span class="o">.</span><span class="n">get_dom_storage_items</span><span class="p">(</span>
<span class="n">cdp</span><span class="o">.</span><span class="n">dom_storage</span><span class="o">.</span><span class="n">StorageId</span><span class="p">(</span>
<span class="n">is_local_storage</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">security_origin</span><span class="o">=</span><span class="n">origin</span><span class="p">))</span>
<span class="p">)</span>
<span class="n">retval</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">items</span><span class="p">:</span>
<span class="n">retval</span><span class="p">[</span><span class="n">item</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="n">item</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="k">return</span> <span class="n">retval</span></div>


<div class="viewcode-block" id="Tab.set_local_storage">
<a class="viewcode-back" href="../../../nodriver/classes/tab.html#nodriver.Tab.set_local_storage">[docs]</a>
<span class="k">async</span> <span class="k">def</span> <span class="nf">set_local_storage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">items</span><span class="p">:</span> <span class="nb">dict</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> set local storage.</span>
<span class="sd"> dict items must be strings. simple types will be converted to strings automatically.</span>

<span class="sd"> :param items: dict containing {key:str, value:str}</span>
<span class="sd"> :type items: dict[str,str]</span>
<span class="sd"> :return:</span>
<span class="sd"> :rtype:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">target</span><span class="o">.</span><span class="n">url</span><span class="p">:</span>
<span class="k">await</span> <span class="bp">self</span>
<span class="c1"># there must be a better way...</span>
<span class="n">origin</span> <span class="o">=</span> <span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">url</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

<span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">gather</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">send</span><span class="p">(</span>
<span class="n">cdp</span><span class="o">.</span><span class="n">dom_storage</span><span class="o">.</span><span class="n">set_dom_storage_item</span><span class="p">(</span>
<span class="n">storage_id</span><span class="o">=</span><span class="n">cdp</span><span class="o">.</span><span class="n">dom_storage</span><span class="o">.</span><span class="n">StorageId</span><span class="p">(</span>
<span class="n">is_local_storage</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">security_origin</span><span class="o">=</span><span class="n">origin</span>
<span class="p">),</span>
<span class="n">key</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">key</span><span class="p">),</span>
<span class="n">value</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">val</span><span class="p">),</span>
<span class="p">)</span>
<span class="p">)</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">items</span><span class="o">.</span><span class="n">items</span><span class="p">()])</span></div>


<span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="n">text</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
Expand Down
4 changes: 4 additions & 0 deletions docs/_build/html/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -3936,6 +3936,8 @@ <h2>G</h2>
<li><a href="nodriver/cdp/css.html#nodriver.cdp.css.get_layers_for_node">get_layers_for_node() (in module nodriver.cdp.css)</a>
</li>
<li><a href="nodriver/cdp/page.html#nodriver.cdp.page.get_layout_metrics">get_layout_metrics() (in module nodriver.cdp.page)</a>
</li>
<li><a href="nodriver/classes/tab.html#nodriver.Tab.get_local_storage">get_local_storage() (Tab method)</a>
</li>
<li><a href="nodriver/cdp/css.html#nodriver.cdp.css.get_location_for_selector">get_location_for_selector() (in module nodriver.cdp.css)</a>
</li>
Expand Down Expand Up @@ -9124,6 +9126,8 @@ <h2>S</h2>
<li><a href="nodriver/cdp/page.html#nodriver.cdp.page.set_lifecycle_events_enabled">set_lifecycle_events_enabled() (in module nodriver.cdp.page)</a>
</li>
<li><a href="nodriver/cdp/css.html#nodriver.cdp.css.set_local_fonts_enabled">set_local_fonts_enabled() (in module nodriver.cdp.css)</a>
</li>
<li><a href="nodriver/classes/tab.html#nodriver.Tab.set_local_storage">set_local_storage() (Tab method)</a>
</li>
<li><a href="nodriver/cdp/emulation.html#nodriver.cdp.emulation.set_locale_override">set_locale_override() (in module nodriver.cdp.emulation)</a>
</li>
Expand Down
2 changes: 2 additions & 0 deletions docs/_build/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ <h4>Main objects<a class="headerlink" href="#main-objects" title="Link to this h
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.get_all_linked_sources"><code class="docutils literal notranslate"><span class="pre">Tab.get_all_linked_sources()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.get_all_urls"><code class="docutils literal notranslate"><span class="pre">Tab.get_all_urls()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.get_content"><code class="docutils literal notranslate"><span class="pre">Tab.get_content()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.get_local_storage"><code class="docutils literal notranslate"><span class="pre">Tab.get_local_storage()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.get_window"><code class="docutils literal notranslate"><span class="pre">Tab.get_window()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.inspector_open"><code class="docutils literal notranslate"><span class="pre">Tab.inspector_open()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.inspector_url"><code class="docutils literal notranslate"><span class="pre">Tab.inspector_url</span></code></a></li>
Expand All @@ -392,6 +393,7 @@ <h4>Main objects<a class="headerlink" href="#main-objects" title="Link to this h
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.select_all"><code class="docutils literal notranslate"><span class="pre">Tab.select_all()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.send"><code class="docutils literal notranslate"><span class="pre">Tab.send()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.set_download_path"><code class="docutils literal notranslate"><span class="pre">Tab.set_download_path()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.set_local_storage"><code class="docutils literal notranslate"><span class="pre">Tab.set_local_storage()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.set_window_size"><code class="docutils literal notranslate"><span class="pre">Tab.set_window_size()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.set_window_state"><code class="docutils literal notranslate"><span class="pre">Tab.set_window_state()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.sleep"><code class="docutils literal notranslate"><span class="pre">Tab.sleep()</span></code></a></li>
Expand Down
34 changes: 34 additions & 0 deletions docs/_build/html/nodriver/classes/tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,20 @@ <h2><a class="reference internal" href="#nodriver.Tab.send" title="nodriver.Tab.
:rtype:</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="nodriver.Tab.get_local_storage">
<em class="property"><span class="pre">async</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">get_local_storage</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/nodriver/core/tab.html#Tab.get_local_storage"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodriver.Tab.get_local_storage" title="Link to this definition">#</a></dt>
<dd><p>get local storage items as dict of strings (careful!, proper deserialization needs to be done if needed)</p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p></p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="nodriver.Tab.get_window">
<em class="property"><span class="pre">async</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">get_window</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/nodriver/core/tab.html#Tab.get_window"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodriver.Tab.get_window" title="Link to this definition">#</a></dt>
Expand Down Expand Up @@ -896,6 +910,24 @@ <h2><a class="reference internal" href="#nodriver.Tab.send" title="nodriver.Tab.
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="nodriver.Tab.set_local_storage">
<em class="property"><span class="pre">async</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">set_local_storage</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">items</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/nodriver/core/tab.html#Tab.set_local_storage"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodriver.Tab.set_local_storage" title="Link to this definition">#</a></dt>
<dd><p>set local storage.
dict items must be strings. simple types will be converted to strings automatically.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>items</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.12)"><em>dict</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><em>str</em></a><em>,</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><em>str</em></a><em>]</em>) – dict containing {key:str, value:str}</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p></p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="nodriver.Tab.set_window_size">
<em class="property"><span class="pre">async</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">set_window_size</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">left</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">top</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">width</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1280</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">height</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1024</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/nodriver/core/tab.html#Tab.set_window_size"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodriver.Tab.set_window_size" title="Link to this definition">#</a></dt>
Expand Down Expand Up @@ -1103,6 +1135,7 @@ <h2><a class="reference internal" href="#nodriver.Tab.send" title="nodriver.Tab.
<li><a class="reference internal" href="#nodriver.Tab.get_all_linked_sources"><code class="docutils literal notranslate"><span class="pre">Tab.get_all_linked_sources()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.get_all_urls"><code class="docutils literal notranslate"><span class="pre">Tab.get_all_urls()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.get_content"><code class="docutils literal notranslate"><span class="pre">Tab.get_content()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.get_local_storage"><code class="docutils literal notranslate"><span class="pre">Tab.get_local_storage()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.get_window"><code class="docutils literal notranslate"><span class="pre">Tab.get_window()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.inspector_open"><code class="docutils literal notranslate"><span class="pre">Tab.inspector_open()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.inspector_url"><code class="docutils literal notranslate"><span class="pre">Tab.inspector_url</span></code></a></li>
Expand All @@ -1121,6 +1154,7 @@ <h2><a class="reference internal" href="#nodriver.Tab.send" title="nodriver.Tab.
<li><a class="reference internal" href="#nodriver.Tab.select_all"><code class="docutils literal notranslate"><span class="pre">Tab.select_all()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.send"><code class="docutils literal notranslate"><span class="pre">Tab.send()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.set_download_path"><code class="docutils literal notranslate"><span class="pre">Tab.set_download_path()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.set_local_storage"><code class="docutils literal notranslate"><span class="pre">Tab.set_local_storage()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.set_window_size"><code class="docutils literal notranslate"><span class="pre">Tab.set_window_size()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.set_window_state"><code class="docutils literal notranslate"><span class="pre">Tab.set_window_state()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.sleep"><code class="docutils literal notranslate"><span class="pre">Tab.sleep()</span></code></a></li>
Expand Down
Binary file modified docs/_build/html/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/_build/html/searchindex.js

Large diffs are not rendered by default.

Loading

0 comments on commit 2019f9f

Please sign in to comment.