browserwright 0.22.0__tar.gz → 0.23.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {browserwright-0.22.0/src/browserwright.egg-info → browserwright-0.23.1}/PKG-INFO +1 -1
- {browserwright-0.22.0 → browserwright-0.23.1}/pyproject.toml +1 -1
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/__init__.py +12 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/_executor/process.py +57 -13
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/cdp.py +9 -7
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/cli.py +3 -1
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/call_deadline.py +1 -1
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/listener.py +5 -1
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/state.py +38 -2
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/verbs.py +19 -1
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/errors.py +97 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/mode_b_client.py +6 -2
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/repl/_smart_goto.py +121 -16
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/repl/inline.py +13 -2
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/skill_runtime.md +41 -20
- {browserwright-0.22.0 → browserwright-0.23.1/src/browserwright.egg-info}/PKG-INFO +1 -1
- {browserwright-0.22.0 → browserwright-0.23.1}/LICENSE +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/README.md +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/setup.cfg +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/__main__.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/_executor/__init__.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/_executor/__main__.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/_executor/client.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/_executor/protocol.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/_text.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/__init__.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/_ipc.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/_net.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/_rpc.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/_stale.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/backends/__init__.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/backends/base.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/backends/cdp.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/backends/extension.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/cli.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/config.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/doctor.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/errors.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/launch_chrome.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/launchagent.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/observability.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/platforms.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/probe.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/relay_status.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/resolver.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/restart_guard.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/__init__.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/daemon.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/exec_relay.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/executor_registry.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/extension_upstream.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/facade.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/facade_extension.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/proxy.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/relay.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/session_state.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/status.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/upstream.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/upstream_context.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/supervise.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/userscripts.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon_lifecycle.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon_url.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/discovery.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/health.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/install.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/memory/__init__.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/memory/_lock.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/memory/_md.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/memory/_yaml.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/memory/global_mem.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/memory/site_mem.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/output_schema.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/primitives/__init__.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/primitives/discovery_api.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/primitives/http.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/primitives/site.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/repl/__init__.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/repl/_md_convert.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/repl/_md_normalize.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/repl/_namespace.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/repl/markdown.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/repl/playwright_handle.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/repl/search.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/repl/snapshot.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/repl/vendor/README.md +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/repl/vendor/readability.js +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/session.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/session_create.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/session_ctx.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/session_registry.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/session_runtime.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/github.com/SKILL.md +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/github.com/memory.md +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/github.com/tasks/list_issues.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/google.com/SKILL.md +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/google.com/memory.md +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/google.com/tasks/search.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/producthunt.com/SKILL.md +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/producthunt.com/memory.md +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/producthunt.com/tasks/today.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/wikipedia.org/SKILL.md +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/wikipedia.org/memory.md +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/wikipedia.org/tasks/lookup.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/ycombinator.com/SKILL.md +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/ycombinator.com/memory.md +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/site_skills_starter/ycombinator.com/tasks/front_page.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/skill_doc.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/tab_surface.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/task_runner.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/version.py +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright.egg-info/SOURCES.txt +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright.egg-info/dependency_links.txt +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright.egg-info/entry_points.txt +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright.egg-info/requires.txt +0 -0
- {browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: browserwright
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.23.1
|
|
4
4
|
Summary: Browserwright — let AI/code agents drive a real or isolated browser and author userscripts. Single package: the agent-facing REPL/site-skills/memory layer plus the bundled browser-resolving daemon (CDP proxy + extension/cloud backends).
|
|
5
5
|
License-Expression: AGPL-3.0-only
|
|
6
6
|
Requires-Python: >=3.11
|
|
@@ -15,7 +15,7 @@ name = "browserwright"
|
|
|
15
15
|
# stamping regex is `^(version\s*=\s*)["'][^"']+["']\s*$` and CI aborts unless
|
|
16
16
|
# it matches exactly once. `tests/skill/test_release_versioning.py` enforces all
|
|
17
17
|
# of that before a tag is ever pushed. See RELEASING.md.
|
|
18
|
-
version = "0.
|
|
18
|
+
version = "0.23.1"
|
|
19
19
|
description = "Browserwright — let AI/code agents drive a real or isolated browser and author userscripts. Single package: the agent-facing REPL/site-skills/memory layer plus the bundled browser-resolving daemon (CDP proxy + extension/cloud backends)."
|
|
20
20
|
requires-python = ">=3.11"
|
|
21
21
|
license = "AGPL-3.0-only"
|
|
@@ -77,6 +77,18 @@ EXPORTS = [
|
|
|
77
77
|
"BrowserwrightError", "PageLoadFailed", "ElementNotFound", "AuthWall",
|
|
78
78
|
"Captcha", "NetworkError", "DaemonUnavailable", "CDPError",
|
|
79
79
|
"NeedsUserConfirm", "UnsupportedContentType", "TabMatchError",
|
|
80
|
+
"OperationTimeout",
|
|
80
81
|
]
|
|
81
82
|
|
|
82
83
|
__all__ = EXPORTS
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def __getattr__(name: str):
|
|
87
|
+
# `OperationTimeout` subclasses Playwright's TimeoutError, so building it
|
|
88
|
+
# imports `playwright.sync_api`; `errors` defers that to first use, and so
|
|
89
|
+
# does this re-export (see `errors._make_operation_timeout`).
|
|
90
|
+
if name == "OperationTimeout":
|
|
91
|
+
from . import errors
|
|
92
|
+
|
|
93
|
+
return errors.OperationTimeout
|
|
94
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -26,6 +26,7 @@ and a generous client-owned wait.
|
|
|
26
26
|
from __future__ import annotations
|
|
27
27
|
|
|
28
28
|
import ast
|
|
29
|
+
import dataclasses
|
|
29
30
|
import io
|
|
30
31
|
import json
|
|
31
32
|
import os
|
|
@@ -44,6 +45,7 @@ from .._text import spill_text, truncate_hard
|
|
|
44
45
|
from ..errors import (
|
|
45
46
|
BrowserwrightError,
|
|
46
47
|
DeadlineExceeded,
|
|
48
|
+
OperationTimeout,
|
|
47
49
|
TabRebindFailed,
|
|
48
50
|
serialize,
|
|
49
51
|
)
|
|
@@ -325,20 +327,41 @@ class _Worker:
|
|
|
325
327
|
exits the whole executor process, which lets the OS tear down the
|
|
326
328
|
Playwright transport without touching browser tabs."""
|
|
327
329
|
box: "queue.Queue[ExecuteResponse]" = queue.Queue(maxsize=1)
|
|
330
|
+
budget_s = max(req.timeout_ms, 1) / 1000.0
|
|
331
|
+
deadline = time.monotonic() + budget_s
|
|
328
332
|
self._q.put((req, box))
|
|
329
333
|
try:
|
|
330
|
-
|
|
334
|
+
response = box.get(timeout=budget_s)
|
|
331
335
|
except queue.Empty:
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
336
|
+
return self._deadline_exceeded(req)
|
|
337
|
+
# ADR-0014, the 7-vs-8 race: a call that FAILED once its deadline had
|
|
338
|
+
# run out failed because of the deadline. Classify by the clock, not by
|
|
339
|
+
# which thread happened to win the hand-off: a Playwright timeout that
|
|
340
|
+
# fires at the deadline (its `timeout=` was >= what was left, so the
|
|
341
|
+
# deadline was the binding cap) and a relay command cut short by the
|
|
342
|
+
# propagated deadline (#120; it lands `INNER_GRACE_S` after it) can
|
|
343
|
+
# reach this box at or after the deadline. They are the call
|
|
344
|
+
# deadline's, never an `OperationTimeout`. A call that finished is
|
|
345
|
+
# left alone: its work is done, there is nothing to blame.
|
|
346
|
+
if response.error is not None and time.monotonic() >= deadline:
|
|
347
|
+
late = self._deadline_exceeded(req)
|
|
348
|
+
return dataclasses.replace(
|
|
349
|
+
response, error=late.error, exit_code=late.exit_code,
|
|
350
|
+
terminal_reason=late.terminal_reason)
|
|
351
|
+
return response
|
|
352
|
+
|
|
353
|
+
@staticmethod
|
|
354
|
+
def _deadline_exceeded(req: ExecuteRequest) -> ExecuteResponse:
|
|
355
|
+
"""The one place the internal terminal reason becomes the
|
|
356
|
+
caller-facing error (ADR-0014): `terminal_reason` stays the
|
|
357
|
+
daemon/client's signal to reap this exact process, while the agent
|
|
358
|
+
reads `DeadlineExceeded` (exit 7) and its `--timeout` fix."""
|
|
359
|
+
exc = DeadlineExceeded(timeout=req.timeout_ms / 1000.0)
|
|
360
|
+
return ExecuteResponse(
|
|
361
|
+
error=serialize(exc),
|
|
362
|
+
exit_code=exc.exit_code,
|
|
363
|
+
terminal_reason=TERMINAL_DEADLINE_EXCEEDED,
|
|
364
|
+
)
|
|
342
365
|
|
|
343
366
|
def shutdown(self) -> None:
|
|
344
367
|
self._q.put(None)
|
|
@@ -908,8 +931,13 @@ class _Worker:
|
|
|
908
931
|
if _is_target_closed_family(e):
|
|
909
932
|
return self._target_closed_response(
|
|
910
933
|
buf, serialize(e), e.exit_code)
|
|
934
|
+
error = serialize(e)
|
|
935
|
+
if isinstance(e, OperationTimeout):
|
|
936
|
+
# Smart goto's timeout: keep the traceback, which
|
|
937
|
+
# says WHICH call ran out.
|
|
938
|
+
error["traceback"] = traceback.format_exc()
|
|
911
939
|
return self._finish(
|
|
912
|
-
buf, error=
|
|
940
|
+
buf, error=error, exit_code=e.exit_code)
|
|
913
941
|
except SystemExit as e:
|
|
914
942
|
code = int(e.code) if isinstance(e.code, int) else 0
|
|
915
943
|
return self._finish(buf, exit_code=code)
|
|
@@ -917,8 +945,24 @@ class _Worker:
|
|
|
917
945
|
# Restore traceback fidelity: the in-process path writes
|
|
918
946
|
# `traceback.format_exc()` to stderr; a shipped heredoc must
|
|
919
947
|
# show the SAME traceback. We carry it on the serialized error.
|
|
920
|
-
from ..errors import
|
|
948
|
+
from ..errors import (
|
|
949
|
+
operation_timeout_from,
|
|
950
|
+
playwright_error_fix,
|
|
951
|
+
)
|
|
921
952
|
|
|
953
|
+
op = operation_timeout_from(e)
|
|
954
|
+
if op is not e:
|
|
955
|
+
# ADR-0014: inside the code a Playwright call raises
|
|
956
|
+
# Playwright's own TimeoutError (we never patch it);
|
|
957
|
+
# escaping the code, it is REPORTED as an operation
|
|
958
|
+
# timeout — exit 8, executor kept. The traceback (the
|
|
959
|
+
# original frames, ending in the reported type) says
|
|
960
|
+
# which call ran out.
|
|
961
|
+
error = serialize(op)
|
|
962
|
+
error["traceback"] = "".join(
|
|
963
|
+
traceback.format_exception(op))
|
|
964
|
+
return self._finish(
|
|
965
|
+
buf, error=error, exit_code=op.exit_code)
|
|
922
966
|
error = {
|
|
923
967
|
"type": type(e).__name__,
|
|
924
968
|
"msg": str(e),
|
|
@@ -34,14 +34,16 @@ def _rpc_error_fix(method: str, err: object) -> str:
|
|
|
34
34
|
return ModeBClient.explain_rpc_error(method, err)
|
|
35
35
|
if (isinstance(err, dict) and method == "Target.attachToTarget"
|
|
36
36
|
and "already attached" in str(err.get("message", "")).lower()):
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
37
|
+
# Issues #40/#131: another client is this target's attacher.
|
|
38
|
+
# `recover` releases an attacher outside the session's executor
|
|
39
|
+
# process (a stray script, an executor the daemon no longer tracks);
|
|
40
|
+
# when the executor process itself is the attacher, only reaping it
|
|
41
|
+
# frees the tab. The generic -32601 hint does not apply.
|
|
41
42
|
return (
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
43
|
+
"another client is attached to this tab: run `browserwright "
|
|
44
|
+
"recover --session <session-id>`, which releases an attacher "
|
|
45
|
+
"outside the session's executor; if the same error survives a "
|
|
46
|
+
"healthy recover, run `browserwright session reset <session-id>`"
|
|
45
47
|
)
|
|
46
48
|
return ""
|
|
47
49
|
|
|
@@ -31,7 +31,9 @@ Usage:
|
|
|
31
31
|
|
|
32
32
|
--timeout SECONDS the call deadline (default 90). When it runs out the
|
|
33
33
|
code is stopped, its executor is recycled, and the
|
|
34
|
-
command exits 7 (DeadlineExceeded).
|
|
34
|
+
command exits 7 (DeadlineExceeded). One Playwright
|
|
35
|
+
call running out of its own timeout= exits 8
|
|
36
|
+
(OperationTimeout) when the code does not catch it.
|
|
35
37
|
|
|
36
38
|
browserwright session new --backend=<extension|cdp> --name=SESSION_LABEL [--reuse] [--create | --attach=PORT]
|
|
37
39
|
browserwright recover --session=<id> (the one recovery verb: exit 0 healthy, 4 needs-human)
|
{browserwright-0.22.0 → browserwright-0.23.1}/src/browserwright/daemon/server/call_deadline.py
RENAMED
|
@@ -68,7 +68,7 @@ def remaining_s(session_id: str | None) -> float | None:
|
|
|
68
68
|
#: fail-stopped and the caller gets `DeadlineExceeded` (exit 7). An inner wait
|
|
69
69
|
#: that ended *at* the deadline would race that — and the extension, which by
|
|
70
70
|
#: construction settles before the relay, would win it, surfacing the expiry
|
|
71
|
-
#: as
|
|
71
|
+
#: as an operation timeout inside the agent's code (`OperationTimeout`, exit 8)
|
|
72
72
|
#: instead. So the inner waits are derived from the deadline but end this much
|
|
73
73
|
#: after it: the executor always fires first, and the inner bounds stay what
|
|
74
74
|
#: they are for — a net for a wedged extension or Chrome. The relay's margin
|
|
@@ -496,6 +496,10 @@ class _ClientHandler:
|
|
|
496
496
|
query = _parse_query(conn.request.path or "/")
|
|
497
497
|
label = query.get("client", "anonymous")
|
|
498
498
|
session_id = query.get("session") or None
|
|
499
|
+
try:
|
|
500
|
+
client_pid: int | None = int(query["pid"])
|
|
501
|
+
except (KeyError, ValueError):
|
|
502
|
+
client_pid = None
|
|
499
503
|
|
|
500
504
|
lease_token: object | None = None
|
|
501
505
|
handler_task = asyncio.current_task()
|
|
@@ -541,7 +545,7 @@ class _ClientHandler:
|
|
|
541
545
|
session_name = rec.get("name")
|
|
542
546
|
client = state.allocate_client(
|
|
543
547
|
label, client_id=next(self.daemon._next_client_id),
|
|
544
|
-
session_id=session_id, session_name=session_name)
|
|
548
|
+
session_id=session_id, session_name=session_name, pid=client_pid)
|
|
545
549
|
client.connection_token = lease_token
|
|
546
550
|
|
|
547
551
|
async def send_to_client(text: str) -> None:
|
|
@@ -110,6 +110,11 @@ class ClientState:
|
|
|
110
110
|
# the bare REPL client / single-context unit tests.
|
|
111
111
|
session_id: str | None = None
|
|
112
112
|
session_name: str | None = None
|
|
113
|
+
# The connecting process, from the ws ``?pid=<pid>`` query. Lets
|
|
114
|
+
# `recover` tell the session's executor process apart from any other
|
|
115
|
+
# attacher of the session's tab (issue #131). None when the client did
|
|
116
|
+
# not say (older clients, unit tests).
|
|
117
|
+
pid: int | None = None
|
|
113
118
|
# Opaque daemon lease used to revoke this exact control transport when its
|
|
114
119
|
# Browserwright session ends. None for sessionless/unit-test clients.
|
|
115
120
|
connection_token: object | None = None
|
|
@@ -170,14 +175,16 @@ class DaemonState:
|
|
|
170
175
|
|
|
171
176
|
def allocate_client(self, label: str, *, client_id: int | None = None,
|
|
172
177
|
session_id: str | None = None,
|
|
173
|
-
session_name: str | None = None
|
|
178
|
+
session_name: str | None = None,
|
|
179
|
+
pid: int | None = None) -> ClientState:
|
|
174
180
|
# Phase 2: the Daemon passes a globally-unique client_id (unique across
|
|
175
181
|
# all UpstreamContexts) so daemon logs never show two clients sharing a
|
|
176
182
|
# number. When omitted (single-context callers / tests), fall back to
|
|
177
183
|
# this state's own monotonic counter.
|
|
178
184
|
cid = client_id if client_id is not None else next(self._next_client_id)
|
|
179
185
|
c = ClientState(client_id=cid, label=label or "anonymous",
|
|
180
|
-
session_id=session_id, session_name=session_name
|
|
186
|
+
session_id=session_id, session_name=session_name,
|
|
187
|
+
pid=pid)
|
|
181
188
|
self.clients[cid] = c
|
|
182
189
|
return c
|
|
183
190
|
|
|
@@ -271,6 +278,35 @@ class DaemonState:
|
|
|
271
278
|
upstream_session_id=upstream_session_id,
|
|
272
279
|
)
|
|
273
280
|
|
|
281
|
+
def release_foreign_attachers(
|
|
282
|
+
self, session_id: str, executor_pid: int | None,
|
|
283
|
+
) -> list[tuple[str, ClientState]]:
|
|
284
|
+
"""Drop attacher ownership on `session_id`'s targets unless it is held
|
|
285
|
+
from the session's executor process (`executor_pid`; None = no live
|
|
286
|
+
executor, so nothing is kept). Returns ``(target_id, former owner)``
|
|
287
|
+
per release.
|
|
288
|
+
|
|
289
|
+
The resident executor owning its own tab is by design. Any other owner
|
|
290
|
+
on the session (a stray script, an executor this daemon no longer
|
|
291
|
+
tracks, a client too old to report its pid) refuses every fresh
|
|
292
|
+
`Target.attachToTarget` with "already attached by another client"
|
|
293
|
+
(issue #131). Bookkeeping only, like `release_client`: the owner's
|
|
294
|
+
bindings on the target go and its connection stays open, but no
|
|
295
|
+
upstream detach is sent and the owner is not told."""
|
|
296
|
+
released: list[tuple[str, ClientState]] = []
|
|
297
|
+
for target_id, own in list(self.attachers.items()):
|
|
298
|
+
owner = self.clients.get(own.primary_client_id)
|
|
299
|
+
if owner is None or owner.session_id != session_id:
|
|
300
|
+
continue
|
|
301
|
+
if executor_pid is not None and owner.pid == executor_pid:
|
|
302
|
+
continue
|
|
303
|
+
for local_sid, binding in list(owner.sessions.items()):
|
|
304
|
+
if binding.target_id == target_id:
|
|
305
|
+
self.unbind_session_by_local(owner.client_id, local_sid)
|
|
306
|
+
self.attachers.pop(target_id, None)
|
|
307
|
+
released.append((target_id, owner))
|
|
308
|
+
return released
|
|
309
|
+
|
|
274
310
|
# ---- pending request map ---------------------------------------------
|
|
275
311
|
|
|
276
312
|
def allocate_upstream_id(self) -> int:
|
|
@@ -635,7 +635,8 @@ class SessionVerbsMixin:
|
|
|
635
635
|
return
|
|
636
636
|
machine = daemon.recovery
|
|
637
637
|
registry = daemon.executors
|
|
638
|
-
|
|
638
|
+
ctx = daemon.context_for_required(session)
|
|
639
|
+
upstream = ctx.upstream
|
|
639
640
|
steps: list[dict] = []
|
|
640
641
|
|
|
641
642
|
def note(event: str, **kw) -> None:
|
|
@@ -659,6 +660,22 @@ class SessionVerbsMixin:
|
|
|
659
660
|
note(RECOVERY_FAILED, reason=reason)
|
|
660
661
|
await finish(NEEDS_HUMAN, reason)
|
|
661
662
|
|
|
663
|
+
# rung 0 — the session's tabs are attachable. The state machine cannot
|
|
664
|
+
# see an attacher that is not the session's executor (issue #131):
|
|
665
|
+
# every fresh attach is refused while it calls the session healthy,
|
|
666
|
+
# and `session reset` only reaps the executor. Release such attachers
|
|
667
|
+
# before trusting `healthy`.
|
|
668
|
+
handle = registry.get(session)
|
|
669
|
+
executor_pid = (handle.current_pid()
|
|
670
|
+
if handle is not None and handle.is_alive() else None)
|
|
671
|
+
for target_id, owner in ctx.state.release_foreign_attachers(
|
|
672
|
+
session, executor_pid):
|
|
673
|
+
detail = (f"released {target_id}: its attacher was client "
|
|
674
|
+
f"{owner.client_id} ({owner.label}, pid "
|
|
675
|
+
f"{owner.pid or 'unknown'}), not this session's executor")
|
|
676
|
+
logger.warning("recover: session %s: %s", session, detail)
|
|
677
|
+
steps.append({"rung": "attach", "ok": True, "detail": detail})
|
|
678
|
+
|
|
662
679
|
# State-directed ladder: a healthy session is already converged. In
|
|
663
680
|
# particular, do not force a tab re-attach merely because a user asked
|
|
664
681
|
# for a diagnosis.
|
|
@@ -915,3 +932,4 @@ VERBS: dict[str, Handler] = {
|
|
|
915
932
|
"BrowserwrightDaemon.userscript.logs": partial(
|
|
916
933
|
SessionVerbsMixin._handle_userscript, verb="logs"),
|
|
917
934
|
}
|
|
935
|
+
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"""Skill exception hierarchy (spec §A.4)."""
|
|
2
2
|
|
|
3
|
+
import re
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
class BrowserwrightError(Exception):
|
|
5
7
|
"""Root of every exception Skill itself raises.
|
|
@@ -160,6 +162,101 @@ class DeadlineExceeded(BrowserwrightError):
|
|
|
160
162
|
)
|
|
161
163
|
|
|
162
164
|
|
|
165
|
+
#: Playwright's own default for an action (``click``, ``fill``, ``wait_for``…)
|
|
166
|
+
#: when the agent sets no ``timeout=``. Restated here only for messages; the
|
|
167
|
+
#: value Playwright uses is its own.
|
|
168
|
+
PLAYWRIGHT_ACTION_TIMEOUT_S = 30
|
|
169
|
+
#: browserwright's smart ``page.goto`` default (``repl/_smart_goto.py``).
|
|
170
|
+
SMART_GOTO_TIMEOUT_S = 60
|
|
171
|
+
|
|
172
|
+
_TIMEOUT_MS_RE = re.compile(r"Timeout (\d+(?:\.\d+)?)ms exceeded")
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _make_operation_timeout() -> type:
|
|
176
|
+
# Playwright's public `TimeoutError` lives in `playwright.sync_api`, whose
|
|
177
|
+
# import pulls in the whole driver stack (~80ms). `errors` is loaded by
|
|
178
|
+
# every CLI invocation, most of which never touch Playwright, so the class
|
|
179
|
+
# is built on first use (module `__getattr__` below), not at import.
|
|
180
|
+
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
|
|
181
|
+
|
|
182
|
+
class OperationTimeout(BrowserwrightError, PlaywrightTimeoutError):
|
|
183
|
+
"""One Playwright call ran out of its own timeout (ADR-0014).
|
|
184
|
+
|
|
185
|
+
The operation timeout is the agent's ``timeout=`` /
|
|
186
|
+
``set_default_timeout()``, or Playwright's default (30s for an action,
|
|
187
|
+
60s for browserwright's smart ``goto``), capped by what is left of the
|
|
188
|
+
call deadline. When the call deadline is the smaller of the two,
|
|
189
|
+
running out is ``DeadlineExceeded`` (exit 7), never this.
|
|
190
|
+
|
|
191
|
+
Inside the agent's code a Playwright call raises Playwright's own
|
|
192
|
+
``TimeoutError``, untouched — browserwright does not patch Playwright.
|
|
193
|
+
This is the type the call REPORTS when such a timeout escapes the
|
|
194
|
+
code: the executor (and the in-process heredoc) map an uncaught
|
|
195
|
+
Playwright ``TimeoutError`` to it at their top-level handler, exit 8.
|
|
196
|
+
The executor survives it, with its ``state``.
|
|
197
|
+
|
|
198
|
+
The one place it is raised directly is browserwright's own smart
|
|
199
|
+
``page.goto`` (``repl/_smart_goto.py``), whose timeout bucket is this
|
|
200
|
+
error. It subclasses Playwright's ``TimeoutError`` so that
|
|
201
|
+
``except TimeoutError`` catches it exactly like any other Playwright
|
|
202
|
+
timeout.
|
|
203
|
+
"""
|
|
204
|
+
|
|
205
|
+
exit_code = 8
|
|
206
|
+
default_fix = (
|
|
207
|
+
"a single Playwright call ran out of its own timeout; the executor "
|
|
208
|
+
"and `state` survived. Call snapshot() to check the page and that "
|
|
209
|
+
"the target exists (a wrong selector waits the full timeout), then "
|
|
210
|
+
"retry with the current ref; if the page is just slow, raise that "
|
|
211
|
+
"call's timeout= (default 30s for actions, 60s for page.goto; it "
|
|
212
|
+
"can never outlast the call deadline `--timeout`)"
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
def __init__(self, message: str = "", *, scope: str = "operation",
|
|
216
|
+
url: str = "", detail: str = "",
|
|
217
|
+
timeout: float | None = None, fix: str = ""):
|
|
218
|
+
self.scope, self.detail = scope, detail
|
|
219
|
+
self.url = url or None
|
|
220
|
+
if timeout is None:
|
|
221
|
+
m = _TIMEOUT_MS_RE.search(message)
|
|
222
|
+
timeout = float(m.group(1)) / 1000.0 if m else None
|
|
223
|
+
self.timeout = timeout
|
|
224
|
+
super().__init__(message or "operation timed out", fix=fix)
|
|
225
|
+
|
|
226
|
+
OperationTimeout.__module__ = __name__
|
|
227
|
+
OperationTimeout.__qualname__ = "OperationTimeout"
|
|
228
|
+
return OperationTimeout
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def __getattr__(name: str):
|
|
232
|
+
"""``OperationTimeout`` and ``PlaywrightTimeoutError``, resolved lazily
|
|
233
|
+
(see ``_make_operation_timeout``)."""
|
|
234
|
+
if name == "OperationTimeout":
|
|
235
|
+
cls = _make_operation_timeout()
|
|
236
|
+
globals()["OperationTimeout"] = cls
|
|
237
|
+
return cls
|
|
238
|
+
if name == "PlaywrightTimeoutError":
|
|
239
|
+
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
|
|
240
|
+
|
|
241
|
+
globals()["PlaywrightTimeoutError"] = PlaywrightTimeoutError
|
|
242
|
+
return PlaywrightTimeoutError
|
|
243
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def operation_timeout_from(exc: BaseException):
|
|
247
|
+
"""The ``OperationTimeout`` an uncaught Playwright ``TimeoutError`` is
|
|
248
|
+
reported as (exit 8). Anything else — including an ``OperationTimeout``
|
|
249
|
+
already — is returned unchanged."""
|
|
250
|
+
g = globals()
|
|
251
|
+
cls = g.get("OperationTimeout") or __getattr__("OperationTimeout")
|
|
252
|
+
timeout_cls = (g.get("PlaywrightTimeoutError")
|
|
253
|
+
or __getattr__("PlaywrightTimeoutError"))
|
|
254
|
+
if isinstance(exc, cls) or not isinstance(exc, timeout_cls):
|
|
255
|
+
return exc
|
|
256
|
+
message = getattr(exc, "message", None) or str(exc)
|
|
257
|
+
return cls(message).with_traceback(exc.__traceback__)
|
|
258
|
+
|
|
259
|
+
|
|
163
260
|
class ElementNotFound(BrowserwrightError):
|
|
164
261
|
exit_code = 3
|
|
165
262
|
default_fix = (
|
|
@@ -19,7 +19,9 @@ Discovery:
|
|
|
19
19
|
/ ``$BW_DAEMON_URL`` / the toml ``daemon_url`` key / the running daemon's
|
|
20
20
|
state file / ``http://127.0.0.1:19990``. No subprocess, no socket path.
|
|
21
21
|
- On connect, the client opens
|
|
22
|
-
``ws://<host>:<port>/control?client=skill-repl&session=<id>``.
|
|
22
|
+
``ws://<host>:<port>/control?client=skill-repl&session=<id>&pid=<pid>``.
|
|
23
|
+
The pid lets the daemon tell the session's executor process apart from
|
|
24
|
+
any other connection on the session (issue #131).
|
|
23
25
|
|
|
24
26
|
This client never starts, stops or replaces a daemon — that is
|
|
25
27
|
:mod:`browserwright.daemon_lifecycle`, and only ``session new`` / ``recover``
|
|
@@ -30,6 +32,7 @@ call it.
|
|
|
30
32
|
"""
|
|
31
33
|
from __future__ import annotations
|
|
32
34
|
|
|
35
|
+
import os
|
|
33
36
|
from typing import Any, Optional
|
|
34
37
|
|
|
35
38
|
from .daemon_url import DaemonEndpoint, daemon_endpoint
|
|
@@ -73,7 +76,8 @@ class ModeBClient:
|
|
|
73
76
|
# Session-bound clients carry ``?session=<id>`` — the daemon dispatcher
|
|
74
77
|
# routes on this (not on the client label). Without it a cdp session
|
|
75
78
|
# resolves to None → the shared (extension) context.
|
|
76
|
-
url = ep.ws("/control", client=client_label, session=self._session_id
|
|
79
|
+
url = ep.ws("/control", client=client_label, session=self._session_id,
|
|
80
|
+
pid=str(os.getpid()))
|
|
77
81
|
self._cached_ws = url
|
|
78
82
|
self._endpoint = ep.url
|
|
79
83
|
self._transport = "tcp"
|