Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fef0bc5ea7 | ||
|
|
2bc12eb80b | ||
|
|
ff2123ef58 | ||
|
|
5402da4d80 |
No files matched your search
+10
-1
@@ -6,7 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.50.0] - 2026-11-11
|
||||
## [0.50.1] - 2026-11-11
|
||||
|
||||
0.50.0 was tagged and never published: its end-to-end gate was red on two tests that counted processes.
|
||||
0.50.1 is 0.50.0 with those tests corrected.
|
||||
|
||||
### Changed
|
||||
- Engine firefox-62 through invisible-core 62.63.0, which this version pins: firefox-61 plus Fission
|
||||
@@ -37,6 +40,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
(`geolocation`, `persistent-storage`, `push`, `notifications`, `screen-wake-lock`); any other name
|
||||
raises `Unknown permission`, as it does there, and a grant with no origin is a grant for every
|
||||
origin.
|
||||
- The end-to-end tests that count content processes count the ones that host a site, not every content
|
||||
process that is new. The engine keeps a pool of preallocated processes and refills it whenever it gets
|
||||
to it, so a refill landing between two reads looked like a process the test had caused (a same-site
|
||||
frame, a closed context with a service worker that never stops). Measured on firefox-62: a closed context
|
||||
leaves no process of its site. On Linux the process is named by the site it hosts; elsewhere these
|
||||
tests skip.
|
||||
|
||||
## [0.49.1] - 2026-11-10
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "invisible_playwright"
|
||||
version = "0.50.0"
|
||||
version = "0.50.1"
|
||||
description = "Playwright wrapper for a patched Firefox with deterministic stealth profile."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.11"
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
"""Which of the engine's processes host a site: what the e2e tests that count processes read.
|
||||
|
||||
A content process is not a site's by being new. The engine keeps preallocated content processes
|
||||
(`dom.ipc.processPrelaunch.fission.number`, 3), hands one to a site when a site needs a process, and starts
|
||||
another to refill the pool whenever it gets to it, so a pid that appears between two reads is often that refill.
|
||||
On Linux the process says which it is: `ContentChild::SetProcessName` names it by its remote type with
|
||||
`prctl(PR_SET_NAME)` (ipc/glue/ProcessUtils_linux.cpp), "Isolated Web Co" once it hosts a site of strategy 1
|
||||
(`webIsolated=<site>`), "Web Content" while it is preallocated. Windows names no process
|
||||
(ProcessUtils_none.cpp): a test that counts sites skips there and says so.
|
||||
|
||||
Measured on firefox-62 (Linux): a cross-site frame renames one preallocated process and a new "Web Content"
|
||||
refills the pool; a same-site frame changes neither; a closed context leaves no "Isolated Web Co", while the
|
||||
pool of "Web Content" fills up behind it in about half the runs.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
#: The name a content process of strategy 1 takes once it hosts a site (PR_SET_NAME keeps 15 characters of
|
||||
#: "Isolated Web Content"). A preallocated one is "Web Content" until a site is given to it.
|
||||
SITE_PROCESS_NAME = "Isolated Web Co"
|
||||
|
||||
|
||||
def site_pids(processes, engine_dir=None):
|
||||
"""The pids, among `processes` (psutil-like), of the content processes that host a site; with `engine_dir`,
|
||||
only those of the engine in that directory."""
|
||||
import psutil
|
||||
|
||||
pids = set()
|
||||
for proc in processes:
|
||||
try:
|
||||
if engine_dir is not None and not os.path.normcase(proc.exe()).startswith(os.path.normcase(engine_dir)):
|
||||
continue
|
||||
name, cmd = proc.name(), proc.cmdline()
|
||||
except psutil.Error:
|
||||
continue
|
||||
if "-contentproc" in cmd and cmd and cmd[-1] == "tab" and name == SITE_PROCESS_NAME:
|
||||
pids.add(proc.pid)
|
||||
return pids
|
||||
|
||||
|
||||
def site_processes_below(root_pid, engine_dir=None):
|
||||
"""The pids of the processes below `root_pid` that host a site. Off Linux the test skips: no name says it."""
|
||||
import psutil
|
||||
|
||||
if not sys.platform.startswith("linux"):
|
||||
pytest.skip("only Linux names a content process by the site it hosts; %s names none" % sys.platform)
|
||||
try:
|
||||
children = psutil.Process(root_pid).children(recursive=True)
|
||||
except psutil.Error:
|
||||
return set()
|
||||
return site_pids(children, engine_dir)
|
||||
@@ -7,10 +7,13 @@ four such contexts left four more processes (8 web content processes at the end
|
||||
BrowserContext now waits a few seconds for the processes of its container once its pages are gone, and kills the
|
||||
ones that stay.
|
||||
|
||||
The test closes five such contexts in a row and counts the web content processes under the engine after each.
|
||||
The first context may add ONE process that is not the leak (the engine starts a spare content process when the
|
||||
first page takes one, and Linux keeps it), so the count after the fifth must not be above the count after the
|
||||
SECOND: a flat line from there on (on the old engine every context adds one: [4, 5, 6, 7, 8]).
|
||||
The test closes five such contexts in a row. While each page is open it counts the processes that host a site
|
||||
(at least one: the page's, or the count would prove nothing), and once `close` has answered it waits a few
|
||||
seconds for them to be gone: none may be left (on the old engine every context leaves its own, one more each
|
||||
time). Only the processes that host a site are counted (tests/_processes.py): the engine refills its pool of
|
||||
preallocated content processes behind a closed context, in about half the runs, and counting every content
|
||||
process read that refill as a leak ([2, 2, 2, 5, 5] on the e2e of the 0.50.0 commit, three "Web Content" and no
|
||||
site left). Off Linux the test skips: no other system names the process.
|
||||
|
||||
The engine that does it is not published when this file is written: `engine_at_least` makes the test wait for
|
||||
it, and on an older engine it is skipped, never passed.
|
||||
@@ -27,6 +30,7 @@ import pytest
|
||||
pytest.importorskip("websockets")
|
||||
from websockets.asyncio.client import connect # noqa: E402
|
||||
|
||||
from _processes import site_processes_below # noqa: E402
|
||||
from _servers import LocalServer # noqa: E402
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
@@ -59,24 +63,6 @@ def _serve():
|
||||
return server, "http://127.0.0.1:%d" % server.server_address[1]
|
||||
|
||||
|
||||
def _web_processes(root_pid):
|
||||
import psutil
|
||||
|
||||
found = set()
|
||||
try:
|
||||
children = psutil.Process(root_pid).children(recursive=True)
|
||||
except psutil.Error:
|
||||
return found
|
||||
for process in children:
|
||||
try:
|
||||
command = " ".join(process.cmdline())
|
||||
except psutil.Error:
|
||||
continue
|
||||
if "-contentproc" in command and command.rstrip().endswith(" tab"):
|
||||
found.add(process.pid)
|
||||
return found
|
||||
|
||||
|
||||
class _Client:
|
||||
"""The few calls of Playwright's protocol this test needs, over the served WebSocket."""
|
||||
|
||||
@@ -114,8 +100,11 @@ def test_closed_contexts_with_a_never_stopping_service_worker_leave_no_process(f
|
||||
launched = launch_server(host="127.0.0.1", port=0, headless=True, virtual_display=False, humanize=False,
|
||||
seed=4266, binary_path=firefox_binary, launch_timeout_ms=180_000)
|
||||
|
||||
def sites():
|
||||
return site_processes_below(launched.process.pid)
|
||||
|
||||
async def drive():
|
||||
counts = []
|
||||
opened, left = [], []
|
||||
async with connect(launched.ws_endpoint, max_size=None) as ws:
|
||||
client = _Client(ws)
|
||||
await client.start()
|
||||
@@ -123,21 +112,18 @@ def test_closed_contexts_with_a_never_stopping_service_worker_leave_no_process(f
|
||||
context, frame = await client.new_page()
|
||||
await client.call(frame, "goto", {"url": "%s/?i=%d" % (base, i), "waitUntil": "load", "timeout": 30000})
|
||||
await asyncio.sleep(1.0) # the worker is registered, its install loop is running
|
||||
await client.call(context, "close")
|
||||
deadline = time.time() + 10
|
||||
settled = None
|
||||
while time.time() < deadline: # the count after the close, once it stops moving
|
||||
now = _web_processes(launched.process.pid)
|
||||
if settled is not None and len(now) == settled:
|
||||
break
|
||||
settled = len(now)
|
||||
await asyncio.sleep(1.0)
|
||||
counts.append(len(_web_processes(launched.process.pid)))
|
||||
return counts
|
||||
opened.append(len(sites()))
|
||||
await client.call(context, "close") # the engine waits for the context's processes, then kills
|
||||
deadline = time.time() + 5
|
||||
while sites() and time.time() < deadline:
|
||||
await asyncio.sleep(0.25)
|
||||
left.append(len(sites()))
|
||||
return opened, left
|
||||
|
||||
try:
|
||||
counts = asyncio.run(drive())
|
||||
opened, left = asyncio.run(drive())
|
||||
finally:
|
||||
launched.close()
|
||||
server.shutdown()
|
||||
assert counts[4] <= counts[1], "web content processes after each closed context: %r" % (counts,)
|
||||
assert all(opened), "a page with no process for its site: the count proves nothing (%r)" % (opened,)
|
||||
assert left == [0] * 5, "processes of a site left after each closed context: %r" % (left,)
|
||||
@@ -21,9 +21,10 @@ test says what the product does not do yet and the step that makes it green:
|
||||
9 named world after the OOP frame step 1a + 2b
|
||||
10 console of the OOP frame step 1a
|
||||
|
||||
The oracle for "another process" is the engine's own processes below the test (`-contentproc ... tab`): a
|
||||
cross-site frame adds at least one, a same-site one adds none. The count is read after the browser is quiet
|
||||
(the engine pre-allocates a content process and replaces it when it is used).
|
||||
The oracle for "another process" is the set of the engine's processes that host a site, below the test
|
||||
(tests/_processes.py says how a site's process is told from a preallocated one): a cross-site frame adds at
|
||||
least one, a same-site one changes nothing. The set is read once it is quiet. Off Linux the two tests that
|
||||
count processes skip: no other system names the process.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -37,6 +38,7 @@ from urllib.parse import parse_qs, urlsplit
|
||||
|
||||
import pytest
|
||||
|
||||
from _processes import site_processes_below
|
||||
from _servers import LocalServer
|
||||
|
||||
FISSION_ON = {
|
||||
@@ -125,30 +127,18 @@ def engine_dir(firefox_binary):
|
||||
return str(Path(firefox_binary).resolve().parent)
|
||||
|
||||
|
||||
def content_processes(engine_dir):
|
||||
"""The pids of the engine's web content processes (`-contentproc ... tab`) below this test."""
|
||||
import psutil
|
||||
|
||||
pids = set()
|
||||
for child in psutil.Process(os.getpid()).children(recursive=True):
|
||||
try:
|
||||
if not os.path.normcase(child.exe()).startswith(os.path.normcase(engine_dir)):
|
||||
continue
|
||||
cmd = child.cmdline()
|
||||
except psutil.Error:
|
||||
continue
|
||||
if "-contentproc" in cmd and cmd[-1] == "tab":
|
||||
pids.add(child.pid)
|
||||
return pids
|
||||
def site_processes(engine_dir):
|
||||
"""The pids of the engine's processes below this test that host a site (tests/_processes.py)."""
|
||||
return site_processes_below(os.getpid(), engine_dir)
|
||||
|
||||
|
||||
def quiet(engine_dir, seconds=3.0, limit=30.0):
|
||||
"""The set of content processes once it has not changed for `seconds`."""
|
||||
"""The set of the processes that host a site, once it has not changed for `seconds`."""
|
||||
end = time.time() + limit
|
||||
last, since = content_processes(engine_dir), time.time()
|
||||
last, since = site_processes(engine_dir), time.time()
|
||||
while time.time() < end:
|
||||
time.sleep(0.25)
|
||||
now = content_processes(engine_dir)
|
||||
now = site_processes(engine_dir)
|
||||
if now != last:
|
||||
last, since = now, time.time()
|
||||
elif time.time() - since >= seconds:
|
||||
@@ -218,18 +208,27 @@ def test_cross_site_iframe_gets_its_own_process(page, cross_site_loop, engine_di
|
||||
assert wait_for(page, lambda: any(r["path"] == "/report/loaded" and r["host"] == "a.test" and
|
||||
r["query"]["path"] == ["/leaf"] for r in cross_site_loop["reports"]))
|
||||
after = quiet(engine_dir)
|
||||
assert len(after - before) >= 1, "no new content process: before %s, after %s" % (sorted(before), sorted(after))
|
||||
assert len(after - before) >= 1, "no new process for a site: before %s, after %s" % (sorted(before), sorted(after))
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
def test_same_site_other_port_stays_in_process(page, cross_site_loop, engine_dir):
|
||||
"""Green today, the control: a frame of the page's own site adds no content process."""
|
||||
"""Green today, the control: a frame of the page's own site adds no process for a site.
|
||||
|
||||
The frame is put in the page that is already shown, not reached by a navigation of the top. A top-level
|
||||
navigation whose old document may enter the back-forward cache replaces the browsing context
|
||||
(`mReplaceBrowsingContext`, dom/ipc/ProcessIsolation.cpp), and the new one may land in another process of
|
||||
the same site (`dom.ipc.processCount.webIsolated` is 4): seen once on the e2e of #451, [10878] -> [10878,
|
||||
11208] after a.test/plain -> a.test/same-site, never in 87 local runs. That is the top's process, not the
|
||||
frame's; a frame of the page's site stays in the page's process."""
|
||||
page.goto(cross_site_loop["plain"])
|
||||
before = quiet(engine_dir)
|
||||
page.goto(cross_site_loop["same_site"], wait_until="load")
|
||||
assert wait_for(page, lambda: any(r["path"] == "/report/loaded" for r in cross_site_loop["reports"]))
|
||||
page.evaluate("(u) => { const f = document.createElement('iframe'); f.id = 's'; f.src = u;"
|
||||
" document.body.appendChild(f); }", cross_site_loop["leaf"])
|
||||
assert wait_for(page, lambda: any(r["path"] == "/report/loaded" and r["query"]["path"] == ["/leaf"]
|
||||
for r in cross_site_loop["reports"]))
|
||||
after = quiet(engine_dir)
|
||||
assert not (after - before), "a same-site frame started a process: %s" % sorted(after - before)
|
||||
assert after == before, "a same-site frame changed the processes of the sites: %s -> %s" % (sorted(before), sorted(after))
|
||||
|
||||
|
||||
# ── 3 .. 10: what the product does not do yet ──────────────────────────────────
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
"""The e2e tests that count processes count the ones that host a site, not every new content process. No browser.
|
||||
|
||||
The engine keeps preallocated content processes and starts one to refill the pool after it hands one to a site,
|
||||
whenever it gets to it. The bench counted every `-contentproc ... tab` pid, so a refill that landed between its
|
||||
two reads was "a process the same-site frame started" (test_same_site_other_port_stays_in_process, red on the
|
||||
e2e of the commit of 0.50.0: `[13443]`). The processes below are the ones measured on firefox-62 (Linux):
|
||||
names and command lines as /proc gives them.
|
||||
"""
|
||||
import _processes
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
ENGINE = "/cache/firefox-62/firefox"
|
||||
DIR = "/cache/firefox-62"
|
||||
|
||||
|
||||
class _Proc:
|
||||
def __init__(self, pid, name, kind, exe=ENGINE):
|
||||
self.pid, self._name, self._exe = pid, name, exe
|
||||
self._cmd = [exe, "-contentproc", "-isForBrowser", "-prefsLen", "1", "-parentBuildID", "20261111073531",
|
||||
"-appDir", DIR + "/browser", str(pid), kind]
|
||||
|
||||
def exe(self):
|
||||
return self._exe
|
||||
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
def cmdline(self):
|
||||
return self._cmd
|
||||
|
||||
|
||||
def _engine_at_plain():
|
||||
"""a.test/plain shown: one process for the site, three preallocated, and the engine's other children."""
|
||||
return [_Proc(184, "Socket Process", "socket"), _Proc(200, "WebExtensions", "tab"),
|
||||
_Proc(334, "Isolated Web Co", "tab"), _Proc(377, "Privileged Cont", "tab"),
|
||||
_Proc(433, "Web Content", "tab"), _Proc(438, "Web Content", "tab"), _Proc(460, "Web Content", "tab")]
|
||||
|
||||
|
||||
def test_a_preallocated_process_that_arrives_is_not_a_site():
|
||||
before = _processes.site_pids(_engine_at_plain(), DIR)
|
||||
after = _processes.site_pids(_engine_at_plain() + [_Proc(549, "Web Content", "tab")], DIR)
|
||||
assert before == after == {334}
|
||||
|
||||
|
||||
def test_a_preallocated_process_given_to_a_site_is_a_new_site_process():
|
||||
"""A cross-site frame: 433 leaves the pool for b.test (and is renamed), 549 refills the pool."""
|
||||
procs = [p for p in _engine_at_plain() if p.pid != 433]
|
||||
procs += [_Proc(433, "Isolated Web Co", "tab"), _Proc(549, "Web Content", "tab")]
|
||||
assert _processes.site_pids(procs, DIR) - _processes.site_pids(_engine_at_plain(), DIR) == {433}
|
||||
|
||||
|
||||
def test_a_process_of_another_firefox_is_not_counted():
|
||||
other = _Proc(900, "Isolated Web Co", "tab", exe="/usr/lib/firefox/firefox")
|
||||
assert _processes.site_pids(_engine_at_plain() + [other], DIR) == {334}
|
||||
|
||||
|
||||
def test_the_pool_refilled_behind_a_closed_context_is_not_a_process_left():
|
||||
"""After the fourth closed context of test_a_context_that_ends_leaves_no_process_e2e, as measured: three
|
||||
preallocated processes and no site. Counting every content process said 5 ([2, 2, 2, 5, 5])."""
|
||||
left = [_Proc(1219, "WebExtensions", "tab"), _Proc(1382, "Privileged Cont", "tab"),
|
||||
_Proc(1739, "Web Content", "tab"), _Proc(1744, "Web Content", "tab"), _Proc(1821, "Web Content", "tab")]
|
||||
assert _processes.site_pids(left) == set()
|
||||
assert _processes.site_pids(left + [_Proc(1900, "Isolated Web Co", "tab")]) == {1900}
|
||||
Reference in new issue
Block a user