browserwright 0.18.4__tar.gz → 0.18.6__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 (112) hide show
  1. {browserwright-0.18.4/src/browserwright.egg-info → browserwright-0.18.6}/PKG-INFO +1 -1
  2. {browserwright-0.18.4 → browserwright-0.18.6}/pyproject.toml +1 -1
  3. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/cli.py +78 -24
  4. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/listener.py +23 -4
  5. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/relay.py +43 -4
  6. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/session_create.py +16 -6
  7. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/skill_runtime.md +37 -14
  8. {browserwright-0.18.4 → browserwright-0.18.6/src/browserwright.egg-info}/PKG-INFO +1 -1
  9. {browserwright-0.18.4 → browserwright-0.18.6}/LICENSE +0 -0
  10. {browserwright-0.18.4 → browserwright-0.18.6}/README.md +0 -0
  11. {browserwright-0.18.4 → browserwright-0.18.6}/setup.cfg +0 -0
  12. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/__init__.py +0 -0
  13. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/__main__.py +0 -0
  14. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/_executor/__init__.py +0 -0
  15. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/_executor/__main__.py +0 -0
  16. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/_executor/client.py +0 -0
  17. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/_executor/process.py +0 -0
  18. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/_executor/protocol.py +0 -0
  19. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/_text.py +0 -0
  20. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/cdp.py +0 -0
  21. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/__init__.py +0 -0
  22. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/_ipc.py +0 -0
  23. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/_net.py +0 -0
  24. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/_rpc.py +0 -0
  25. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/_stale.py +0 -0
  26. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/backends/__init__.py +0 -0
  27. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/backends/base.py +0 -0
  28. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/backends/cdp.py +0 -0
  29. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/backends/extension.py +0 -0
  30. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/cli.py +0 -0
  31. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/config.py +0 -0
  32. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/doctor.py +0 -0
  33. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/errors.py +0 -0
  34. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/launch_chrome.py +0 -0
  35. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/launchagent.py +0 -0
  36. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/observability.py +0 -0
  37. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/platforms.py +0 -0
  38. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/probe.py +0 -0
  39. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/relay_status.py +0 -0
  40. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/resolver.py +0 -0
  41. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/restart_guard.py +0 -0
  42. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/__init__.py +0 -0
  43. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/daemon.py +0 -0
  44. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/exec_relay.py +0 -0
  45. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/executor_registry.py +0 -0
  46. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/extension_upstream.py +0 -0
  47. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/facade.py +0 -0
  48. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/facade_extension.py +0 -0
  49. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/proxy.py +0 -0
  50. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/session_state.py +0 -0
  51. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/state.py +0 -0
  52. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/status.py +0 -0
  53. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/upstream.py +0 -0
  54. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/server/verbs.py +0 -0
  55. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/supervise.py +0 -0
  56. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon/userscripts.py +0 -0
  57. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/daemon_url.py +0 -0
  58. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/discovery.py +0 -0
  59. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/errors.py +0 -0
  60. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/health.py +0 -0
  61. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/install.py +0 -0
  62. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/memory/__init__.py +0 -0
  63. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/memory/_lock.py +0 -0
  64. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/memory/_md.py +0 -0
  65. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/memory/_yaml.py +0 -0
  66. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/memory/global_mem.py +0 -0
  67. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/memory/site_mem.py +0 -0
  68. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/mode_b_client.py +0 -0
  69. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/output_schema.py +0 -0
  70. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/primitives/__init__.py +0 -0
  71. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/primitives/discovery_api.py +0 -0
  72. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/primitives/http.py +0 -0
  73. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/primitives/site.py +0 -0
  74. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/repl/__init__.py +0 -0
  75. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/repl/_md_convert.py +0 -0
  76. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/repl/_md_normalize.py +0 -0
  77. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/repl/_namespace.py +0 -0
  78. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/repl/_smart_goto.py +0 -0
  79. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/repl/inline.py +0 -0
  80. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/repl/markdown.py +0 -0
  81. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/repl/playwright_handle.py +0 -0
  82. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/repl/snapshot.py +0 -0
  83. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/repl/vendor/README.md +0 -0
  84. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/repl/vendor/readability.js +0 -0
  85. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/session.py +0 -0
  86. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/session_ctx.py +0 -0
  87. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/session_registry.py +0 -0
  88. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/session_runtime.py +0 -0
  89. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/github.com/SKILL.md +0 -0
  90. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/github.com/memory.md +0 -0
  91. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/github.com/tasks/list_issues.py +0 -0
  92. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/google.com/SKILL.md +0 -0
  93. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/google.com/memory.md +0 -0
  94. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/google.com/tasks/search.py +0 -0
  95. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/producthunt.com/SKILL.md +0 -0
  96. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/producthunt.com/memory.md +0 -0
  97. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/producthunt.com/tasks/today.py +0 -0
  98. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/wikipedia.org/SKILL.md +0 -0
  99. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/wikipedia.org/memory.md +0 -0
  100. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/wikipedia.org/tasks/lookup.py +0 -0
  101. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/ycombinator.com/SKILL.md +0 -0
  102. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/ycombinator.com/memory.md +0 -0
  103. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/site_skills_starter/ycombinator.com/tasks/front_page.py +0 -0
  104. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/skill_doc.py +0 -0
  105. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/tab_surface.py +0 -0
  106. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/task_runner.py +0 -0
  107. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright/version.py +0 -0
  108. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright.egg-info/SOURCES.txt +0 -0
  109. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright.egg-info/dependency_links.txt +0 -0
  110. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright.egg-info/entry_points.txt +0 -0
  111. {browserwright-0.18.4 → browserwright-0.18.6}/src/browserwright.egg-info/requires.txt +0 -0
  112. {browserwright-0.18.4 → browserwright-0.18.6}/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.18.4
