Files
playwright/scripts/_upstream_alias.py
feder-cr 9292f2e26f Event delivery was recursive, and past 330 pages the browser stopped talking
Playwright's own suite, pointed at this client for the first time, broke at 63%
with a wall of 150 identical errors: newPage still answered with its targetId
and the attach event never arrived again. Commands alive, events dead, twenty
seconds of waiting per test.

Every subscriber captured the previous on_event and installed itself on top, so
delivering one event called the whole chain nested: the Python stack depth was
the number of subscribers. Nothing ever unsubscribed, and a page registers
three. Measured: 4 links at page 0, 979 at page 325, then RecursionError on
every event - inside the catch the read loop has so a bad handler cannot kill
it, which wrote the failure to a list capped at 32 entries that nobody reads.

One registry now, EventListeners: add_listener, remove_listener, and a
dispatch_event that iterates. The test fakes INHERIT it rather than imitating
it, because a fake with its own idea of what delivering an event means made
those tests green independently of the shipped code. The unsubscribe lives in
announce_closed, the one place that already knows a page is over.

A second leak was hiding behind the first: the server's guid registry grew by
one object per page. The protocol half was real - the driver disposes a closed
Page and we did not - and was found by giving diff_protocol a fifth dimension,
because its event comparison skips every method starting with __. The other
half was not protocol at all: the leftover was a FrameDispatcher, and the
driver sends nothing for frames because its client cascades children itself. So
children are dropped silently inside dispose(), and the wire stays identical.

After: one subscriber and eight objects at page 499, against 979 and 508.

Mutations run: the old recursive implementation stops at 965 of 5000, the same
limit seen in production at 979; announce_closed without the detach and an
inert Lifecycle.detach() both go red; and the e2e reports exactly 120 leaked
subscribers over forty pages, which is three per page.

The cursor default also moves to on. The wrapper forwards show_cursor=None and
lets invisible_core resolve it - a dependency on new BEHAVIOUR that no gate
here can see, since nothing fails to import. A test now imports
DEFAULT_SHOW_CURSOR by name so the ordering is enforced: publish the core, move
the pin, then release this.
2026-08-28 18:17:18 +02:00

95 lines
4.0 KiB
Python

"""Loaded with -p, before the suite's conftest, so the redirection is in place
by the time anything imports `playwright`."""
import sys, pathlib
_ROOT = pathlib.Path(__file__).resolve().parent.parent
sys.path.insert(0, str(_ROOT / "src"))
import invisible_playwright._pw as _pw
_NAMES = ['playwright', 'playwright._impl._assertions', 'playwright._impl._browser', 'playwright._impl._driver', 'playwright._impl._errors', 'playwright._impl._glob', 'playwright._impl._helper', 'playwright._impl._network', 'playwright._impl._page', 'playwright._impl._path_utils', 'playwright._impl._selectors', 'playwright.async_api', 'playwright.async_api._generated', 'playwright.sync_api']
class _Absent:
"""A module our client does not have, that says so when touched."""
def __init__(self, name, why):
self.__name__ = name
self._why = why
def __getattr__(self, attr):
# ⛔ IT HANDS BACK A CALLABLE AND RAISES ON THE CALL, not on the
# attribute. `from playwright._impl._driver import
# compute_driver_executable` is a module-level line in the suite's
# conftest, so raising here kills COLLECTION and takes all 657 tests
# with it - for a name used inside exactly one fixture. Failing at the
# call means the baseline loses only the tests that actually reach it,
# which is the honest count.
why = self._why
name = self.__name__
def gone(*a, **k):
raise RuntimeError(
"%s.%s does not exist in invisible_playwright: %s. This suite "
"is Playwright's own and tests components this package "
"removed - the Node driver went on 2026-08-28 - so a test that "
"reaches this name is testing something we deliberately do not "
"ship, not something broken." % (name, attr, why))
gone.__name__ = attr
return gone
def _absent(name, why):
return _Absent(name, why)
sys.modules["playwright"] = _pw
for _name in _NAMES:
if _name == "playwright":
continue
_tail = _name.split(".", 1)[1]
try:
_mod = __import__("invisible_playwright._pw." + _tail,
fromlist=["_"])
except ImportError as _failure:
# ⛔ A STAND-IN THAT EXPLAINS, not a silent skip and not a crash at
# collection. Our client genuinely lacks some modules - `_impl._driver`
# went with the Node driver - and the suite imports them at the top of
# its conftest while using them in ONE fixture. Refusing here would
# lose all 657 tests to a trace-viewer path; falling back to the real
# `playwright` would measure Microsoft's client and call it ours. So
# the name exists, and touching it says exactly what was removed.
_mod = _absent(_name, str(_failure))
sys.modules[_name] = _mod
def pytest_sessionstart(session):
"""Give every launch OUR engine.
The suite calls `browser_type.launch(**launch_arguments)` and those
arguments carry only `headless`: upstream downloads its browsers, we pin
one. Our launch REFUSES without an `executable_path` - correctly, it is the
seal's whole job - so the binary is injected here rather than by editing
the reference copy.
"""
import os
binary = os.environ.get("INVPW_BINARY_PATH")
if not binary:
return
from invisible_playwright._pw._impl import _browser_type as _bt
original = _bt.BrowserType.launch
async def launch(self, *args, **kwargs):
# ⛔ `executablePath`, camelCase: the impl layer takes the wire
# spelling, and `executable_path` would be swallowed by nothing and
# silently ignored - the launch would refuse exactly as before, and
# the patch would look installed while doing nothing.
if not kwargs.get("executablePath"):
kwargs["executablePath"] = binary
return await original(self, *args, **kwargs)
_bt.BrowserType.launch = launch
print("[baseline] every launch pinned to %s" % binary)