browser-daemon-client
Async client for browser-daemon: Playwright runs over HTTP, sessions and logins, with nothing but aiohttp
Downloads & Community Adoption
Health & Engineering Analysis (5 Pillars)
1. Governance & Community50 / 200 ▾
2. PEP Metadata & Packaging150 / 200 ▾
3. Security & Supply Chain200 / 200 ▾
4. Documentation, SEO & Ecosystem155 / 200 ▾
5. Engineering, CI & Quality165 / 200 ▾
Official Documentation & Usage Guide — browser-daemon-client
Show full original documentation (English README) ▾
browser-daemon-client
Async Python client for browser-daemon,
with nothing but aiohttp: made for Home Assistant integrations and other code
that cannot carry Playwright.
import aiohttp
from browser_daemon_client import BrowserDaemon, RunError, step
async with aiohttp.ClientSession() as http:
bd = BrowserDaemon(
http, "https://browser.example.org", secret, client="Home Assistant · HR WORKS"
)
try:
res = await bd.run(
profile="work",
url="https://hr.example.org/login",
steps=[
step.fill("#user", arg="user"),
step.fill("#password", arg="password"),
step.click("role=button[name='Sign in']"),
step.wait_for(".dashboard"),
step.text(".balance", as_="balance"),
],
args={"user": user, "password": password},
)
except RunError as err:
print(err, err.run.url) # err.run.screenshot: the tab, as a base64 PNG
else:
print(res.result["balance"])
run(): a Playwrightscript(a JavaScript function expression) orsteps, in a profile's browser, a session or a throwaway browser. Runs for a profile go to the node that has it. See docs/run.md.login(session_id, tab, username, password, ...): submit credentials in an existing Chromium tab and return aLoginResult.outcome. Setsuccess_selectorto visible page evidence before treating the result as authenticated; see docs/run.md.overview(),find_profile(),sessions(),session(),create_session(),delete_session(),set_idle_timeout(),tabs(),open_tab(),close_tab(),export_auth()(a page's cookies and storage; never log them).place_browser(profile=..., node=..., group=..., engine=...)selects a matching node and moves an idle existing profile there.create=Truepermits a missing profile for a subsequent session or run; it reserves nothing.create_session(profile="work", group="cloud")places the profile before opening it and returnsnode_namefor subsequent node-specific calls. Supplying bothprofileandnodealso enables automatic placement. See profile placement for transfer restrictions and failure behavior.create_session(ephemeral_node=True)provisions a dedicated node and returns itsnode_urlalongside the session, andnode_secret(node_tokenfor a viewer's token): the node never gets the cluster secret, so present that to it (headerX-Browser-Cluster-Secret, or?auth=with a token). Connect to that node with the session ID; the session and node are removed after the last client disconnects.node=sends a request to another node of the mesh through this one.read_secret()reads the cluster secret from its file.
Errors are BrowserDaemonError (with status), and for runs RunError and
RunTimeout (with the whole answer in .run).
Releasing
The client has the daemon's version and is released with it: just release-prepare X.Y.Z
bumps pyproject.toml with Cargo.toml, and the signed vX.Y.Z tag makes the
python job of the release workflow publish it to PyPI through trusted
publishing (the pypi environment; no token is stored anywhere). test.yaml
tests it on every change.