3
+ Version: 0.18.6
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.4"
18
+ version = "0.18.6"
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"
@@ -45,7 +45,7 @@ Usage:
45
45
  One page as Markdown. Creates and tears down its own session, so it takes
46
46
  no -s. Absolute links, shadow DOM flattened in, HTML only.
47
47
 
48
- browserwright -s <session-id> task <site>/<name> [--key=value ...] [--isolated]
48
+ browserwright -s <session-id> task <site>/<name> [--env NAME ...] [--key=value ...] [--isolated]
49
49
  browserwright list-tasks [--site SITE] [--query Q] [--json]
50
50
 
51
51
  browserwright install
@@ -66,15 +66,25 @@ Global option (valid before or after any subcommand):
66
66
  """
67
67
 
68
68
  TASK_HELP = """Usage:
69
- browserwright -s <session-id> task <site>/<name> [--key=value ...] [--isolated]
69
+ browserwright -s <session-id> task <site>/<name> [--env NAME ...] [--key=value ...] [--isolated]
70
70
 
71
71
  Runs a site-skill task in the bound Browserwright session. Session may also be
72
72
  provided as --session=<id> after `task`, or via BD_SESSION.
73
73
 
74
+ Tasks run in the daemon-launched resident executor, whose PATH may differ from
75
+ the invoking shell. Environment variables are not forwarded implicitly. Select
76
+ only the names this request needs; for local executable lookup, use --env PATH.
77
+
74
78
  Flags:
79
+ --env NAME forward one variable from this CLI process for this
80
+ task request only; repeat for multiple variables
75
81
  --json-args JSON merge a JSON object into task args
76
82
  --json-output print task result as JSON
77
83
  --output json alias for --json-output
84
+
85
+ Executable lookup examples:
86
+ browserwright -s "$sid" task local.example/build --env PATH
87
+ browserwright -s "$sid" --env PATH -e 'run_task("local.example/build")'
78
88
  """
79
89
 
80
90
  USERSCRIPT_HELP = """Usage:
@@ -177,6 +187,27 @@ def _bind_cli_session(session_id: Optional[str]):
177
187
  return 0
178
188
 
179
189
 
190
+ def _parse_env_option(
191
+ args: list[str], index: int,
192
+ ) -> tuple[str, int, Optional[str]]:
193
+ """Parse one name-only ``--env`` option at ``index`` if present."""
194
+ arg = args[index]
195
+ if arg == "--env":
196
+ if index + 1 >= len(args) or args[index + 1].startswith("-"):
197
+ return "", 0, "--env requires a variable name"
198
+ name = args[index + 1]
199
+ consumed = 2
200
+ elif arg.startswith("--env="):
201
+ name = arg.split("=", 1)[1]
202
+ consumed = 1
203
+ else:
204
+ return "", 0, None
205
+ error = _validate_request_env_name(name)
206
+ if error:
207
+ return "", 0, error
208
+ return name, consumed, None
209
+
210
+
180
211
  def _parse_execute_args(
181
212
  args: list[str],
182
213
  ) -> tuple[Optional[str], Optional[str], list[str], Optional[str]]:
