browserwright 0.22.0__tar.gz → 0.23.0__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.
Files changed (116) hide show
  1. {browserwright-0.22.0/src/browserwright.egg-info → browserwright-0.23.0}/PKG-INFO +1 -1
  2. {browserwright-0.22.0 → browserwright-0.23.0}/pyproject.toml +1 -1
  3. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/__init__.py +12 -0
  4. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/_executor/process.py +57 -13
  5. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/cli.py +3 -1
  6. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/call_deadline.py +1 -1
  7. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/errors.py +97 -0
  8. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/repl/_smart_goto.py +121 -16
  9. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/repl/inline.py +13 -2
  10. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/skill_runtime.md +41 -20
  11. {browserwright-0.22.0 → browserwright-0.23.0/src/browserwright.egg-info}/PKG-INFO +1 -1
  12. {browserwright-0.22.0 → browserwright-0.23.0}/LICENSE +0 -0
  13. {browserwright-0.22.0 → browserwright-0.23.0}/README.md +0 -0
  14. {browserwright-0.22.0 → browserwright-0.23.0}/setup.cfg +0 -0
  15. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/__main__.py +0 -0
  16. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/_executor/__init__.py +0 -0
  17. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/_executor/__main__.py +0 -0
  18. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/_executor/client.py +0 -0
  19. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/_executor/protocol.py +0 -0
  20. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/_text.py +0 -0
  21. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/cdp.py +0 -0
  22. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/__init__.py +0 -0
  23. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/_ipc.py +0 -0
  24. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/_net.py +0 -0
  25. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/_rpc.py +0 -0
  26. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/_stale.py +0 -0
  27. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/backends/__init__.py +0 -0
  28. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/backends/base.py +0 -0
  29. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/backends/cdp.py +0 -0
  30. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/backends/extension.py +0 -0
  31. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/cli.py +0 -0
  32. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/config.py +0 -0
  33. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/doctor.py +0 -0
  34. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/errors.py +0 -0
  35. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/launch_chrome.py +0 -0
  36. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/launchagent.py +0 -0
  37. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/observability.py +0 -0
  38. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/platforms.py +0 -0
  39. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/probe.py +0 -0
  40. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/relay_status.py +0 -0
  41. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/resolver.py +0 -0
  42. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/restart_guard.py +0 -0
  43. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/__init__.py +0 -0
  44. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/daemon.py +0 -0
  45. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/exec_relay.py +0 -0
  46. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/executor_registry.py +0 -0
  47. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/extension_upstream.py +0 -0
  48. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/facade.py +0 -0
  49. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/facade_extension.py +0 -0
  50. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/listener.py +0 -0
  51. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/proxy.py +0 -0
  52. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/relay.py +0 -0
  53. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/session_state.py +0 -0
  54. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/state.py +0 -0
  55. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/status.py +0 -0
  56. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/upstream.py +0 -0
  57. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/upstream_context.py +0 -0
  58. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/server/verbs.py +0 -0
  59. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/supervise.py +0 -0
  60. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon/userscripts.py +0 -0
  61. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon_lifecycle.py +0 -0
  62. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/daemon_url.py +0 -0
  63. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/discovery.py +0 -0
  64. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/health.py +0 -0
  65. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/install.py +0 -0
  66. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/memory/__init__.py +0 -0
  67. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/memory/_lock.py +0 -0
  68. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/memory/_md.py +0 -0
  69. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/memory/_yaml.py +0 -0
  70. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/memory/global_mem.py +0 -0
  71. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/memory/site_mem.py +0 -0
  72. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/mode_b_client.py +0 -0
  73. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/output_schema.py +0 -0
  74. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/primitives/__init__.py +0 -0
  75. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/primitives/discovery_api.py +0 -0
  76. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/primitives/http.py +0 -0
  77. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/primitives/site.py +0 -0
  78. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/repl/__init__.py +0 -0
  79. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/repl/_md_convert.py +0 -0
  80. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/repl/_md_normalize.py +0 -0
  81. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/repl/_namespace.py +0 -0
  82. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/repl/markdown.py +0 -0
  83. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/repl/playwright_handle.py +0 -0
  84. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/repl/search.py +0 -0
  85. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/repl/snapshot.py +0 -0
  86. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/repl/vendor/README.md +0 -0
  87. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/repl/vendor/readability.js +0 -0
  88. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/session.py +0 -0
  89. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/session_create.py +0 -0
  90. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/session_ctx.py +0 -0
  91. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/session_registry.py +0 -0
  92. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/session_runtime.py +0 -0
  93. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/github.com/SKILL.md +0 -0
  94. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/github.com/memory.md +0 -0
  95. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/github.com/tasks/list_issues.py +0 -0
  96. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/google.com/SKILL.md +0 -0
  97. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/google.com/memory.md +0 -0
  98. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/google.com/tasks/search.py +0 -0
  99. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/producthunt.com/SKILL.md +0 -0
  100. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/producthunt.com/memory.md +0 -0
  101. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/producthunt.com/tasks/today.py +0 -0
  102. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/wikipedia.org/SKILL.md +0 -0
  103. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/wikipedia.org/memory.md +0 -0
  104. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/wikipedia.org/tasks/lookup.py +0 -0
  105. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/ycombinator.com/SKILL.md +0 -0
  106. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/ycombinator.com/memory.md +0 -0
  107. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/site_skills_starter/ycombinator.com/tasks/front_page.py +0 -0
  108. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/skill_doc.py +0 -0
  109. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/tab_surface.py +0 -0
  110. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/task_runner.py +0 -0
  111. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright/version.py +0 -0
  112. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright.egg-info/SOURCES.txt +0 -0
  113. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright.egg-info/dependency_links.txt +0 -0
  114. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright.egg-info/entry_points.txt +0 -0
  115. {browserwright-0.22.0 → browserwright-0.23.0}/src/browserwright.egg-info/requires.txt +0 -0
  116. {browserwright-0.22.0 → browserwright-0.23.0}/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.22.0
