@@ -71,13 +71,21 @@ def __init__(self, browser: Browser, session_id: str):
7171
7272 @property
7373 def id (self ) -> str :
74+ """The session id, as the browser knows it."""
7475 return self ._id
7576
7677 def call (self , tool : str , ** kwargs ):
7778 """Invoke a browser tool by name. The generated methods route here.
7879
79- Returns parsed JSON for JSON-carrying tools, ``bytes`` for image
80- results (``screenshot`` without ``path``), otherwise the result text.
80+ Accepts the tool and argument names as the browser declares them
81+ (``waitForSelector``, ``backendNodeId``) as well as their snake_case
82+ forms. Returns parsed JSON for JSON-carrying tools, ``bytes`` for
83+ image results (``screenshot`` without ``path``), otherwise the result
84+ text. Raises :class:`ToolError` when the tool reports a failure.
85+
86+ Args:
87+ tool: The tool name.
88+ **kwargs: The tool's arguments; ``None`` values are omitted.
8189 """
8290 if self ._closed :
8391 raise ToolError (f"session { self ._id } is closed" )
@@ -124,6 +132,8 @@ def __getattr__(self, attr: str):
124132 raise AttributeError (f"{ type (self ).__name__ !r} object has no attribute { attr !r} " )
125133
126134 def close (self ) -> None :
135+ """Release the session's page. Idempotent; calls made after this
136+ raise :class:`ToolError`. Closing the browser closes every session."""
127137 if not self ._closed :
128138 self ._closed = True
129139 self ._client .delete_session (self ._id )
@@ -151,8 +161,19 @@ def __init__(
151161 verbose : bool = False ,
152162 args : Sequence [str ] = (),
153163 ):
154- """``args`` are extra CLI flags for the spawned browser process
155- (e.g. ``["--http-cache-dir", path]`` or cookie flags)."""
164+ """Spawn the browser process and fetch its tool list.
165+
166+ Args:
167+ binary: Path to a lightpanda binary. When omitted, resolved from
168+ the ``LIGHTPANDA_BIN`` environment variable, then the binary
169+ bundled in the package, then ``PATH``.
170+ env: Extra environment variables for the spawned process.
171+ timeout: Seconds to wait for a response to any request before
172+ raising :class:`ProtocolError`.
173+ verbose: Let the browser's own logging through to stderr.
174+ args: Extra CLI flags for the spawned browser process, e.g.
175+ ``["--http-cache-dir", path]`` or cookie flags.
176+ """
156177 self ._client = Client (binary = binary , env = env , timeout = timeout , verbose = verbose , args = args )
157178 self ._seq = itertools .count (1 )
158179 listed = self ._client .request ("tools/list" )
@@ -171,11 +192,14 @@ def tools(self) -> dict[str, dict]:
171192 return self ._tools
172193
173194 def new_session (self ) -> Session :
195+ """Open a new isolated browsing context: its own page, cookies and
196+ memory. Close it with :meth:`Session.close` or a ``with`` block."""
174197 # itertools.count is atomic, so concurrent callers (the async facade's
175198 # worker threads) can't mint duplicate session ids.
176199 return Session (self , f"py{ next (self ._seq )} " )
177200
178201 def close (self ) -> None :
202+ """Stop the browser process, closing every session with it."""
179203 self ._client .close ()
180204
181205 def __enter__ (self ):
0 commit comments