@@ -204,23 +235,12 @@ def _parse_execute_args(
204
235
  session_id = a.split("=", 1)[1]
205
236
  i += 1
206
237
  continue
207
- if a == "--env":
208
- if i + 1 >= n or args[i + 1].startswith("-"):
209
- return None, None, [], "--env requires a variable name"
210
- name = args[i + 1]
211
- error = _validate_execute_env_name(name)
212
- if error:
213
- return None, None, [], error
214
- env_names.append(name)
215
- i += 2
216
- continue
217
- if a.startswith("--env="):
218
- name = a.split("=", 1)[1]
219
- error = _validate_execute_env_name(name)
220
- if error:
221
- return None, None, [], error
222
- env_names.append(name)
223
- i += 1
238
+ env_name, consumed, env_error = _parse_env_option(args, i)
239
+ if env_error:
240
+ return None, None, [], env_error
241
+ if consumed:
242
+ env_names.append(env_name)
243
+ i += consumed
224
244
  continue
225
245
  if a in {"-e", "--execute"}:
226
246
  if i + 1 >= n:
@@ -300,7 +320,7 @@ def _parse_execute_args(
300
320
  return session_id, code, env_names, None
301
321
 
302
322
 
303
- def _validate_execute_env_name(name: str) -> Optional[str]:
323
+ def _validate_request_env_name(name: str) -> Optional[str]:
304
324
  """Validate one name-only ``--env`` argument without echoing its value."""
305
325
  from ._executor.protocol import is_valid_env_name
306
326
 
@@ -319,7 +339,7 @@ def _validate_execute_env_name(name: str) -> Optional[str]:
319
339
  return None
320
340
 
321
341
 
322
- def _resolve_execute_env(
342
+ def _resolve_request_env(
323
343
  env_names: list[str],
324
344
  ) -> tuple[dict[str, str], Optional[str]]:
325
345
  """Select explicit variables from this CLI process for one request."""
@@ -339,7 +359,7 @@ def _cmd_execute(args: list[str]) -> int:
339
359
  "(-e 'print(snapshot())' | -f script.py | --code-stdin)",
340
360
  file=sys.stderr)
341
361
  return 1
342
- request_env, err = _resolve_execute_env(env_names)
362
+ request_env, err = _resolve_request_env(env_names)
343
363
  if err:
344
364
  print(f"usage error: {err}", file=sys.stderr)
345
365
  return 1
@@ -351,12 +371,37 @@ def _cmd_execute(args: list[str]) -> int:
351
371
  )
352
372
 
353
373
 
374
+ def _extract_env_args(
375
+ args: list[str],
376
+ ) -> tuple[list[str], list[str], Optional[str]]:
377
+ """Remove repeatable name-only ``--env`` options from command arguments."""
378
+ env_names: list[str] = []
379
+ out: list[str] = []
380
+ i, n = 0, len(args)
381
+ while i < n:
382
+ arg = args[i]
383
+ env_name, consumed, env_error = _parse_env_option(args, i)
384
+ if env_error:
385
+ return [], [], env_error
386
+ if consumed:
387
+ env_names.append(env_name)
388
+ i += consumed
389
+ continue
390
+ out.append(arg)
391
+ i += 1
392
+ return env_names, out, None
393
+
394
+
354
395
  def _cmd_task(args: list[str], *, session_id: Optional[str] = None) -> int:
355
396
  if args and args[0] in {"-h", "--help"}:
356
397
  sys.stdout.write(TASK_HELP)
357
398
  return 0
399
+ usage = (
400
+ "usage: browserwright -s <session-id> task <site>/<name> "
401
+ "[--env NAME ...] [--key=val ...]"
402
+ )
358
403
  if not args:
359
- print("usage: browserwright -s <session-id> task <site>/<name> [--key=val ...]", file=sys.stderr)
404
+ print(usage, file=sys.stderr)
360
405
  return 1
361
406
  inner_session, args, err = _extract_session_arg(args)
362
407
  if err:
@@ -364,8 +409,16 @@ def _cmd_task(args: list[str], *, session_id: Optional[str] = None) -> int:
364
409
  return 1
365
410
  if inner_session:
366
411
  session_id = inner_session
412
+ env_names, args, err = _extract_env_args(args)
413
+ if err:
414
+ print(f"usage error: {err}", file=sys.stderr)
415
+ return 1
416
+ request_env, err = _resolve_request_env(env_names)
417
+ if err:
418
+ print(f"usage error: {err}", file=sys.stderr)
419
+ return 1
367
420
  if not args:
368
- print("usage: browserwright -s <session-id> task <site>/<name> [--key=val ...]", file=sys.stderr)
421
+ print(usage, file=sys.stderr)
369
422
  return 1
370
423
  spec = args[0]
371
424
  if "/" not in spec:
@@ -398,6 +451,7 @@ def _cmd_task(args: list[str], *, session_id: Optional[str] = None) -> int:
398
451
  name,
399
452
  args=kwargs,
400
453
  isolated=isolated,
454
+ env=request_env,
401
455
  )
