Compare commits

...
Author SHA1 Message Date
feder-crandClaude Sonnet 5.5 fec1320486 0.49.1: page.request_gc() works on a served browser
A change to the package's code takes a new version and a changelog entry: 0.49.0 is published.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 16:39:52 +01:00
feder-crandClaude Sonnet 5.5 428c36aa30 The periodic collection option is out: only the page.request_gc() fix stays
The engine has no behaviour that stock Playwright's Juggler lacks, and a server option that
sends a memory command on a schedule is one. INVPW_GC_EVERY_NAV and INVPW_GC_MODE, navgc.py,
the hook in the commit path, their unit tests, the e2e of the engine command and the entry in
the protocol-name scan leave the branch.

What stays is a defect of the standard API: page.request_gc() sent Heap.collectGarbage on the
browser connection, whose handler does not have it, so it failed on every call; it is now sent
with the session of the page. The test fails on main's server.py and passes here.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 16:19:28 +01:00
feder-cr 9d66fd437a Merge remote-tracking branch 'origin/main' into feat/gc-every-navigation 2026-11-10 16:18:32 +01:00
feder-crandClaude Sonnet 5.5 6d61df460a tests: the minimize e2e uses a plain protocol client, and the protocol-name scan lets the engine-gated name through
The e2e imported the installed Playwright (test_fork forbids it) and the vendored client has no
connect: it now speaks the protocol over the served WebSocket, like the other served-browser e2e.
Re-run on an engine with the command (all three pass) and on one without (the first and the third
fail, with the fallback warning).