3
+ Version: 0.23.0
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.22.0"
18
+ version = "0.23.0"
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
- return box.get(timeout=max(req.timeout_ms, 1) / 1000.0)
334
+ response = box.get(timeout=budget_s)
331
335
  except queue.Empty:
332
- # The one place the internal terminal reason becomes the
333
- # caller-facing error (ADR-0014): `terminal_reason` stays the
334
- # daemon/client's signal to reap this exact process, while the
335
- # agent reads `DeadlineExceeded` (exit 7) and its `--timeout` fix.
336
- exc = DeadlineExceeded(timeout=req.timeout_ms / 1000.0)
337
- return ExecuteResponse(
338
- error=serialize(exc),
339
- exit_code=exc.exit_code,
340
- terminal_reason=TERMINAL_DEADLINE_EXCEEDED,
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=serialize(e), exit_code=e.exit_code)
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 playwright_error_fix
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),
@@ -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)
@@ -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 a command timeout inside the agent's code (`PageLoadFailed`, exit 3)
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
@@ -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 = (
@@ -12,7 +12,12 @@ import types
12
12
  from datetime import timedelta
13
13
  from typing import Any
14
14
 
15
- from ..errors import PageLoadFailed
15
+ from ..errors import (
16
+ SMART_GOTO_TIMEOUT_S,
17
+ OperationTimeout,
18
+ PageLoadFailed,
19
+ PlaywrightTimeoutError,
20
+ )
16
21
 
17
22
 
18
23
  _PATCHED = "_bw_smart_goto"
@@ -20,12 +25,19 @@ _ORIG_GOTO = "_bw_orig_goto"
20
25
  _CONTEXT_PATCHED = "_bw_smart_new_page"
21
26
  _ORIG_NEW_PAGE = "_bw_orig_new_page"
22
27
  _STABLE_WINDOW_MS = 1500
23
- _DEFAULT_TIMEOUT_MS = 60_000
28
+ _DEFAULT_TIMEOUT_MS = SMART_GOTO_TIMEOUT_S * 1000
24
29
  _DOMCONTENTLOADED_TIMEOUT_MS = 10_000
30
+ # What the agent set with the public `set_default_timeout()` /
31
+ # `set_default_navigation_timeout()`, recorded on the page / context object by
32
+ # our wrappers (`_track_default_timeouts`). `None` = not set.
33
+ _DEFAULT_TIMEOUT_ATTR = "_bw_default_timeout"
34
+ _DEFAULT_NAV_TIMEOUT_ATTR = "_bw_default_navigation_timeout"
35
+ _TRACKED = "_bw_tracks_default_timeouts"
25
36
 
26
37
 
27
38
  def patch_context_pages(context: Any) -> None:
28
39
  """Patch existing pages and future ``context.new_page()`` results."""
40
+ _track_default_timeouts(context)
29
41
  for page in list(getattr(context, "pages", []) or []):
30
42
  patch_page_goto(page)
31
43
  if getattr(context, _CONTEXT_PATCHED, False):
@@ -52,21 +64,33 @@ def patch_page_goto(page: Any) -> Any:
52
64
  return page
53
65
 
54
66
  orig_goto = page.goto
67
+ _track_default_timeouts(page)
68
+ try:
69
+ _track_default_timeouts(page.context)
70
+ except Exception: # noqa: BLE001 - best effort; the page's own still apply
71
+ pass
55
72
 
56
- def smart_goto(self: Any, url: str, *, timeout: int | float | timedelta | None = _DEFAULT_TIMEOUT_MS,
73
+ def smart_goto(self: Any, url: str, *, timeout: int | float | timedelta | None = None,
57
74
  wait_until: str | None = None, referer: str | None = None) -> Any:
75
+ if timeout is None:
76
+ timeout = _default_navigation_timeout_ms(self)
58
77
  timeout_ms = _normalize_timeout(timeout)
59
78
  network = _NetworkMonitor(self)
60
79
  deadline = _deadline_for(timeout_ms)
80
+ before_url = _url_of(self)
61
81
  try:
62
82
  response = orig_goto(url, timeout=timeout_ms,
63
83
  wait_until="commit", referer=referer)
64
84
  except Exception as exc: # noqa: BLE001 - translate Playwright failures.
65
- if _looks_loaded(self):
85
+ # A timeout on a page still at its pre-goto URL never committed:
86
+ # skip the probe (see `_looks_loaded`).
87
+ if _looks_loaded(
88
+ self,
89
+ before_url if isinstance(exc, PlaywrightTimeoutError) else None):
66
90
  response = None
67
91
  else:
68
92
  network.detach()
69
- raise _page_load_failed(url, "commit", exc) from exc
93
+ raise _navigation_failed(url, "commit", exc) from exc
70
94
 
71
95
  _wait_for_domcontentloaded(self, _remaining_timeout_ms(deadline))
72
96
  try:
@@ -96,6 +120,58 @@ def _normalize_timeout(timeout: int | float | timedelta | None) -> int:
96
120
  return timeout_ms if timeout_ms >= 0 else _DEFAULT_TIMEOUT_MS
97
121
 
98
122
 
123
+ def _track_default_timeouts(obj: Any) -> None:
124
+ """Wrap a page's or context's public ``set_default_timeout()`` /
125
+ ``set_default_navigation_timeout()`` so smart goto knows what the agent set.
126
+
127
+ ADR-0014: an operation timeout is the agent's own value when it set one.
128
+ Smart goto always passes an explicit ``timeout`` to Playwright (its 60s
129
+ default differs from Playwright's 30s), which would otherwise shadow those
130
+ defaults. Playwright keeps them in private state, so — like ``goto`` itself
131
+ — the public setters are wrapped and the values remembered here.
132
+ """
133
+ if obj is None or getattr(obj, _TRACKED, False):
134
+ return
135
+
136
+ def wrap(method_name: str, attr: str) -> None:
137
+ orig = getattr(obj, method_name)
138
+
139
+ def setter(timeout: float | None) -> None:
140
+ orig(timeout)
141
+ setattr(obj, attr, timeout)
142
+
143
+ setattr(obj, method_name, setter)
144
+
145
+ try:
146
+ wrap("set_default_timeout", _DEFAULT_TIMEOUT_ATTR)
147
+ wrap("set_default_navigation_timeout", _DEFAULT_NAV_TIMEOUT_ATTR)
148
+ setattr(obj, _TRACKED, True)
149
+ except Exception: # noqa: BLE001 - best effort; the smart default applies
150
+ return
151
+
152
+
153
+ def _default_navigation_timeout_ms(page: Any) -> float | None:
154
+ """The navigation timeout the agent set, or ``None`` (the smart default,
155
+ 60s, then applies).
156
+
157
+ Same precedence as Playwright's own: the page's navigation default, then
158
+ the page's default, then the context's navigation default, then the
159
+ context's default — a page setting always overrides the context's.
160
+ """
161
+ try:
162
+ context = page.context
163
+ except Exception: # noqa: BLE001
164
+ context = None
165
+ for obj in (page, context):
166
+ if obj is None:
167
+ continue
168
+ for attr in (_DEFAULT_NAV_TIMEOUT_ATTR, _DEFAULT_TIMEOUT_ATTR):
169
+ value = getattr(obj, attr, None)
170
+ if isinstance(value, (int, float)) and not isinstance(value, bool):
171
+ return value
172
+ return None
173
+
174
+
99
175
  def _deadline_for(timeout_ms: int) -> float | None:
100
176
  if timeout_ms == 0:
101
177
  return None
@@ -118,17 +194,33 @@ def _wait_for_domcontentloaded(page: Any, remaining_timeout_ms: int) -> None:
118
194
  pass
119
195
 
120
196
 
121
- def _looks_loaded(page: Any) -> bool:
197
+ def _url_of(page: Any) -> str | None:
198
+ try:
199
+ return page.url
200
+ except Exception: # noqa: BLE001
201
+ return None
202
+
203
+
204
+ def _looks_loaded(page: Any, before_url: str | None = None) -> bool:
122
205
  """Detect successful navigations masked by commit watcher races.
123
206
 
124
207
  Some redirects/client transitions can leave Playwright's commit wait in an
125
208
  error state even after the document is usable. Treat any probe failure as
126
- not loaded so true failures still follow the existing PageLoadFailed path.
209
+ not loaded so true failures still follow the existing failure path.
210
+
211
+ ``before_url`` is passed for a timeout only. A page that timed out still on
212
+ the URL it had before the ``goto`` never committed the navigation, so there
213
+ is nothing to detect — and probing it is not free: the navigation is still
214
+ pending, and the ``evaluate`` below waits for it (on the extension backend,
215
+ until the slow page finally commits). That turned a 2s ``goto`` timeout
216
+ into a 12s one (#121).
127
217
  """
128
218
  try:
129
219
  url = page.url
130
220
  if not url or url == "about:blank":
131
221
  return False
222
+ if before_url is not None and url == before_url:
223
+ return False
132
224
  ready_state = page.evaluate("() => document.readyState")
133
225
  return ready_state != "loading"
134
226
  except Exception:
@@ -179,6 +271,11 @@ def _bounded_timeout(total_ms: int, cap_ms: int) -> int:
179
271
  # derived from the caller's remaining call deadline. Its breach is therefore
180
272
  # the caller's own deadline running out, and lands in the ordinary `timeout`
181
273
  # bucket — see `_TIMEOUT_NEEDLES`.
274
+ #
275
+ # The `timeout` bucket is not a PageLoadFailed at all: it is raised as
276
+ # `OperationTimeout` (ADR-0014, exit 8), the same error every other Playwright
277
+ # call raises when it runs out of its own `timeout=`. Its fix keeps #123's rule:
278
+ # never suggest a fresh tab, check whether the navigation landed first.
182
279
  _REASON_TIMEOUT = "timeout"
183
280
  _REASON_NETWORK = "network"
184
281
  _REASON_NAV_INTERRUPTED = "navigation-interrupted"
@@ -270,16 +367,20 @@ def _classify(exc: BaseException) -> tuple[str, str]:
270
367
  lower = str(exc).lower()
271
368
  timeout = (
272
369
  _REASON_TIMEOUT,
273
- "site did not respond at commit in time; the navigation may still "
274
- "land, so check page.url / snapshot() before retrying page.goto(url), "
275
- "and verify the site with http_get(url)",
370
+ "the navigation ran out of its timeout before the page committed; it "
371
+ "may still land, so check page.url / snapshot() before retrying "
372
+ "page.goto(url) (do not open a new tab). If the site is just slow, "
373
+ "raise this goto's timeout= (default 60s; it can never outlast the "
374
+ "call deadline `--timeout`), and verify the site with http_get(url)",
276
375
  )
277
376
  if any(needle in lower for needle in _TIMEOUT_NEEDLES):
278
377
  return timeout
279
378
  for reason, fix, needles in _CLASSIFIERS:
280
379
  if any(needle in lower for needle in needles):
281
380
  return reason, fix
282
- if "timeout" in lower or "timed out" in lower or type(exc).__name__ == "TimeoutError":
381
+ if ("timeout" in lower or "timed out" in lower
382
+ or isinstance(exc, PlaywrightTimeoutError)
383
+ or type(exc).__name__ == "TimeoutError"):
283
384
  return timeout
284
385
  return (
285
386
  _REASON_UNKNOWN,
@@ -289,13 +390,17 @@ def _classify(exc: BaseException) -> tuple[str, str]:
289
390
  )
290
391
 
291
392
 
292
- def _page_load_failed(url: str, phase: str, exc: BaseException) -> PageLoadFailed:
393
+ def _navigation_failed(
394
+ url: str, phase: str, exc: BaseException,
395
+ ) -> PageLoadFailed | OperationTimeout:
293
396
  reason, fix = _classify(exc)
294
- # `phase` ("commit") is only meaningful for the timeout bucket, where it
295
- # says how far the navigation got. Every other bucket names its own cause.
397
+ detail = _detail_for(exc)
296
398
  if reason == _REASON_TIMEOUT:
297
- reason = phase or _REASON_TIMEOUT
298
- return PageLoadFailed(url, reason, fix=fix, detail=_detail_for(exc))
399
+ # `phase` ("commit") says how far the navigation got.
400
+ return OperationTimeout(
401
+ f"page.goto timed out at {phase or 'commit'}: {url}: {detail}",
402
+ url=url, detail=detail, fix=fix)
403
+ return PageLoadFailed(url, reason, fix=fix, detail=detail)
299
404
 
300
405
 
301
406
  class _NetworkMonitor:
@@ -127,13 +127,24 @@ def run_code(code: str, *, session_id: str,
127
127
  except SystemExit as e:
128
128
  sys.stdout.write(buf.getvalue())
129
129
  return int(e.code) if isinstance(e.code, int) else 0
130
- except Exception: # noqa: BLE001
130
+ except Exception as e: # noqa: BLE001
131
131
  sys.stdout.write(buf.getvalue())
132
132
  sys.stderr.write(traceback.format_exc())
133
+ # ADR-0014: an uncaught Playwright TimeoutError is reported as an
134
+ # operation timeout (exit 8), the same as on the executor path. Only
135
+ # look when Playwright is loaded: a Playwright error implies it is,
136
+ # and checking must not import its driver stack for every failure.
137
+ if "playwright.sync_api" in sys.modules:
138
+ from ..errors import operation_timeout_from
139
+ op = operation_timeout_from(e)
140
+ if op is not e:
141
+ sys.stderr.write(json.dumps(serialize(op)) + "\n")
142
+ sys.stderr.write(f"[fix] {op.fix}\n")
143
+ return op.exit_code
133
144
  # C: surface the recovery hint for raw Playwright failures (target
134
145
  # closed etc.) instead of dropping it with the traceback.
135
146
  from ..errors import playwright_error_fix
136
- fix = playwright_error_fix(sys.exc_info()[1])
147
+ fix = playwright_error_fix(e)
137
148
  if fix:
138
149
  sys.stderr.write(f"[fix] {fix}\n")
139
150
  return 3
@@ -137,28 +137,45 @@ call cannot see the values unless it selects them again. Values travel directly
137
137
  over the local executor socket and are not written to persistent `state`,
138
138
  discovery files, or Browserwright logs.
139
139
 
140
- ## Call deadline: `--timeout`
140
+ ## Timeouts: the call deadline and the operation timeout
141
141
 
142
- Every `-e` / `-f` / `--code-stdin` call has one **call deadline** for the whole
143
- call: `--timeout <seconds>`, default **90**. It is a ceiling, not a default for
144
- the Playwright calls inside your code — `click`, `wait_for` and friends keep
145
- Playwright's own `timeout=` (30s unless you pass one), and `page.goto` keeps
146
- its 60s.
142
+ You own exactly two timeouts.
143
+
144
+ **Call deadline: `--timeout`.** Every `-e` / `-f` / `--code-stdin` call has one
145
+ deadline for the whole call: `--timeout <seconds>`, default **90**.
147
146
 
148
147
  ```bash
149
148
  browserwright -s "$sid" --timeout 300 -f long_crawl.py # a known-slow job
150
149
  ```
151
150
 
152
- When the deadline runs out the call is **fail-stopped**: the code is cut off
153
- wherever it was, its executor is terminated, and the command exits with code
154
- **7** and a `DeadlineExceeded` error (`"scope": "call"`). It cannot be caught
155
- from inside the code. Browser tabs survive; `state` does not, and `finally`
156
- blocks are not guaranteed. The next call starts a fresh executor on the same
157
- tab, so it works normally.
151
+ **Operation timeout: `timeout=`.** Each Playwright call inside your code
152
+ (`click`, `fill`, `wait_for`, `goto`, …) has its own timeout:
153
+
154
+ ```
155
+ operation timeout = min(your timeout= / page.set_default_timeout(), or Playwright's default,
156
+ what is left of the call deadline)
157
+ ```
158
158
 
159
- What to do with exit 7: raise `--timeout` if the work is legitimately slow, or
160
- split it into several smaller calls (keep progress with `state` or
161
- `remember()`). Do not re-run the same call unchanged.
159
+ Playwright's default is **30s** for an action and **60s** for `page.goto`. The
160
+ call deadline is a ceiling, never the default: an unset `timeout=` is still 30s
161
+ under `--timeout 300`, so a wrong selector fails in 30s, not in 5 minutes. A
162
+ `timeout=` larger than what is left of the call deadline does not extend it.
163
+
164
+ The two run out differently, and the exit code tells you which one did:
165
+
166
+ | | exit **7** — `DeadlineExceeded` | exit **8** — `OperationTimeout` |
167
+ |---|---|---|
168
+ | what ran out | the whole call (`--timeout`), `"scope": "call"` | one Playwright call (`timeout=`), `"scope": "operation"` |
169
+ | inside your code | cannot be caught: the code is cut off wherever it was | Playwright's own `TimeoutError`, an ordinary exception: catch it with `from playwright.sync_api import TimeoutError` / `except TimeoutError:`. `OperationTimeout` is the type the CLI **reports** (exit 8) when you do not catch it |
170
+ | executor and `state` | executor terminated (fail-stop): `state` is gone, `finally` blocks are not guaranteed | executor survives: `state` is intact |
171
+ | next move | raise `--timeout`, or split the work into smaller calls | `snapshot()` to check the page and that the target exists, then retry with the current ref; if the page is just slow, raise that call's `timeout=` |
172
+
173
+ When the call deadline is the smaller of the two — a `goto(url,
174
+ timeout=60_000)` under `--timeout 3` — running out is exit 7, never 8: any
175
+ failure that lands once the call deadline has run out is reported as the call
176
+ deadline's. Browser tabs survive both. After exit 7 the next call starts a
177
+ fresh executor on the same tab and works normally; keep progress across calls
178
+ with `state` or `remember()`, and do not re-run the same call unchanged.
162
179
 
163
180
  | exit | meaning |
164
181
  |---|---|
@@ -168,6 +185,7 @@ split it into several smaller calls (keep progress with `state` or
168
185
  | 3 | the code raised (a Playwright error, an `ElementNotFound`, …) |
169
186
  | 4 / 5 | auth wall / captcha — stop and ask the user |
170
187
  | 7 | `DeadlineExceeded`: the call deadline (`--timeout`) ran out |
188
+ | 8 | `OperationTimeout`: one Playwright call ran out of its `timeout=` and your code did not catch it |
171
189
 
172
190
  ## Driving The Browser: real Playwright
173
191
 
@@ -200,10 +218,13 @@ Browserwright keeps the normal Playwright API, but transparently patches
200
218
  `page` and on pages returned by `context.new_page()`. Any `wait_until` value you
201
219
  pass is accepted for compatibility and ignored: Browserwright always navigates
202
220
  to commit, waits briefly for DOMContentLoaded, then returns once rendering is
203
- stable or requests have been quiet. The default timeout is 60s, but normal
204
- pages return much earlier; if final stability is not reached, `goto` still
205
- returns the Playwright `Response | None` so you can inspect the page with
206
- `snapshot()`.
221
+ stable or requests have been quiet. The default timeout is 60s (or what you set
222
+ with `page.set_default_navigation_timeout()` / `set_default_timeout()`), but
223
+ normal pages return much earlier; if final stability is not reached, `goto`
224
+ still returns the Playwright `Response | None` so you can inspect the page with
225
+ `snapshot()`. A page that does not even commit in time raises a `TimeoutError`
226
+ (catch it as above; reported as `OperationTimeout`, exit 8, if uncaught); the
227
+ navigation may still land, so check `page.url` / `snapshot()` before retrying.
207
228
 
208
229
  ### Same live objects across calls (mental model)
209
230
 
@@ -255,7 +276,7 @@ page.goto("https://example.com")
255
276
 
256
277
  If the executor itself is wedged and cannot run `reset()`, use `browserwright session reset <id>`. Both reset paths recycle only the executor; the browser, tab group, and tabs stay open.
257
278
 
258
- The call deadline (`--timeout`, see above) follows the same fail-stop rule: Browserwright terminates that executor and waits for daemon confirmation before the command exits 7 with `DeadlineExceeded`. The next command starts fresh on the same browser tabs. An ordinary Playwright action timeout that is caught and returned normally does **not** recycle the executor. After fail-stop, Python `finally` blocks are not guaranteed to run and webpage side effects are not rolled back.
279
+ The call deadline (`--timeout`, see above) follows the same fail-stop rule: Browserwright terminates that executor and waits for daemon confirmation before the command exits 7 with `DeadlineExceeded`. The next command starts fresh on the same browser tabs. An operation timeout (`OperationTimeout`, exit 8), caught or not, does **not** recycle the executor. After fail-stop, Python `finally` blocks are not guaranteed to run and webpage side effects are not rolled back.
259
280
 
260
281
  ### Tabs are workstreams, not steps
261
282
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: browserwright
3
- Version: 0.22.0
3
+ Version: 0.23.0
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
File without changes
File without changes
File without changes