402
456
  except Exception as e: # noqa: BLE001
403
457
  print(f"task crashed: {e!r}", file=sys.stderr)
@@ -696,6 +696,9 @@ class _UpstreamHolder:
696
696
  # across idle detach/reattach. The relay is transport only.
697
697
  self._extension_adapter: ExtensionUpstream | None = None
698
698
  self._last_auto_recover: float = 0.0
699
+ # A sweep is queued and has not started yet; later hellos ride on it.
700
+ self._auto_recover_queued: bool = False
701
+ self._auto_recover_hello: tuple[str, bool] = ("", False)
699
702
  # ADR-0013: the daemon's recovery state machine and its executor
700
703
  # liveness oracle, wired by `run_serve` once the Daemon exists.
701
704
  self.recovery = None
@@ -1067,15 +1070,31 @@ class _UpstreamHolder:
1067
1070
  self._note_extension_sessions(EXTENSION_HELLO, generation=generation,
1068
1071
  reason="extension connected; re-attaching tabs")
1069
1072
 
1073
+ # GH#106: the throttle defers, it never drops. It used to `return` for
1074
+ # a hello inside the window, so a service worker that restarted within
1075
+ # 10s of the previous sweep (e.g. a drift reload right after the first
1076
+ # hello) lost its tabs for good: nothing else re-attaches them.
1077
+ self._auto_recover_hello = (install_id, first_seen)
1078
+ if self._auto_recover_queued:
1079
+ return
1080
+ self._auto_recover_queued = True
1081
+
1070
1082
  async def _recover() -> None:
1071
1083
  try:
1072
1084
  await asyncio.sleep(_AUTO_RECOVER_DELAY_S)
1085
+ wait = (self._last_auto_recover + _AUTO_RECOVER_THROTTLE_S
1086
+ - time.monotonic())
1087
+ if wait > 0:
1088
+ await asyncio.sleep(wait)
1073
1089
  except asyncio.CancelledError:
1090
+ self._auto_recover_queued = False
1074
1091
  return
1075
- now = time.monotonic()
1076
- if (now - self._last_auto_recover) < _AUTO_RECOVER_THROTTLE_S:
1077
- return
1078
- self._last_auto_recover = now
1092
+ # Unqueue before sweeping: a hello that lands mid-sweep may come
1093
+ # from a SW that lost the tabs this sweep is re-attaching.
1094
+ self._auto_recover_queued = False
1095
+ self._last_auto_recover = time.monotonic()
1096
+ install_id, first_seen = self._auto_recover_hello
1097
+ generation = getattr(self.relay, "connection_generation", None)
1079
1098
  ext = self._extension_adapter
1080
1099
  if ext is None:
1081
1100
  return
@@ -97,6 +97,11 @@ APP_PING_INTERVAL = 5.0
97
97
  STALE_FRAME_AFTER = 30.0
98
98
  RECONNECT_WAIT_TIMEOUT = 35.0
99
99
 
100
+ # GH#106: first extension build whose ws handlers are bound to their own
101
+ # socket (GH#79 / #81). Older builds null the live `ws` from *any* socket's
102
+ # `onclose`, so closing a superseded socket makes them dial again.
103
+ SOCKET_BOUND_HANDLERS_VERSION = "0.17.2"
104
+
100
105
  # D (reload verification): after sending reloadExtension we wait this long for
101
106
  # the SW to come back before declaring it dead. Chrome does not reliably
102
107
  # restart a reloaded MV3 SW (the alarm net is cleared by the reload), so this
@@ -222,6 +227,19 @@ class _ExtensionConn:
222
227
  connection_generation: int = 0
223
228
 
