0.48.1: the browser never opens its crash reporter, launch_server is public (#437)
* e2e: the run stops at the first refusal of the engine instead of launching for 26 minutes
Against a firefox-59 engine whose gate wanted a declaration the core no longer made (59.58.0), the
suite went on for 26 minutes, launching the browser for each test, being refused each time with the
same sentence, and opening a crash window per refusal on the desktop. tests/engine_refusal.py reads
the text of a failed e2e report and, when it holds the engine's own refusal ("stealth: X is not
declared. Engine rule 7" or the scale refusal), stops the run with that sentence as the reason:
session.shouldstop on the serial path, the controller's shouldstop under xdist (a worker is never
stopped alone). A test that expects a refusal passes, so it never reaches the plugin; a unit test
that only quotes the sentence does not count.
The unit tests read the sentence; the integration tests run pytest over twenty e2e-marked tests of
which the second fails with the refusal, serial and with -n 2: the old suite ran all twenty (the two
fail without the plugin, and a failure that is not a refusal still runs all twenty).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* launch_server, launch_server_async and RemoteServer are on the package; the README shows a server and a client
The server API was reachable only through invisible_playwright._juggler.remote, a private path.
`from invisible_playwright import launch_server` now works, with launch_server_async and
RemoteServer, and they are in __all__. The README section "Serving one browser to many clients"
gets a complete example: a server with launch_server() and a Playwright for Python client that
connects to its ws_endpoint, how to install the extra, where it listens and how the browser ends,
and one line for a client in another language. The example was run against the real engine (the
server printed its address, the client read "Example Domain" and closed, the server's browser stayed
up until Enter).
The test checks the exports and reads the README block against the package; four of its five tests
fail on the old code.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* 0.48.1: invisible-core 59.60.0 (the browser never opens its crash reporter), launch_server on the package
Pins invisible-core 59.60.0, whose launch environment carries MOZ_CRASHREPORTER_DISABLE=1. The
version is 0.48.1 and the CHANGELOG names the crash reporter, the exported launch_server with its
README example and the e2e run that stops at the engine's first refusal.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f86007065
commit
f3d083aa85
8 files changed
+349
-4
No files matched your search
@@ -6,6 +6,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.48.1] - 2026-11-10
|
||||
|
||||
### Added
|
||||
- `launch_server`, `launch_server_async` and `RemoteServer` are importable from
|
||||
`invisible_playwright`, and the README's "Serving one browser to many clients" has a
|
||||
complete example: a server, and a Playwright for Python client that connects to its
|
||||
`ws_endpoint`.
|
||||
|
||||
### Changed
|
||||
- invisible-core 59.60.0, which this version pins. The browser never opens its crash
|
||||
reporter: the launch environment carries `MOZ_CRASHREPORTER_DISABLE=1`, so an engine that
|
||||
refuses a launch no longer leaves a "Crash Reporter" window on a Windows desktop.
|
||||
- The e2e run stops at the first refusal of the engine instead of launching the browser for
|
||||
every test (a change to the test suite, not to the package).
|
||||
|
||||
## [0.48.0] - 2026-11-10
|
||||
|
||||
### Added
|
||||
|
||||
@@ -127,8 +127,37 @@ Schemes supported: `socks5`, `socks4`, `http`, `https`. DNS is routed through th
|
||||
|
||||
### Serving one browser to many clients
|
||||
|
||||
`launch_server()` serves one browser on a WebSocket to any Playwright client. On Linux, set
|
||||
`MALLOC_ARENA_MAX=2` in the environment of the process that runs it (glibc keeps a memory
|
||||
`launch_server()` serves one browser on a WebSocket to any Playwright client. Install the
|
||||
extra that carries the WebSocket library with `uv add "invisible-playwright[remote]"`.
|
||||
|
||||
```python
|
||||
# server.py
|
||||
from invisible_playwright import launch_server
|
||||
|
||||
with launch_server(seed=42, headless=True) as server:
|
||||
print(server.ws_endpoint) # ws://127.0.0.1:<port>/<secret>
|
||||
input("serving, press Enter to stop")
|
||||
```
|
||||
|
||||
```python
|
||||
# client.py: any Playwright client; this one is Playwright for Python (uv add playwright)
|
||||
import sys
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.firefox.connect(sys.argv[1]) # the address the server printed
|
||||
page = browser.new_page()
|
||||
page.goto("https://example.com")
|
||||
print(page.title())
|
||||
browser.close() # ends this client; the server's browser keeps running
|
||||
```
|
||||
|
||||
The server listens on `127.0.0.1` with a random secret path; `host=`, `port=` and `path=` choose
|
||||
another address. A client in another language (Node, Java, .NET, Go) connects to the same
|
||||
address with the `connect` call of its own Playwright. The browser belongs to the server and
|
||||
ends with `server.close()` (or with the `with` block).
|
||||
|
||||
On Linux, set `MALLOC_ARENA_MAX=2` in the environment of the process that runs it (glibc keeps a memory
|
||||
arena per thread otherwise); the server already hands freed memory back with `malloc_trim`
|
||||
(`INVPW_MALLOC_TRIM=0` turns that off).
|
||||
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "invisible_playwright"
|
||||
version = "0.48.0"
|
||||
version = "0.48.1"
|
||||
description = "Playwright wrapper for a patched Firefox with deterministic stealth profile."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.11"
|
||||
@@ -69,7 +69,7 @@ dependencies = [
|
||||
# metadata; nothing in src/ hardcodes a second copy (tests/test_core_pin.py
|
||||
# fails if one appears). What stays invisible to install-time machinery is the
|
||||
# --no-deps / lockfile residue, and _pin.py is the only layer that sees it.
|
||||
"invisible_core==59.59.0",
|
||||
"invisible_core==59.60.0",
|
||||
# ⛔ playwright is NO LONGER a dependency: since the full fork, the Python
|
||||
# client lives in src/invisible_playwright/_pw/ and its server in
|
||||
# src/invisible_playwright/_juggler/ (no Node driver). Reintroducing it would not visibly
|
||||
|
||||
@@ -68,6 +68,7 @@ from invisible_core import BINARY_VERSION, FIREFOX_UPSTREAM_VERSION
|
||||
from invisible_core import GeoTimezoneError, resolve_session_timezone
|
||||
from invisible_core import ensure_binary, ensure_geoip_mmdb
|
||||
from .launcher import InvisiblePlaywright
|
||||
from ._juggler.remote import RemoteServer, launch_server, launch_server_async
|
||||
|
||||
# `__version__` describes the CODE that is about to run; the install record is
|
||||
# a different fact and keeps a name that says so, the way `invisible_core` does.
|
||||
@@ -79,6 +80,9 @@ from ._version import __install_record_version__, __version__
|
||||
|
||||
__all__ = [
|
||||
"InvisiblePlaywright",
|
||||
"launch_server",
|
||||
"launch_server_async",
|
||||
"RemoteServer",
|
||||
"ensure_binary",
|
||||
"ensure_geoip_mmdb",
|
||||
"get_default_stealth_prefs",
|
||||
|
||||
@@ -69,6 +69,12 @@ def _watchdog_open():
|
||||
return _watchdog_handle
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
# The run stops at the first refusal of the engine (tests/engine_refusal.py).
|
||||
from engine_refusal import StopAtTheFirstRefusal
|
||||
config.pluginmanager.register(StopAtTheFirstRefusal(config), "engine-refusal-stop")
|
||||
|
||||
|
||||
def pytest_runtest_setup(item):
|
||||
if item.get_closest_marker("e2e") is None:
|
||||
return
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
"""The e2e run stops at the first refusal of the engine.
|
||||
|
||||
The engine refuses a launch whose declarations are incomplete ("stealth: zoom.stealth.X is not
|
||||
declared. Engine rule 7 ..."), and it refuses it the same way for every test that follows: the
|
||||
core and the engine do not agree, and no test after the first can say anything the first did not.
|
||||
Before this plugin the run went on for 26 minutes, launching the browser for each of ~450 tests
|
||||
and filling the desktop with crash windows, to report one cause 313 times.
|
||||
|
||||
The plugin reads the text of a FAILED report. A refusal in it is the engine's own sentence, and
|
||||
the run is stopped there, with that sentence as the reason:
|
||||
|
||||
* serial: `session.shouldstop` on the test's session (pytest stops before the next test);
|
||||
* under xdist: the controller's `DSession.shouldstop` (the workers are told to finish, and the
|
||||
tests that have not started do not start). A worker's own session is not touched: stopping a
|
||||
worker alone would make the controller schedule its tests on the others.
|
||||
|
||||
A test that EXPECTS a refusal (`pytest.raises`) does not fail, so it never reaches here.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
#: The sentences the engine's gate writes through StealthRefuse (StealthDeclarationGate.cpp).
|
||||
REFUSAL = re.compile(
|
||||
r"stealth: [^\n]*(?:is not declared\. Engine rule 7"
|
||||
r"|The scale is part of the declaration)")
|
||||
|
||||
|
||||
def refusal_in(text: str) -> Optional[str]:
|
||||
"""The engine's refusal sentence in `text` (one line, as printed), or None."""
|
||||
match = REFUSAL.search(text or "")
|
||||
if not match:
|
||||
return None
|
||||
end = text.find("\n", match.end())
|
||||
return text[match.start():end if end != -1 else None].strip()[:300]
|
||||
|
||||
|
||||
def reason_to_stop(report) -> Optional[str]:
|
||||
"""Why the run must stop after this report, or None. Only the failure of an e2e test counts:
|
||||
a unit test that quotes the sentence (this plugin's own) did not launch the engine."""
|
||||
if not getattr(report, "failed", False):
|
||||
return None
|
||||
if "e2e" not in getattr(report, "keywords", {}):
|
||||
return None
|
||||
sentence = refusal_in(getattr(report, "longreprtext", "") or "")
|
||||
if sentence is None:
|
||||
return None
|
||||
return ("the engine refused a launch (%s): every test after this one would launch the same "
|
||||
"browser and be refused the same way. First seen in %s" % (sentence, report.nodeid))
|
||||
|
||||
|
||||
class StopAtTheFirstRefusal:
|
||||
"""The pytest plugin. Register an instance with `config.pluginmanager.register`."""
|
||||
|
||||
def __init__(self, config) -> None:
|
||||
self.config = config
|
||||
self.stopped_by: Optional[str] = None
|
||||
self.session = None
|
||||
|
||||
def _controller(self):
|
||||
return self.config.pluginmanager.getplugin("dsession")
|
||||
|
||||
def pytest_sessionstart(self, session) -> None:
|
||||
self.session = session
|
||||
|
||||
def pytest_runtest_logreport(self, report) -> None:
|
||||
if self.stopped_by is not None:
|
||||
return
|
||||
reason = reason_to_stop(report)
|
||||
if reason is None:
|
||||
return
|
||||
self.stopped_by = reason
|
||||
controller = self._controller()
|
||||
if controller is not None: # the controller of an xdist run
|
||||
controller.shouldstop = reason
|
||||
elif not hasattr(self.config, "workerinput"): # the serial path (a worker has workerinput)
|
||||
self.session.shouldstop = reason
|
||||
|
||||
def pytest_terminal_summary(self, terminalreporter) -> None:
|
||||
if self.stopped_by:
|
||||
terminalreporter.write_sep("!", "stopped at the first refusal of the engine")
|
||||
terminalreporter.write_line(self.stopped_by)
|
||||
@@ -0,0 +1,142 @@
|
||||
"""The e2e run stops at the first refusal of the engine instead of launching for 26 minutes.
|
||||
|
||||
Run on 59.58.0 against a firefox-59 engine whose gate wanted a declaration the core no longer made,
|
||||
the suite went on for 26 minutes, launching the browser for every test and being refused every
|
||||
time, and opened a crash window per refusal. The plugin in `tests/engine_refusal.py` reads the
|
||||
text of a failed report and stops the run at the engine's own sentence.
|
||||
|
||||
The unit tests read the sentence. The integration tests run pytest, serial and under xdist, over
|
||||
twenty tests of which the second fails with the engine's refusal: the old suite ran all twenty.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from engine_refusal import refusal_in, reason_to_stop
|
||||
|
||||
TESTS = Path(__file__).resolve().parent
|
||||
|
||||
SENTENCE = ("stealth: zoom.stealth.text.coverage_ladder is not declared. Engine rule 7 - a "
|
||||
"finite-domain value lives only in invisible_core, and a missing declaration refuses "
|
||||
"rather than falling back to a compiled default or to the host.")
|
||||
|
||||
# The failure as the wrapper's own tests print it (the browser's last output, indented).
|
||||
PRINTED = ("E invisible_playwright._pw._impl._errors.TargetClosedError: BrowserContext.new_page: "
|
||||
"Browser.newPage: the pipe closed:\nE the browser exited with code 0\n"
|
||||
"E its last output:\nE Juggler listening to the pipe\nE " + SENTENCE +
|
||||
"\nE Exiting due to channel error.\n")
|
||||
|
||||
|
||||
class Report:
|
||||
def __init__(self, failed, text, nodeid="tests/test_x.py::test_a", keywords=("e2e",)):
|
||||
self.failed, self.longreprtext, self.nodeid = failed, text, nodeid
|
||||
self.keywords = {k: 1 for k in keywords}
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_refusal_is_found_in_a_printed_failure():
|
||||
assert refusal_in(PRINTED) == SENTENCE[:300]
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_scale_refusal_is_found_too():
|
||||
text = ("E stealth: layout.css.devPixelsPerPx is 1.5000, but the declared screen is 1920 CSS "
|
||||
"pixels over a 1920 device-pixel work area. The scale is part of the declaration "
|
||||
"(invisible_core sets it from the persona's DPR): pin screen.dpr.\n")
|
||||
assert refusal_in(text).startswith("stealth: layout.css.devPixelsPerPx")
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.parametrize("text", [
|
||||
"", "AssertionError: 3 != 4", "TargetClosedError: the pipe closed: the browser exited with code 1",
|
||||
"stealth: something else the gate never says",
|
||||
])
|
||||
def test_any_other_failure_is_not_a_refusal(text):
|
||||
assert refusal_in(text) is None
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_only_a_failed_report_stops_the_run():
|
||||
assert reason_to_stop(Report(True, PRINTED)) is not None
|
||||
assert reason_to_stop(Report(False, PRINTED)) is None, "a test that expected the refusal passes"
|
||||
assert reason_to_stop(Report(True, "AssertionError")) is None
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_a_unit_test_that_quotes_the_sentence_does_not_stop_the_run():
|
||||
assert reason_to_stop(Report(True, PRINTED, keywords=("unit",))) is None
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_reason_names_the_sentence_and_the_first_test():
|
||||
reason = reason_to_stop(Report(True, PRINTED, "tests/test_mouse.py::test_click"))
|
||||
assert "coverage_ladder is not declared" in reason and "tests/test_mouse.py::test_click" in reason
|
||||
|
||||
|
||||
# ── pytest itself, serial and parallel ─────────────────────────────────────
|
||||
|
||||
N = 20
|
||||
|
||||
|
||||
def _project(root: Path, failing_text: str) -> None:
|
||||
(root / "conftest.py").write_text(textwrap.dedent("""
|
||||
import sys
|
||||
sys.path.insert(0, %r)
|
||||
from engine_refusal import StopAtTheFirstRefusal
|
||||
|
||||
def pytest_configure(config):
|
||||
config.pluginmanager.register(StopAtTheFirstRefusal(config), "engine-refusal-stop")
|
||||
""" % str(TESTS)), encoding="utf-8")
|
||||
for i in range(N):
|
||||
body = ("import time, pytest\npytestmark = pytest.mark.e2e\n\n"
|
||||
"def test_%d():\n time.sleep(0.4)\n" % i)
|
||||
if i == 1:
|
||||
body = ("import pytest\npytestmark = pytest.mark.e2e\n\ndef test_%d():\n"
|
||||
" raise RuntimeError(%r)\n" % (i, failing_text))
|
||||
(root / ("test_t%02d.py" % i)).write_text(body, encoding="utf-8")
|
||||
|
||||
|
||||
def _run(root: Path, *extra: str) -> str:
|
||||
done = subprocess.run([sys.executable, "-m", "pytest", "-q", "-p", "no:cacheprovider",
|
||||
"-rN", "--rootdir", str(root)] + list(extra),
|
||||
cwd=root, capture_output=True, text=True, timeout=180)
|
||||
return done.stdout + done.stderr
|
||||
|
||||
|
||||
def _ran(output: str) -> int:
|
||||
import re
|
||||
m = re.search(r"(\d+) failed", output)
|
||||
failed = int(m.group(1)) if m else 0
|
||||
m = re.search(r"(\d+) passed", output)
|
||||
return failed + (int(m.group(1)) if m else 0)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_a_serial_run_stops_at_the_refusal(tmp_path):
|
||||
_project(tmp_path, SENTENCE)
|
||||
out = _run(tmp_path)
|
||||
assert "stopped at the first refusal of the engine" in out, out
|
||||
assert "coverage_ladder is not declared" in out, out
|
||||
assert _ran(out) <= 3, "the run went on after the refusal:\n" + out
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_a_parallel_run_stops_at_the_refusal(tmp_path):
|
||||
pytest.importorskip("xdist")
|
||||
_project(tmp_path, SENTENCE)
|
||||
out = _run(tmp_path, "-n", "2", "--dist", "load")
|
||||
assert "stopped at the first refusal of the engine" in out, out
|
||||
assert _ran(out) < N - 5, "the run went on after the refusal:\n" + out
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_a_failure_that_is_not_a_refusal_does_not_stop_the_run(tmp_path):
|
||||
_project(tmp_path, "an ordinary bug")
|
||||
out = _run(tmp_path)
|
||||
assert _ran(out) == N, out
|
||||
assert "stopped at the first refusal" not in out
|
||||
@@ -0,0 +1,66 @@
|
||||
"""`from invisible_playwright import launch_server` works, and the README's example is the one that runs.
|
||||
|
||||
The server API lived only at `invisible_playwright._juggler.remote`, a private path: the README
|
||||
and every caller had to name a module that is allowed to move. The names a user writes are on the
|
||||
package, and the README block that shows them is the one a reader copies, so it is read here and
|
||||
checked against the package: every name it imports from `invisible_playwright` exists, and the
|
||||
two files (server and client) are both there. The example itself was run against the real engine
|
||||
when it was written (the server prints its address, Playwright for Python connects, reads a page's
|
||||
title and closes; the server's browser stays up until Enter).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
import invisible_playwright
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
README = (Path(__file__).resolve().parents[1] / "README.md").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_the_server_api_is_on_the_package():
|
||||
from invisible_playwright import RemoteServer, launch_server, launch_server_async
|
||||
from invisible_playwright._juggler import remote
|
||||
assert launch_server is remote.launch_server
|
||||
assert launch_server_async is remote.launch_server_async
|
||||
assert RemoteServer is remote.RemoteServer
|
||||
|
||||
|
||||
def test_the_names_are_in_all():
|
||||
for name in ("launch_server", "launch_server_async", "RemoteServer"):
|
||||
assert name in invisible_playwright.__all__
|
||||
|
||||
|
||||
def test_importing_the_package_does_not_need_the_websocket_library():
|
||||
"""The extra is optional: the import is at the top of the package and must not reach for it."""
|
||||
source = (Path(invisible_playwright.__file__).parent / "_juggler" / "remote.py").read_text(encoding="utf-8")
|
||||
top = [line for line in source.splitlines() if re.match(r"^(import|from) websockets", line)]
|
||||
assert top == [], "remote.py imports websockets at the top: %r" % top
|
||||
|
||||
|
||||
def _section() -> str:
|
||||
return README.split("### Serving one browser to many clients")[1].split("\n### ")[0]
|
||||
|
||||
|
||||
def test_the_readme_example_names_only_what_the_package_exports():
|
||||
blocks = re.findall(r"```python\n(.*?)```", _section(), re.S)
|
||||
assert len(blocks) == 2, "the section shows a server and a client: %d blocks" % len(blocks)
|
||||
server, client = blocks
|
||||
imported = re.findall(r"from invisible_playwright import ([\w, ]+)", server)
|
||||
assert imported, "the server example does not import from invisible_playwright"
|
||||
for names in imported:
|
||||
for name in (n.strip() for n in names.split(",")):
|
||||
assert hasattr(invisible_playwright, name), name
|
||||
assert "ws_endpoint" in server and "launch_server(" in server
|
||||
assert ".firefox.connect(" in client
|
||||
assert "invisible_playwright._juggler" not in README, "the README names a private module"
|
||||
|
||||
|
||||
def test_the_readme_says_how_to_install_the_extra_and_how_a_browser_ends():
|
||||
section = _section()
|
||||
assert 'uv add "invisible-playwright[remote]"' in section
|
||||
assert "server.close()" in section
|
||||
Reference in new issue
Block a user