From fb1b46923036c6f642a651fc505aa504c5821dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Wed, 7 Oct 2026 10:27:36 +0200 Subject: [PATCH 1/3] Document classic WebDriver and add a WebDriverServer alias The browser now serves classic WebDriver (driver.get, find_element, click, execute_script, ...) next to BiDi on `serve --protocol webdriver`, so the docs saying those commands 404 are stale. Lead the Selenium examples with plain classic code, add WebDriverServer and AsyncWebDriverServer as aliases of the BiDi classes, and cover a classic Selenium session in the tests. --- README.md | 43 ++++++++++++++--------------- lightpanda/__init__.py | 9 ++++--- lightpanda/bidi.py | 54 ++++++++++++++++++++----------------- tests/test_bidi_selenium.py | 37 ++++++++++++++++++++----- 4 files changed, 89 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 0208a78..4eeba8f 100644 --- a/README.md +++ b/README.md @@ -87,36 +87,37 @@ cannot serve MCP and CDP from the same one). The package itself needs only Python's standard library; Playwright is a dev-only test dependency and `connect_over_cdp` never downloads a browser. -## Drive it with Selenium (WebDriver BiDi) +## Drive it with Selenium (WebDriver) -The browser also speaks [WebDriver BiDi](https://w3c.github.io/webdriver-bidi/). -`BiDiServer` starts `lightpanda serve --protocol webdriver` and hands you the -URL Selenium's `webdriver.Remote` takes as `command_executor`: +The browser also speaks [WebDriver](https://www.w3.org/TR/webdriver2/), both +classic and [BiDi](https://w3c.github.io/webdriver-bidi/). `WebDriverServer` +starts `lightpanda serve --protocol webdriver` and hands you the URL +Selenium's `webdriver.Remote` takes as `command_executor`, so no chromedriver +is involved: ```python -from lightpanda import BiDiServer +from lightpanda import WebDriverServer from selenium import webdriver -from selenium.webdriver.common.options import ArgOptions +from selenium.webdriver.common.by import By -options = ArgOptions() -options.web_socket_url = True # ask for a WebDriver BiDi session - -with BiDiServer() as server: - driver = webdriver.Remote(command_executor=server.http_endpoint, options=options) - context = driver.browsing_context.create(type="tab") - driver.browsing_context.navigate(context=context, url="https://example.com", wait="complete") - print(driver.script.execute("() => document.title", context_id=context)["value"]) +with WebDriverServer() as server: + # Selenium requires an options object; Lightpanda accepts any browser's. + driver = webdriver.Remote(command_executor=server.http_endpoint, options=webdriver.ChromeOptions()) + driver.get("https://example.com") + print(driver.find_element(By.CSS_SELECTOR, "h1").text) driver.quit() ``` -`AsyncBiDiServer` is the asyncio twin, and `server.bidi_endpoint` +In a pytest suite, start the server once in a session-scoped fixture and open +a driver per test; with pytest-xdist each worker gets its own server on its +own free port. + +Set `options.web_socket_url = True` to also get a WebDriver BiDi session and +use `driver.browsing_context` / `driver.script`. `server.bidi_endpoint` (`ws://127.0.0.1:/session`) is the raw BiDi WebSocket for clients that -speak the protocol directly. The browser serves the BiDi modules plus the -classic session bootstrap Selenium needs, not the classic WebDriver -commands: `driver.get`, `find_element` and friends are not implemented, so -drive the page through `driver.browsing_context` and `driver.script` with an -explicit context, created first as above. Pass `args=["--protocol", "cdp"]` -to serve CDP on the same port as well. +speak the protocol directly. `WebDriverServer` is an alias of `BiDiServer`, +`AsyncWebDriverServer` (alias of `AsyncBiDiServer`) is the asyncio twin, and +`args=["--protocol", "cdp"]` serves CDP on the same port as well. ## Respecting robots.txt diff --git a/lightpanda/__init__.py b/lightpanda/__init__.py index 5405d72..984efc9 100644 --- a/lightpanda/__init__.py +++ b/lightpanda/__init__.py @@ -22,8 +22,9 @@ For Playwright or Puppeteer code, ``CDPServer`` runs the browser's own Chrome DevTools Protocol server and hands you the endpoint to connect to -(see its docs for an example). For Selenium, ``BiDiServer`` serves WebDriver -BiDi the same way and hands you the ``command_executor`` URL. +(see its docs for an example). For Selenium, ``BiDiServer`` (alias +``WebDriverServer``) serves WebDriver, classic and BiDi, the same way and +hands you the ``command_executor`` URL. The browser can enforce ``robots.txt``, which is off by default. Pass ``args=["--obey-robots"]`` to any of these and a disallowed request fails @@ -36,7 +37,7 @@ __docformat__ = "google" from .async_browser import AsyncBrowser, AsyncSession, run_script_async -from .bidi import AsyncBiDiServer, BiDiServer +from .bidi import AsyncBiDiServer, AsyncWebDriverServer, BiDiServer, WebDriverServer from .browser import Browser, PageResult, Session, run_script from .cdp import AsyncCDPServer, CDPServer from .errors import LightpandaError, ProcessError, ProtocolError, ScriptError, ToolError @@ -53,6 +54,8 @@ "AsyncCDPServer", "BiDiServer", "AsyncBiDiServer", + "WebDriverServer", + "AsyncWebDriverServer", "LightpandaError", "ProcessError", "ProtocolError", diff --git a/lightpanda/bidi.py b/lightpanda/bidi.py index f4df081..bdf0f32 100644 --- a/lightpanda/bidi.py +++ b/lightpanda/bidi.py @@ -1,8 +1,9 @@ -"""WebDriver BiDi: run ``lightpanda serve --protocol webdriver`` for Selenium and co. +"""WebDriver: run ``lightpanda serve --protocol webdriver`` for Selenium and co. -:class:`BiDiServer` spawns the browser's WebDriver BiDi server on a free -localhost port and owns the process; :class:`AsyncBiDiServer` is the asyncio -twin. See :class:`BiDiServer` for what the browser serves. +:class:`BiDiServer` spawns the browser's WebDriver server (classic and BiDi) +on a free localhost port and owns the process; :class:`AsyncBiDiServer` is the +asyncio twin. ``WebDriverServer`` / ``AsyncWebDriverServer`` are aliases. See +:class:`BiDiServer` for what the browser serves. """ from __future__ import annotations @@ -15,35 +16,34 @@ @_documented class BiDiServer(_ServeProcess): - """A lightpanda process serving WebDriver BiDi on 127.0.0.1. + """A lightpanda process serving WebDriver, classic and BiDi, on 127.0.0.1. + + Also importable as ``WebDriverServer``. ```python from lightpanda import BiDiServer from selenium import webdriver - from selenium.webdriver.common.options import ArgOptions - - options = ArgOptions() - options.web_socket_url = True # ask for a WebDriver BiDi session + from selenium.webdriver.common.by import By with BiDiServer() as server: - driver = webdriver.Remote(command_executor=server.http_endpoint, options=options) - context = driver.browsing_context.create(type="tab") - driver.browsing_context.navigate(context=context, url="https://example.com", wait="complete") - print(driver.script.execute("() => document.title", context_id=context)["value"]) + # Selenium requires an options object; Lightpanda accepts any browser's. + driver = webdriver.Remote(command_executor=server.http_endpoint, options=webdriver.ChromeOptions()) + driver.get("https://example.com") + print(driver.find_element(By.CSS_SELECTOR, "h1").text) driver.quit() ``` :attr:`http_endpoint` is Selenium's ``command_executor``. The browser - serves the BiDi modules (``session``, ``browser``, ``browsingContext``, - ``script``, ``input``) over the WebSocket plus the classic session - bootstrap (``GET /status``, ``POST /session`` with the ``webSocketUrl`` - capability, ``DELETE /session/``); other classic WebDriver commands - such as Selenium's ``driver.get`` or ``find_element`` are not served, so - drive the page through ``driver.browsing_context`` and ``driver.script`` - with an explicit context, created first as above. Pass - ``args=["--protocol", "cdp"]`` to serve CDP on the same port as well - (``--protocol`` is additive). The process is stopped by :meth:`close` / - leaving the ``with`` block, and on Linux also when the interpreter dies. + serves classic WebDriver over HTTP (navigation, element lookup and + interaction, script execution, actions, cookies) and, for a session + created with the ``webSocketUrl`` capability (Selenium's + ``options.web_socket_url = True``), the BiDi modules (``session``, + ``browser``, ``browsingContext``, ``script``, ``input``) over the + WebSocket, reached through ``driver.browsing_context`` and + ``driver.script``. Pass ``args=["--protocol", "cdp"]`` to serve CDP on the + same port as well (``--protocol`` is additive). The process is stopped by + :meth:`close` / leaving the ``with`` block, and on Linux also when the + interpreter dies. """ _protocol = ("--protocol", "webdriver") @@ -82,4 +82,10 @@ async def status(self) -> dict: return await asyncio.to_thread(self._started().status) -__all__ = ["BiDiServer", "AsyncBiDiServer"] +WebDriverServer = BiDiServer +"""Alias of :class:`BiDiServer`: the same server speaks classic WebDriver too.""" + +AsyncWebDriverServer = AsyncBiDiServer +"""Alias of :class:`AsyncBiDiServer`.""" + +__all__ = ["BiDiServer", "AsyncBiDiServer", "WebDriverServer", "AsyncWebDriverServer"] diff --git a/tests/test_bidi_selenium.py b/tests/test_bidi_selenium.py index 1dac250..8736bd8 100644 --- a/tests/test_bidi_selenium.py +++ b/tests/test_bidi_selenium.py @@ -1,15 +1,40 @@ -"""Drive a BiDiServer with Selenium. Selenium is a dev-only dependency: -`webdriver.Remote` needs its pip package, not a driver or browser download, -and this test skips when it is not installed. - -Only the WebDriver BiDi modules are served, so every step goes over the -websocket with an explicit browsing context.""" +"""Drive a BiDiServer with Selenium, over classic WebDriver and over BiDi. +Selenium is a dev-only dependency: `webdriver.Remote` needs its pip package, +not a driver or browser download, and these tests skip when it is not +installed.""" import pytest webdriver = pytest.importorskip("selenium.webdriver") +from selenium.webdriver.common.by import By # noqa: E402 from selenium.webdriver.common.options import ArgOptions # noqa: E402 +from lightpanda import BiDiServer, WebDriverServer # noqa: E402 + + +def test_webdriver_server_alias(): + assert WebDriverServer is BiDiServer + + +def test_selenium_classic_session(bidi_server, fixture_url): + driver = webdriver.Remote(command_executor=bidi_server.http_endpoint, options=webdriver.ChromeOptions()) + try: + driver.get(f"{fixture_url}/index.html") + assert driver.title == "Fixture Home" + assert driver.find_element(By.ID, "headline").text == "Hello from the fixture" + + items = driver.find_elements(By.CSS_SELECTOR, ".item a") + assert [i.text for i in items] == ["First item", "Second item", "Third item"] + + items[0].click() + assert driver.current_url == f"{fixture_url}/other.html" + driver.back() + assert driver.current_url == f"{fixture_url}/index.html" + + assert driver.execute_script("return document.querySelectorAll('.item').length") == 3 + finally: + driver.quit() # DELETE /session/ + def test_selenium_bidi_session(bidi_server, fixture_url): options = ArgOptions() From 70493d9d5b9c201e0a5929c1cdb2b7ee7c7812d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Wed, 7 Oct 2026 10:29:03 +0200 Subject: [PATCH 2/3] Regenerate _methods.py against nightly --- lightpanda/_methods.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lightpanda/_methods.py b/lightpanda/_methods.py index 92c1ed3..03b2b78 100644 --- a/lightpanda/_methods.py +++ b/lightpanda/_methods.py @@ -40,7 +40,7 @@ def detect_forms(self, *, url: str | None = None, timeout: int | None = None) -> """List the forms on the page as JSON: each form's `backendNodeId`, `action`, `method` and `fields`, where each field has `backendNodeId`, `tagName`, `name`, `inputType`, `required`, `disabled`, and when present `value`, `placeholder` and select `options`. Use it before filling a form to see every field it expects. It returns no CSS selectors; get one per field with `nodeDetails` so the fill calls stay replayable. If a url is provided, it navigates there first. Args: - url: Optional URL to navigate to before processing. + url: Optional URL to navigate to before processing. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return self.call("detectForms", url=url, timeout=timeout) @@ -49,7 +49,7 @@ def evaluate(self, *, script: str, url: str | None = None, timeout: int | None = Args: script: JavaScript run in the page context. A bare trailing expression, or `return` with top-level `await`, is the result. - url: Optional URL to navigate to before evaluating. + url: Optional URL to navigate to before evaluating. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. save: Optional bridge-store key. The evaluate's return value is stored under this name and re-exposed as `lp.` to subsequent evaluates. Objects, arrays, and strings are serialized automatically — no JSON.stringify needed. """ @@ -105,7 +105,7 @@ def get_cookies(self, *, url: str | None = None, all: bool | None = None) -> Any """Cookies stored in the browser. Defaults to cookies whose domain matches the current page's host. Pass `url=` to filter for another host, or `all=true` to dump every cookie regardless of host. Useful for debugging authentication and session state. Args: - url: Restrict output to cookies matching this URL's host. Defaults to the current page. + url: Restrict output to cookies matching this URL's host. Defaults to the current page. An empty string is treated as omitted. all: If true, dump every cookie regardless of host. Overrides `url`. """ return self.call("getCookies", url=url, all=all) @@ -158,7 +158,7 @@ def html(self, *, selector: str | None = None, backend_node_id: int | None = Non backend_node_id: Optional backend node ID. When set, dump only that node's outerHTML. 0 is treated as omitted. max_bytes: Optional soft cap on output size in bytes. Content is truncated at a UTF-8 boundary and a short '[truncated]' marker is appended past the cap. strip: Optional. Omit element groups from the output: `js` (script, noscript, script preloads), `css` (style, stylesheet links), `ui` (css plus img, picture, video, audio, svg, canvas, iframe), `invisible` (elements an author rule or inline style sets to display:none), `shell` (nav, aside, dialog, page-level header/footer and the matching landmark roles; skipped when that would drop most of the text), `clutter` (keep only the main content, in the manner of reader modes; includes `shell` and `invisible`, and falls back to `shell` when it finds too little). {"js":true,"css":true} keeps a page dump small. - url: Optional URL to navigate to before dumping. + url: Optional URL to navigate to before dumping. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return self.call("html", selector=selector, backend_node_id=backend_node_id, max_bytes=max_bytes, strip=strip, url=url, timeout=timeout) @@ -166,7 +166,7 @@ def interactive_elements(self, *, url: str | None = None, timeout: int | None = """List every visible interactive element on the page as a JSON array: native controls, ARIA widgets, contenteditable regions, elements with event listeners, and focusable elements. Each entry has `backendNodeId`, `tagName`, `role`, `name`, `type` (why it counts as interactive), `tabIndex`, and when present `listeners`, `disabled`, `id`, `class`, `href`, `inputType`, `value`, `elementName` and `placeholder`. Use it to survey what can be acted on; to locate one element by role or name, `findElement` is cheaper. If a url is provided, it navigates there first. Args: - url: Optional URL to navigate to before processing. + url: Optional URL to navigate to before processing. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return self.call("interactiveElements", url=url, timeout=timeout) @@ -175,7 +175,7 @@ def links(self, *, limit: int | None = None, url: str | None = None, timeout: in Args: limit: Optional. Return at most this many links, in document order. - url: Optional URL to navigate to before processing. + url: Optional URL to navigate to before processing. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return self.call("links", limit=limit, url=url, timeout=timeout) @@ -187,7 +187,7 @@ def markdown(self, *, selector: str | None = None, backend_node_id: int | None = backend_node_id: Optional backend node ID. Render markdown for just that node's subtree. 0 is treated as omitted. max_bytes: Optional soft cap on output size in bytes. Content is truncated at a UTF-8 boundary and a short '[truncated]' marker is appended past the cap. strip: Optional. Omit element groups from the output; same groups as the html tool's strip. `shell` (page chrome by markup) and `clutter` (keep only the main content, in the manner of reader modes) are the ones that matter for reading; `ui` also drops images. - url: Optional URL to navigate to before rendering. + url: Optional URL to navigate to before rendering. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return self.call("markdown", selector=selector, backend_node_id=backend_node_id, max_bytes=max_bytes, strip=strip, url=url, timeout=timeout) @@ -223,7 +223,7 @@ def screenshot(self, *, path: str | None = None, selector: str | None = None, ba backend_node_id: Optional backend node ID. When set, render only that node. 0 is treated as omitted. full_page: Render the whole content height instead of one viewport. Defaults to false. strip: Optional. Omit element groups from the render; same groups as the html tool's strip (`js`, `css`, `ui`, `invisible`, `shell`, `clutter`). - url: Optional URL to navigate to before rendering. + url: Optional URL to navigate to before rendering. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return self.call("screenshot", path=path, selector=selector, backend_node_id=backend_node_id, full_page=full_page, strip=strip, url=url, timeout=timeout) @@ -288,7 +288,7 @@ def structured_data(self, *, url: str | None = None, timeout: int | None = None) """Page metadata as JSON: `jsonLd` (each JSON-LD block as a string), `openGraph`, `twitterCard`, `meta` and `links` (key/value lists), plus `alternate` (hreflang variants) and `linkHeaders` (relations from the HTTP Link header) when present. Empty sections come back as empty arrays. Use it for publisher-declared facts such as product price, article author or canonical URL before scraping the visible text for them. If a url is provided, it navigates there first. Args: - url: Optional URL to navigate to before processing. + url: Optional URL to navigate to before processing. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return self.call("structuredData", url=url, timeout=timeout) @@ -296,7 +296,7 @@ def tree(self, *, url: str | None = None, timeout: int | None = None, backend_no """Semantic outline of the page as indented text: one node per line with its role, accessible name, value and backendNodeId, plus checked state and select options with the selected one marked. The default first read of an unfamiliar page; input and select values are already here, so no `nodeDetails` call is needed to read them. Pass `backendNodeId` to scope to a subtree and `maxDepth` to survey structure before going deeper. Read it again after any page-changing action, since the DOM it describes may have changed; use `nodeDetails` to turn a backendNodeId into a CSS selector for actions. Args: - url: Optional URL to navigate to before fetching the semantic tree. + url: Optional URL to navigate to before fetching the semantic tree. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. backend_node_id: Optional backend node ID to get the tree for a specific element instead of the document root. 0 is treated as omitted. max_depth: Optional maximum depth of the tree to return. Useful for exploring high-level structure first. @@ -353,7 +353,7 @@ async def detect_forms(self, *, url: str | None = None, timeout: int | None = No """List the forms on the page as JSON: each form's `backendNodeId`, `action`, `method` and `fields`, where each field has `backendNodeId`, `tagName`, `name`, `inputType`, `required`, `disabled`, and when present `value`, `placeholder` and select `options`. Use it before filling a form to see every field it expects. It returns no CSS selectors; get one per field with `nodeDetails` so the fill calls stay replayable. If a url is provided, it navigates there first. Args: - url: Optional URL to navigate to before processing. + url: Optional URL to navigate to before processing. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return await self.call("detectForms", url=url, timeout=timeout) @@ -362,7 +362,7 @@ async def evaluate(self, *, script: str, url: str | None = None, timeout: int | Args: script: JavaScript run in the page context. A bare trailing expression, or `return` with top-level `await`, is the result. - url: Optional URL to navigate to before evaluating. + url: Optional URL to navigate to before evaluating. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. save: Optional bridge-store key. The evaluate's return value is stored under this name and re-exposed as `lp.` to subsequent evaluates. Objects, arrays, and strings are serialized automatically — no JSON.stringify needed. """ @@ -418,7 +418,7 @@ async def get_cookies(self, *, url: str | None = None, all: bool | None = None) """Cookies stored in the browser. Defaults to cookies whose domain matches the current page's host. Pass `url=` to filter for another host, or `all=true` to dump every cookie regardless of host. Useful for debugging authentication and session state. Args: - url: Restrict output to cookies matching this URL's host. Defaults to the current page. + url: Restrict output to cookies matching this URL's host. Defaults to the current page. An empty string is treated as omitted. all: If true, dump every cookie regardless of host. Overrides `url`. """ return await self.call("getCookies", url=url, all=all) @@ -471,7 +471,7 @@ async def html(self, *, selector: str | None = None, backend_node_id: int | None backend_node_id: Optional backend node ID. When set, dump only that node's outerHTML. 0 is treated as omitted. max_bytes: Optional soft cap on output size in bytes. Content is truncated at a UTF-8 boundary and a short '[truncated]' marker is appended past the cap. strip: Optional. Omit element groups from the output: `js` (script, noscript, script preloads), `css` (style, stylesheet links), `ui` (css plus img, picture, video, audio, svg, canvas, iframe), `invisible` (elements an author rule or inline style sets to display:none), `shell` (nav, aside, dialog, page-level header/footer and the matching landmark roles; skipped when that would drop most of the text), `clutter` (keep only the main content, in the manner of reader modes; includes `shell` and `invisible`, and falls back to `shell` when it finds too little). {"js":true,"css":true} keeps a page dump small. - url: Optional URL to navigate to before dumping. + url: Optional URL to navigate to before dumping. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return await self.call("html", selector=selector, backend_node_id=backend_node_id, max_bytes=max_bytes, strip=strip, url=url, timeout=timeout) @@ -479,7 +479,7 @@ async def interactive_elements(self, *, url: str | None = None, timeout: int | N """List every visible interactive element on the page as a JSON array: native controls, ARIA widgets, contenteditable regions, elements with event listeners, and focusable elements. Each entry has `backendNodeId`, `tagName`, `role`, `name`, `type` (why it counts as interactive), `tabIndex`, and when present `listeners`, `disabled`, `id`, `class`, `href`, `inputType`, `value`, `elementName` and `placeholder`. Use it to survey what can be acted on; to locate one element by role or name, `findElement` is cheaper. If a url is provided, it navigates there first. Args: - url: Optional URL to navigate to before processing. + url: Optional URL to navigate to before processing. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return await self.call("interactiveElements", url=url, timeout=timeout) @@ -488,7 +488,7 @@ async def links(self, *, limit: int | None = None, url: str | None = None, timeo Args: limit: Optional. Return at most this many links, in document order. - url: Optional URL to navigate to before processing. + url: Optional URL to navigate to before processing. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return await self.call("links", limit=limit, url=url, timeout=timeout) @@ -500,7 +500,7 @@ async def markdown(self, *, selector: str | None = None, backend_node_id: int | backend_node_id: Optional backend node ID. Render markdown for just that node's subtree. 0 is treated as omitted. max_bytes: Optional soft cap on output size in bytes. Content is truncated at a UTF-8 boundary and a short '[truncated]' marker is appended past the cap. strip: Optional. Omit element groups from the output; same groups as the html tool's strip. `shell` (page chrome by markup) and `clutter` (keep only the main content, in the manner of reader modes) are the ones that matter for reading; `ui` also drops images. - url: Optional URL to navigate to before rendering. + url: Optional URL to navigate to before rendering. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return await self.call("markdown", selector=selector, backend_node_id=backend_node_id, max_bytes=max_bytes, strip=strip, url=url, timeout=timeout) @@ -536,7 +536,7 @@ async def screenshot(self, *, path: str | None = None, selector: str | None = No backend_node_id: Optional backend node ID. When set, render only that node. 0 is treated as omitted. full_page: Render the whole content height instead of one viewport. Defaults to false. strip: Optional. Omit element groups from the render; same groups as the html tool's strip (`js`, `css`, `ui`, `invisible`, `shell`, `clutter`). - url: Optional URL to navigate to before rendering. + url: Optional URL to navigate to before rendering. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return await self.call("screenshot", path=path, selector=selector, backend_node_id=backend_node_id, full_page=full_page, strip=strip, url=url, timeout=timeout) @@ -601,7 +601,7 @@ async def structured_data(self, *, url: str | None = None, timeout: int | None = """Page metadata as JSON: `jsonLd` (each JSON-LD block as a string), `openGraph`, `twitterCard`, `meta` and `links` (key/value lists), plus `alternate` (hreflang variants) and `linkHeaders` (relations from the HTTP Link header) when present. Empty sections come back as empty arrays. Use it for publisher-declared facts such as product price, article author or canonical URL before scraping the visible text for them. If a url is provided, it navigates there first. Args: - url: Optional URL to navigate to before processing. + url: Optional URL to navigate to before processing. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. """ return await self.call("structuredData", url=url, timeout=timeout) @@ -609,7 +609,7 @@ async def tree(self, *, url: str | None = None, timeout: int | None = None, back """Semantic outline of the page as indented text: one node per line with its role, accessible name, value and backendNodeId, plus checked state and select options with the selected one marked. The default first read of an unfamiliar page; input and select values are already here, so no `nodeDetails` call is needed to read them. Pass `backendNodeId` to scope to a subtree and `maxDepth` to survey structure before going deeper. Read it again after any page-changing action, since the DOM it describes may have changed; use `nodeDetails` to turn a backendNodeId into a CSS selector for actions. Args: - url: Optional URL to navigate to before fetching the semantic tree. + url: Optional URL to navigate to before fetching the semantic tree. An empty string is treated as omitted. timeout: Optional timeout in milliseconds. Defaults to 10000. backend_node_id: Optional backend node ID to get the tree for a specific element instead of the document root. 0 is treated as omitted. max_depth: Optional maximum depth of the tree to return. Useful for exploring high-level structure first. From 12a9f0619bd2a9e38149ccb9e6cf0b12a9036c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Wed, 7 Oct 2026 10:29:25 +0200 Subject: [PATCH 3/3] Match goto's new 'Navigated. HTTP 200 OK.' wording in the PageResult test --- tests/test_browser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_browser.py b/tests/test_browser.py index beb0e02..15f0231 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -25,7 +25,7 @@ def test_page_result_carries_status(browser, fixture_url): if not isinstance(ok, PageResult): pytest.skip("binary predates structuredContent on goto") - assert ok.startswith("Navigated successfully"), "the sentence is still the value" + assert ok.startswith("Navigated"), "the sentence is still the value" assert ok.url == f"{fixture_url}/index.html" assert ok.http_status == 200 assert ok.title == "Fixture Home"