224
229
 
230
+ def _has_legacy_ws_handlers(ext: _ExtensionConn) -> bool:
231
+ """True for a released build older than SOCKET_BOUND_HANDLERS_VERSION.
232
+
233
+ Unparseable versions and the unpacked dev build (`0.0.0`) run the handlers
234
+ in this checkout, so they count as current.
235
+ """
236
+ version = ext.browserwright_version or ext.version
237
+ if version == "0.0.0":
238
+ return False
239
+ order = compare_versions(version, SOCKET_BOUND_HANDLERS_VERSION).order
240
+ return order is not None and order < 0
241
+
242
+
225
243
  class RelayServer:
226
244
  """ws://127.0.0.1:19989 — extension talks to us here.
227
245
 
@@ -1055,6 +1073,15 @@ class RelayServer:
1055
1073
  "caller must revalidate ownership")
1056
1074
  return fresh
1057
1075
 
1076
+ def _evict_without_closing(self, ext: _ExtensionConn) -> None:
1077
+ if ext.app_ping_task is not None:
1078
+ ext.app_ping_task.cancel()
1079
+ # A legacy build answers on its newest socket, never on this one.
1080
+ for fut in list(ext.pending.values()):
1081
+ if not fut.done():
1082
+ fut.set_exception(ConnectionError(
1083
+ "extension relay superseded by a newer connection"))
1084
+
1058
1085
  async def _force_close_extension(self, ext: _ExtensionConn, *, reason: str) -> None:
1059
1086
  logger.warning(
1060
1087
  "force-closing stale extension relay connection: install_id=%s reason=%s",
@@ -1314,15 +1341,27 @@ class RelayServer:
1314
1341
  self._extensions.pop(temp_key, None)
1315
1342
  self._extensions[ext.install_id or temp_key] = ext
1316
1343
  ext.hello_received.set()
1344
+ # GH#106: never close the superseded socket of a pre-0.17.2 build.
1345
+ # Its `onclose` strands the extension's live socket, the next
1346
+ # dial supersedes that one, and the pair livelock about twice a
1347
+ # second. Evicting it is enough: it is off the routing table, and
1348
+ # with no ping loop nothing on this side ever closes it.
1349
+ closes_safely = not _has_legacy_ws_handlers(ext)
1317
1350
  for other in superseded:
1318
1351
  logger.info(
1319
1352
  "superseding older relay connection for install_id=%s "
1320
- "(the extension dialled twice)",
1353
+ "(the extension dialled twice)%s",
1321
1354
  ext.install_id,
1355
+ "" if closes_safely else
1356
+ "; leaving it open: extension %s predates socket-bound "
1357
+ "handlers" % (ext.browserwright_version or ext.version),
1322
1358
  )
1323
- asyncio.create_task(self._force_close_extension(
1324
- other, reason="superseded by a newer connection from the "
1325
- "same install_id"))
1359
+ if closes_safely:
1360
+ asyncio.create_task(self._force_close_extension(
1361
+ other, reason="superseded by a newer connection from "
1362
+ "the same install_id"))
1363
+ else:
1364
+ self._evict_without_closing(other)
1326
1365
  if ext.app_ping_task is None or ext.app_ping_task.done():
1327
1366
  ext.app_ping_task = asyncio.create_task(self._app_ping_loop(ext))
1328
1367
  self._first_ready.set()
@@ -25,6 +25,7 @@ from __future__ import annotations
25
25
  import json
26
26
  import socket
27
27
  import subprocess
28
+ import time
28
29
  from typing import Optional
29
30
 
30
31
  from . import session_registry as reg
@@ -200,6 +201,11 @@ def _end_daemon_session(record: dict) -> bool:
200
201
  return _run(cmd, timeout=_END_SESSION_CLI_TIMEOUT) == 0
201
202
 
202
203
 
204
+ #: How long `session reset` keeps retrying `kill-executor` against a daemon
205
+ #: that answers but has not finished starting (issue #40 after a SIGKILL).
206
+ _RESET_DAEMON_STARTUP_S = 10.0
207
+
208
+
203
209
  def reset_executor(record: dict) -> str:
204
210
  """Recycle only this session's resident executor.
205
211
 