Heap.minimizeMemory is written by navgc.py for an engine the published core's protocol mirror does
not describe yet, behind a fallback to the older command. test_protocol_names_are_declared keeps it
in AHEAD_OF_THE_MIRROR, still checks every other name, and a last test fails when the mirror gets
the command, saying to delete it from the list.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 15:20:54 +01:00
feder-crandClaude Sonnet 5.5 85ebef6698 INVPW_GC_MODE: the command must be named in the error that makes minimize fall back to gc
A fallback on any error saying "is not supported" would turn the mode down for good on an
unrelated error; the sign of an engine without the command is its answer naming it
("method 'Heap.minimizeMemory' is not supported", or 'does not implement method "..."').
Also the docs say what the command is: the memory manager's MinimizeMemoryUsage.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 15:15:12 +01:00
feder-crandClaude Sonnet 5.5 6d1180499c INVPW_GC_MODE=minimize: the option can send Heap.minimizeMemory, with a fallback to gc
INVPW_GC_MODE=gc|minimize (default gc) says what INVPW_GC_EVERY_NAV sends. minimize sends the
Juggler command that runs about:memory's "Minimize memory usage" (engine commit 2423b7c242 of
the engine's juggler/minimize branch); on an engine without it the first round logs one
warning and falls back to Heap.collectGarbage for that round and every later one (the
engine's answer, "method '...' is not supported", is the sign).

Unit tests for the mode, the fallback and the other errors; e2e (engine_at_least firefox-61)
that the engine takes the command and, as documentation, that minimize evicts the bfcache
(pageshow.persisted false on go_back) where nothing sent leaves it true. Measured on the
engine with the command, and on the one without: the first and third e2e fail there.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 15:15:12 +01:00
feder-cr 8956035edc Merge remote-tracking branch 'origin/main' into feat/gc-every-navigation 2026-11-10 14:58:04 +01:00
feder-crandClaude Sonnet 5.5 5b888467ed INVPW_GC_EVERY_NAV: send the collection with the page session; fix page.request_gc
Juggler answers Heap.collectGarbage from its page handler. Sent with the
browser-level connection it fails with 'Handler for does not implement method',
so the first version of the option counted every collection as failed, and
page.request_gc() has been failing the same way.

The option now sends with the session of the page that committed (a thread of its
own, one in flight); op_request_gc uses the page session too. Tests fail on the
old code and pass on the fix; measured on the engine: collections take 0.02-0.09 s
and the values a page reads are identical with the option on and off.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 14:09:02 +01:00
feder-crandClaude Sonnet 5.5 0e09ae57ee Add INVPW_GC_EVERY_NAV: optional Heap.collectGarbage every N main-frame navigations
Off by default. The collection is sent from a daemon thread (never from the
reader thread, which would deadlock), with at most one in flight; a round
due while one runs is skipped and counted, and every error is swallowed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 13:17:12 +01:00
4 changed files with 74 additions and 3 deletions

No files matched your search

+8
View File
@@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
## [Unreleased]
## [0.49.1] - 2026-11-10
### Fixed
- `page.request_gc()` works on a served browser. It sent the engine's `Heap.collectGarbage` on the
browser-level connection, whose handler does not have it, so every call failed with
`Handler for does not implement method "Heap.collectGarbage"`; it is now sent with the session
of the page, as the engine answers it.
## [0.49.0] - 2026-11-10
### Changed
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "invisible_playwright"
version = "0.49.0"
version = "0.49.1"
description = "Playwright wrapper for a patched Firefox with deterministic stealth profile."
readme = "README.md"
requires-python = ">=3.11"
+4 -2
View File
@@ -3478,8 +3478,10 @@ class PageDispatcher(Dispatcher):
"""⛔ `Heap.collectGarbage` really does collect, and it is SLOW - it was
once used as a "bare command" to measure transport latency and reported
26,8 ms of browser work as if it were ours. It is the right command
here, and the wrong one to benchmark with."""
self.conn.send("Heap.collectGarbage", {}, timeout=None)
here, and the wrong one to benchmark with. Sent with this page's session
(`self.send`): Juggler answers it from its PAGE handler, and the browser-level
connection (`self.conn`) gets 'Handler for does not implement method'."""
self.send("Heap.collectGarbage", {}, timeout=None)
return None
def op_add_script_tag(self, params: Dict) -> Any:
@@ -0,0 +1,61 @@
"""`page.request_gc()` (Playwright's own API) reaches the engine, which answers it.
⛔ THE KNOWN-BAD INPUT, measured on a real engine: `Page.requestGC` was answered by `op_request_gc` with
`Heap.collectGarbage` sent on the BROWSER connection, and Juggler's browser-level handler does not have it:
`Page.request_gc: Heap.collectGarbage: Handler for does not implement method "Heap.collectGarbage"`, on every
call. The command is a page command (`PageHandler`), so it goes with the session of the page.
No browser: the page dispatcher is built the way tests/test_navigation_*.py build one, with the two senders
replaced by mocks.
"""
from __future__ import annotations
from types import SimpleNamespace
from unittest.mock import Mock
import pytest
from invisible_core.juggler.connection import EventListeners
from invisible_core.juggler.lifecycle import Lifecycle
from invisible_playwright._juggler.dispatcher import Dispatcher
from invisible_playwright._juggler.server import (
FrameDispatcher,
JugglerServer,
PageDispatcher,
)
pytestmark = pytest.mark.unit
def make_page(server):
server.attach(SimpleNamespace(emit_message=lambda m: None))
context = Dispatcher(server, None)
context.options = {}
page = object.__new__(PageDispatcher)
page.context = context
page.lifecycle = Lifecycle(EventListeners(), "session")
page.injected = Mock()
page.actions = Mock()
page._frames = {}
page._navigation_requests = {}
page._announced_closed = False
Dispatcher.__init__(page, server, context)
page.frame = FrameDispatcher(server, page, "main")
for fid, parent in (("main", None), ("sub", "main")):
page.lifecycle._on_event("Page.frameAttached", {"frameId": fid, "parentFrameId": parent})
return page
def test_page_request_gc_is_sent_with_the_page_session_not_the_browser_connection():
page = make_page(JugglerServer())
page.send = Mock()
page.context.browser = SimpleNamespace(conn=Mock())
assert page.op_request_gc({}) is None
page.send.assert_called_once_with("Heap.collectGarbage", {}, timeout=None)
page.context.browser.conn.send.assert_not_called()
def test_the_protocol_name_it_writes_is_the_one_the_engine_declares():
from invisible_core.juggler.protocol import COMMANDS
assert "Heap.collectGarbage" in COMMANDS