@@ -209,12 +215,16 @@ def reset_executor(record: dict) -> str:
209
215
  """
210
216
  _ensure_daemon_running()
211
217
  sid = record["id"]
212
- rc = _run([
213
- "browserwright-daemon",
214
- "kill-executor",
215
- "--session",
216
- str(sid),
217
- ])
218
+ cmd = ["browserwright-daemon", "kill-executor", "--session", str(sid)]
219
+ rc = _run(cmd)
220
+ # `_ensure_daemon_running` returns as soon as it has spawned a daemon, so
221
+ # the first call can land while that daemon is still starting (and still
222
+ # sweeping the old one's orphans). Retry while it answers; a daemon that
223
+ # does not answer falls through to the local reap below at once.
224
+ deadline = time.monotonic() + _RESET_DAEMON_STARTUP_S
225
+ while rc != 0 and time.monotonic() < deadline and _daemon_is_running():
226
+ time.sleep(0.5)
227
+ rc = _run(cmd)
218
228
  if rc != 0:
219
229
  # Issue #40: when the daemon is unreachable, the executor cannot be
220
230
  # reaped through it and the session is stuck — the orphan blocks the
@@ -82,12 +82,34 @@ browserwright -s "$sid" -f script.py
82
82
  browserwright -s "$sid" --code-stdin < script.py
83
83
  ```
84
84
 
85
- ### Passing approved credentials to the resident executor
85
+ ### Passing caller environment to the resident executor
86
86
 
87
- A secret broker injects credentials into the short-lived CLI process, while
88
- browser code runs in the resident executor. Select each credential explicitly
89
- with repeatable `--env NAME`; Browserwright forwards only those values for that
90
- one request:
87
+ Browserwright never forwards the invoking shell's environment implicitly. A
88
+ pure `-e` body that does not reference an executor-bound name runs in the
89
+ short-lived CLI process and naturally sees that process's `PATH`. Direct tasks
90
+ always run in the resident executor, and referencing `run_task()` from `-e`
91
+ moves that whole code request there too. Because the daemon launched the
92
+ resident executor, its base environment and `PATH` can differ from the invoking
93
+ shell's.
94
+
95
+ Select each value explicitly with repeatable, name-only `--env NAME`. For a
96
+ local task that starts an executable available only through the caller's
97
+ `PATH`, forward `PATH` on either task entrypoint:
98
+
99
+ ```bash
100
+ # Direct task command
101
+ browserwright -s "$sid" task local.example/build --env PATH
102
+
103
+ # The same task nested in executor-backed inline code
104
+ browserwright -s "$sid" --env PATH -e 'run_task("local.example/build")'
105
+ ```
106
+
107
+ `--env PATH` sends the caller's string value as-is for one request; it does not
108
+ translate paths or make a client-machine executable available to a daemon on a
109
+ different host. No variable, including `PATH`, is selected by default.
110
+
111
+ The same mechanism forwards credentials injected into the short-lived CLI
112
+ process by a secret broker:
91
113
 
92
114
  ```bash
93
115
  approved-secret exec \
@@ -102,15 +124,16 @@ page.get_by_label("Password").fill(os.environ["SITE_PASSWORD"])
102
124
  '
103
125
  ```
104
126
 
105
- Pass names only. `--env SITE_EMAIL=value` is rejected so credential values do
106
- not enter shell history or the process argument list. An unset selected variable
107
- is also rejected before execution, and its value is never printed in the error.
108
- Inside the executor, selected variables temporarily overlay standard
109
- `os.environ` after the browser connection is ready. Browserwright restores the
110
- executor's prior environment exactly when the call succeeds, raises, or exits;
111
- the next call cannot see the values unless it selects them again. Values travel
112
- directly over the local executor socket and are not written to persistent
113
- `state`, discovery files, or Browserwright logs.
127
+ Pass names only. `--env SITE_EMAIL=value` is rejected so values do not enter
128
+ shell history or the process argument list. An unset selected variable is also
129
+ rejected before execution, and its value is never printed in the error. Inside
130
+ the executor, selected variables temporarily overlay standard `os.environ`
131
+ after the browser connection is ready. This applies equally to direct task
132
+ requests and executor-backed inline code. Browserwright restores the executor's
133
+ prior environment exactly when the call succeeds, raises, or exits; the next
134
+ call cannot see the values unless it selects them again. Values travel directly
135
+ over the local executor socket and are not written to persistent `state`,
136
+ discovery files, or Browserwright logs.
114
137
 
115
138
  ## Driving The Browser: real Playwright
116
139
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: browserwright
3
- Version: 0.18.4
3
+ Version: 0.18.6
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