* docs: the agent links and the command name the repo as it is now Two things were broken for a reader on main, not one. Thirteen links pointed at github.com/feder-cr/AIHawk. GitHub redirects a NAME to the OBJECT that carried it, not to the content: after the September swaps that name belongs to invisible_dots, which has seven wiki pages, so AIHawk/wiki/<page> lands on its wiki Home. It answers 200 with different content, which means a reader who clicks does not find the page and a search engine sees a soft-404 across about 150 indexed URLs. Seven occurrences said `uvx aihawk`, a command that does not exist. One sat in a front-matter description, which is the snippet search engines show, and one in a block meant to be copied: `claude mcp add stealth -- uvx aihawk`. The command is invisible-playwright-mcp, on PyPI at 0.70.16. All eight link targets were checked one by one and resolve to themselves with the page title, no redirect. Three things stay as they are, which only reading them showed. The `pip install invisible-playwright` line matches what this engine's own README teaches for the library, so the page is consistent rather than broken. CHANGELOG.md keeps the old name because a changelog entry says what was true then. And the fixture in scripts/sync_article_pixels.py keeps it because it is the deliberate wrong case, a pixel for ANOTHER repo. One sentence went away instead of being renamed: "shipped inside AIHawk" made sense when AIHawk was the larger product containing the server. The server and the repository are now the same thing, so "shipped inside itself" was circular. (cherry picked from commitd9c8e46dce) * test: the docs name the MCP server's repository and command as they are now feder-cr/AIHawk now leads to an unrelated repository and answers 200, which no link checker reports; `uvx aihawk` does not exist. The README and docs/ are read for both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * tests: the Fission bench counts the processes that host a site, not every new content process test_same_site_other_port_stays_in_process was red on the e2e of the 0.50.0 commit ("a same-site frame started a process: [13443]"): the bench counted every `-contentproc ... tab` pid, and the engine starts a preallocated content process to refill its pool whenever it gets to it. On Linux the engine names a content process by its remote type (ContentChild::SetProcessName, prctl PR_SET_NAME): "Isolated Web Co" once it hosts a site of strategy 1, "Web Content" while preallocated. Measured on firefox-62: a cross-site frame renames a preallocated process and a new "Web Content" refills the pool; a same-site frame changes neither. The two tests that count processes skip off Linux, where no process carries a name. Unit test with the measured processes: 3 red on the old bench, 3 green here. e2e on firefox-62 (candidate #6, Linux): the bench file 17 passed; the two counting tests 15 of 15 runs green. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * tests: a closed context is checked for the processes of its sites, not for every content process test_closed_contexts_with_a_never_stopping_service_worker_leave_no_process was red on the e2e of the 0.50.0 tag ([2, 2, 2, 5, 5], 5 <= 2). Measured on firefox-62 (Linux), the test's own scenario 10 times with every process named: no "Isolated Web Co" left after any close; the 3 more are "Web Content", the engine's pool of preallocated processes filling up behind the closed contexts (5 runs of 10, new pids each time). Not a leak: the count read the refill. The helper of the bench moves to tests/_processes.py and both tests use it. The context test counts the processes that host a site: at least one while the page is open (or the count proves nothing), none a few seconds after `close` answers (the engine waits for them inside close and kills the ones that stay). Off Linux it skips, as the bench's two counting tests do: no other system names the process. Unit tests (tests/unit/test_processes_counts_sites.py) from the measured processes, the closed-context case included. e2e on firefox-62 (candidate #6, Linux): the context test 10 of 10; run_e2e.py on the two files and the unit test 18 passed. The old counter, same scenario: 5 of 10 runs would fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Release 0.50.1: 0.50.0 with the process-counting e2e corrected (0.50.0 never reached the index) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * tests: the same-site control puts its frame in the shown page; CHANGELOG: 0.50.0's entry is 0.50.1's The e2e of #451 saw a new "Isolated Web Co" once after a.test/plain -> a.test/same-site ([10878] -> [10878, 11208]). Not a process of an earlier test: it was created after the first read and only this worker's descendants are counted. It is the top-level navigation: when the old document may enter the back-forward cache, the browsing context is replaced (mReplaceBrowsingContext, dom/ipc/ProcessIsolation.cpp) and the new one may be placed in another process of the same site (dom.ipc.processCount.webIsolated = 4). Measured on firefox-62 (candidate #6, Linux): 0 of 30 runs alone (bfcache on and off), 0 of 57 under 4 workers. The test was written for the frame, so the frame is now added to the page already shown and the top never navigates: 20 of 20 runs green. 0.50.0 never reached the index, so the changelog gate refused its heading; its entry now opens 0.50.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * tests: networkidle through a served browser whose context routes every request, on a reused page launch_server() plus a stock Playwright client, a context route that aborts image/font/media and continues the rest, a page with sendBeacon, the same font twice, a frame of another site, a worker, redirects, requests the page cancels while a slow route decides, 100 requests at once, and a slow client that answers concurrently (async). Every shape reaches networkidle on firefox-62; one page reused for twelve addresses too. The leak that tf-fetch meets on real sites needs end events the engine loses, which no local page produces: its deterministic red/green is in the core (tests/test_networkidle_on_a_reused_page.py of invisible-core); this file guards the remote path end to end. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> (cherry picked from commit 47182f0cd85fea08fc45e36f1c91d2d570722f14) (cherry picked from commit e46f2dcf3eb361e6af0fedcdf6e1189f0ac330b6) * server: the answer to a request the browser has already closed is not an error (Cannot find request), as stock sendMayFail A page cancels requests while a route is deciding (a fetch aborted, an image replaced, an iframe removed, a beacon with its document, the favicon of the page a goto just left). The engine takes the request out of its held set at once and the late continue/abort/fulfill meets "Cannot find request" or NS_BINDING_ABORTED. Stock Playwright sends the interception commands as may-fail and tells the client nothing; ours passed the error up, the client kept it as the error of the whole connection and raised it on the NEXT route command, which was then never sent: its request stayed held in the engine, its handler failed too, and so on down the page. Seen on a real news page: six held requests in a row, one a beacon, and networkidle never came. RouteDispatcher._send now treats "Cannot find request" and a closed target as done (still disposed); any other protocol error still reaches the client. Tests: the e2e with a plain handler (no try) on a page that removes an iframe whose requests are held (red before: networkidle never; green after), and a static guard that every op of RouteDispatcher goes through _send and that _send swallows exactly those two. The same defect was found a month earlier by richardpowellus (#351), with the favicon of the previous page: his test is added in the next commit. Co-authored-by: Richard Powell <1369873+richardpowellus@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * tests: the stock Playwright client is required by the networkidle e2e (explicit failure, never a skip); the dev extra pins it Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> (cherry picked from commit 91223226f5bba25edff9af0e8b1fd6b5bfea2227) (cherry picked from commit 612b18c02b95e9b5833d62b6595d4a0ff324aac2) * tests: answering a route the next navigation already aborted does not raise (the case of #351: the favicon of the page just left) Sixty sequential routed gotos on a loopback page: 4-12 of them failed on the old server, every failing continue_ being the previous document's favicon, aborted by the next navigation while the route sat with the handler. Red on main (in-process path), green with the fix of RouteDispatcher._send. Co-authored-by: Richard Powell <1369873+richardpowellus@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * Release 0.50.1: pin invisible-core 62.64.0; CHANGELOG for the networkidle fixes Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> (cherry picked from commit e63ef8e61ea42e7f8df7c1bde206f3bf86fc18f7) * A route answer the engine refuses is the engine's business, whatever its wording The server took one wording ("Cannot find request") of an answer to a closed request as done and passed every other protocol error up to the client. The engine also says "NS_BINDING_ABORTED [nsIInterceptedChannel.resetInterceptionWithURI]" when the channel was cancelled while the answer was on its way: the same event, and the client kept it as the error of the connection and raised it on its next route command. Stock Playwright sends the three interception commands as may-fail and tells the client nothing, whatever the engine says. So does RouteDispatcher._send now: every ProtocolError is swallowed, the route is disposed after it. Tests: the static guard no longer allows a re-raise inside the handlers; a unit test feeds three wordings (red on the old code for two of them). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * tests: the descriptors of the spawn are asserted by running it, not by reading the core's source test_the_spawn_keeps_the_two_hardwired_descriptors asserted that the source of the core's _spawn_posix contains `pass_fds=(its_read, its_write, 3, 4)`. Core 62.64.0 starts the engine with posix_spawn and file actions, so the words are gone and the test failed on every Linux unit suite although the behaviour is the same (and better). The test now runs the spawn: a parent with nothing open on 3 and 4 and its pipes far from them launches a program that reads fd 3 and answers on fd 4 (the contract of nsRemoteDebuggingPipe.cpp), and the answer must come back and the child must hold no descriptor above 4 of the parent's. Same shape as the core's own test (test_the_pipe_of_the_engine_reaches_its_fixed_descriptors). No skip: the file is already POSIX-only. The other tests of the file do not read source text (checked: no getsource/inspect/read_text left). Ran the parent program on Linux with core 62.64.0 (image tetra-invisible:run1b-final): pong:ping:0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * The page dispatcher waits for Page.ready before the page is handed over (needs invisible-core with Lifecycle.wait_for_page_ready) Same defect and fix as in the core's page (see the core commit): a goto sent right after new_page could meet the page's initial about:blank. The pin of invisible-core moves with the core release that carries wait_for_page_ready. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * Pin invisible-core==62.65.0 (a page handed over when the engine says it is ready); changelog The core that carries Lifecycle.wait_for_page_ready is invisible-core 62.65.0 (draft PR invisible_core#238), not on the index yet: the pin check of this push is skipped on purpose (INVISIBLE_PIN_CHECK=skip). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * tests: the stand-in engine of the registry test says Page.ready, as the real one does (the page is handed over on it) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * tests: new_page and a popup are handed over only when the engine says Page.ready (red without the wait in PageDispatcher, green with it) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * A page is built at once and announced when the engine says Page.ready (the wait inside the constructor held a popup's first request behind a page that did not exist yet, and lost its commit and load) - PageDispatcher no longer waits in __init__; wait_until_ready() is called by the adoption between the construction and the announcement (context 'page' event, newPage answer). A detach while waiting ends the wait; a page that is not ready in time is disposed. - The main frame's initializer carries what the lifecycle already knows (url, name, load states), as every other frame's does. - Tests: unit (a popup exists and listens while it waits; what it does before its ready reaches its frame; red on6a60dce) and e2e (a popup of a link, noopener or window.open reaches an in-process and a stock client of a served browser within 2 s, with and without a context route; 15 of 16 red on6a60dce, 16 green). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * tests: the stand-in pages say wait_until_ready; the popup e2e reaches the stock client as the other served tests do Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * tests: the popup reaches the client from another site too (a link, noopener, window.open: 16 more cases, in-process and through a served browser) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * A popup is reported on Page.ready as Playwright's is: no limit and no warning, with the address of the commit that came with the ready - Stock Playwright 1.62 (measured): a 204 or a silent destination gives no page event, one that answers after 4 s gives it at 4 s with the destination already. The adoption of a popup waited 20 s and dropped it with a warning; now only a page a caller asked for (newPage) has the 20 s; a popup waits until the engine says Page.ready, the target goes away, or its context closes (BrowserDispatcher.end_waits_of), and says nothing. - The ready and the commit of the document that made the page ready come in the same turn: the page is announced after a round trip to the engine (settle_events), so the frame reads the destination at the page event (3 of 4 slow popups said about:blank). - In-process the slow popup arrived 0.9 s later than stock: it is the humanised click (1.1 s of pointer movement before the click returns), the popup arrives 4.02 s after the click in both modes. - Tests: unit (limit None for a popup and 20 s for a requested page; a popup with no ready ends with its context and says nothing; the address at the page event is the commit's) red on b09d620; e2e (204 and silent: no event; 1.5 s: url is the destination; 25 s: reported then) in-process and through a served browser: the 25 s ones red onb09d620. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * A download started by a popup that is not announced yet is reported on its opener, as Playwright reports it - Browser.downloadCreated names the tab the download came from. A tab opened for an attachment (a target=_blank link, a window.open) never gets a Page.ready and the engine closes it at once, so it is not among the announced pages and the download was lost: no download event anywhere (a21e1dehad it, on the popup). Playwright's ffBrowser._onDownloadCreated reports it on the opener of a page that is not reported yet; so does this, from the opener recorded when the target was attached (BrowserDispatcher._openers). The abort of the navigation that became the download still goes to the page that owns the frame. - Tests: unit (red onfbceeaf); the e2e of the destinations and of the popup matrix of the fake-web branch (73f1e8d): 16 + 34 cases against the reference measured on stock Playwright 1.62 - onfbceeaf4 of the 16 were red (the download), now 50 of 50 green. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * A popup tells its listeners the load it reached before it was announced; an unannounced frame has no address of its own - The popup is announced when the engine says Page.ready, which is when its document commits, so its domcontentloaded and load may be said before the client has the page: page.on('load') registered in the handler of the page event never fired (Playwright's does, measured by the independent run: destinations of 4 s and 25 s). FrameDispatcher.emit records those two states while the page is not announced and PageDispatcher.announce says them again right after the page event, in their order and under one lock; the first time they already set the state wait_for_load_state reads, so it returns at once. Only popups: a requested page is announced as before. - The main frame is created with the address the lifecycle knows, '' if it has committed nothing (an attachment's empty tab), not about:blank: Playwright says '' there. - Tests: unit (the two states after the page event, in order; red on2f153c7); e2e: a listener registered in the handler of the page event hears the load of a slow popup, wait_for_load_state in the handler returns in under 2 s (in-process and a stock client over a served browser, window.open and link). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * A popup whose target goes away while its page is being built is announced and closed, not waited for for ever A download's empty tab is closed by the engine within milliseconds; on a loaded machine its page is still being built when the detach arrives. _handle_detach recorded it as early (nobody in _building to tell) and the adoption then waited for a Page.ready that never comes: the popup was never announced (test_popup_destinations_e2e, the download on the opener, failed once in a full suite run). The adoption now looks at the early detaches when it registers the page as waiting. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * A command of the adoption that finds the target's session gone announces and closes the popup, as a detach before the ready does The independent run on a quiet machine lost one link-into-attachment popup in a hundred: the engine closed the tab WHILE the adoption was initializing it, answered 'cannot find session' to Page.setInitScripts, and the popup was discarded with a warning - no page event - where Playwright's is announced and closed. PageDispatcher._build now treats an initialization command that fails because the target or its session is gone (one test: _target_is_gone) as the same case: the page is built, flagged gone_while_building, and the adoption announces it and closes it right after. Test: a fake engine answers 'cannot find session' to each command of the adoption in turn (parametrised): the page event and the close arrive, no warning; red onb05741ffor Page.setInitScripts. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * tests: the helper of the popup destinations does not shadow the browser fixture (ruff F811) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * tests: the popup tests do not fail on the machine's speed (no 2 s limit) A runner with four workers delivered a popup in 2.013 s (the limit of the test was 2 s). The verdict of these tests is that the popup arrives with its address and its load; the wait is generous (30 s) and the check of the time is gone. The wait_for_load_state of the handler is bounded by 8 s. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * The adoption of a target is one explicit state machine, proved over every order of the engine's events Four patches of the same race (a detach before the ready, during the build, between the build and the wait, a command answered 'cannot find session') and a fifth the exhaustive test found (a detach while the adoption waits for the main frame of a tab the engine never announced: the wait went on for 20 s and the popup was discarded; this is the order the runner produced for the download popups: 3 of 4 lost). - _Adoption: the single record of a target between its attach and its announcement: state (attached, building, waiting, announced), gone (set by the engine's detach AT ANY MOMENT), page, opener, context. It replaces _adopting, _building, _openers and _detached_early. - Every wait of the adoption looks at gone (the main-frame wait polls it), every state change is one method (_enter_building, _enter_waiting, _enter_announced), a command that finds the session gone ends in the same place as a detach, a closing context takes away every adoption of it in any state (end_waits_of). - Invariant: an attached target that is not a page a caller asked for gives the client exactly one page event, at its ready or at its disappearance (and its close right after), unless its context closed first. - Test: test_every_order_of_the_events_of_a_popup_gives_one_page_event stops the adoption thread at six points of its own and delivers the engine's events (frame, commit, ready, detach, in every prefix) at every one of the eight moments: 635 orders, none sampled. Mutation check: without the gone-aware main-frame wait 24 orders break, without the tolerance of the command error 42, without the close after the page 374; without the early-gone check of _enter_waiting the adoption hangs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * The adoption keeps a short trace per target and writes it where a popup is dropped or fails The log of a CI run says that a popup was not announced and not in which order the engine's events came. Each target in flight keeps (in memory, at most 60 short strings, nothing afterwards) what the engine said (frame, commit, ready, detach) and what the adoption did (building, waiting, announced), with the milliseconds since the attach. It is written in the warning of a failed adoption, in the error the newPage waiter gets, in the timeout of a requested page, and in browser._dropped (the last 16 targets dropped with their context). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * The WebGL determinism test says why the browser could not make a context One run in 31 of the e2e on a loaded Linux runner failed this test with "reason='gl null'" and nothing else: getContext('webgl') gave the page null. The browser says why in the `webglcontextcreationerror` event (statusMessage: the failure list, e.g. "tryNativeGL (FEATURE_FAILURE_EGL_LOAD_3)", "Initializing WebGL backbuffer failed.", "GL error 0x505 occurred during OpenGL context initialization"), and each of the paths that can produce null on Linux in our engine writes a different one (library not loaded, display not initialised, context not created, GL out of memory, backbuffer not allocated). The test reads the event and puts it in the assertion, and tries webgl2 on a fresh canvas (the old canvas already had the failed type). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * tests: the same-site control of the Fission bench measures the frame, not the process pool The control counted the processes that host a site between two reads, with the default pool of three preallocated content processes: a pool process handed to a site after the first read moved the count without the frame having asked for anything ([63248] -> [63248, 63386] on a four-worker runner; the same family as5402da4,ff2123eandfef0bc5). The control now runs in a browser with dom.ipc.processPrelaunch.fission.number at 0, where a process of a site appears only because a site needed one, and says so if the page of the site has no process to compare with. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * The download of a tab that is not announced yet is said after the page event of the tab The tab opened for an attachment is announced when the engine takes it away, a few milliseconds after it says the download; the download (reported on the opener) went to the client first, the popup after: the order the other way round from Playwright's, and a client that read the popup the moment the download arrived found none on a one-CPU machine (the 4 download cases of GitHub, 3 of 4 red; the same on a one-CPU container: 1, 0, 2 of 50 ona90dadc). The adoption holds the download on its record and says it right after the page event (never lost: also when the tab is dropped or fails). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * A download is taken with the record's removal in one step, and the opener of a target not announced is remembered: no step of the adoption can lose it The failure branch said the pending downloads BEFORE it removed the record: a download created between the two found the record, queued on it, and nobody said it. Taking the pending downloads and removing the record are now one step under the browser's lock, in the three branches (announced, dropped with its context, failed); the opener of a target that ended without being announced is kept for the last 16 targets, so a download that comes after the record is gone is still said, on the opener. Test: the download is forced into the gap of the failing adoption (red on65f7580: said 0 times, now once). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Richard Powell <1369873+richardpowellus@users.noreply.github.com>
102 lines
4.9 KiB
Python
102 lines
4.9 KiB
Python
"""Every route command (continue, abort, fulfill, redirect) leaves through `RouteDispatcher._send`, and `_send` swallows the one
|
|
error that is not an error: the request the browser has already closed.
|
|
|
|
Stock Playwright's server sends the three interception commands as may-fail. Here a new command that talked to the page
|
|
directly (`self.request.page.send("Network....")`) would bring the old defect back: the client keeps an error for the whole
|
|
connection and raises it on the next route command, which is then never sent (see
|
|
`test_networkidle_through_a_served_browser_with_routes_e2e.py`). No browser: the source is read.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import ast
|
|
import pathlib
|
|
|
|
import pytest
|
|
|
|
pytestmark = pytest.mark.unit
|
|
|
|
SERVER = pathlib.Path(__file__).resolve().parents[1] / "src" / "invisible_playwright" / "_juggler" / "server.py"
|
|
|
|
|
|
def _route_dispatcher():
|
|
tree = ast.parse(SERVER.read_text(encoding="utf-8"))
|
|
return next(n for n in tree.body if isinstance(n, ast.ClassDef) and n.name == "RouteDispatcher")
|
|
|
|
|
|
def _methods(cls):
|
|
return {n.name: n for n in cls.body if isinstance(n, ast.FunctionDef)}
|
|
|
|
|
|
def _sends_network_command(fn):
|
|
"""The `page.send` / `conn.send` / `_send` calls of a function that name a Network.* command string."""
|
|
out = []
|
|
for node in ast.walk(fn):
|
|
if isinstance(node, ast.Call):
|
|
for arg in node.args[:1]:
|
|
if isinstance(arg, ast.Constant) and isinstance(arg.value, str) and arg.value.startswith("Network."):
|
|
out.append((getattr(node.func, "attr", getattr(node.func, "id", "?")), arg.value))
|
|
return out
|
|
|
|
|
|
def test_every_op_of_a_route_goes_through__send_and_nothing_else_talks_to_the_page():
|
|
methods = _methods(_route_dispatcher())
|
|
ops = {name: fn for name, fn in methods.items() if name.startswith("op_")}
|
|
assert set(ops) >= {"op_abort", "op_continue", "op_fulfill", "op_redirect"}, sorted(ops)
|
|
for name, fn in ops.items():
|
|
sends = _sends_network_command(fn)
|
|
assert sends, "%s sends no Network command at all: update this guard if it is a new kind" % name
|
|
for via, command in sends:
|
|
assert via == "_send", "%s sends %s through %s, not through RouteDispatcher._send" % (name, command, via)
|
|
# and the only direct talk to the page in the class is _send's
|
|
for name, fn in methods.items():
|
|
if name in ops or name == "_send":
|
|
continue
|
|
assert not _sends_network_command(fn), "%s sends a Network command by itself" % name
|
|
|
|
|
|
def test__send_answers_every_protocol_error_of_a_route_command_as_may_fail():
|
|
"""Stock's `sendMayFail`: whatever the engine says about a request the page already closed ("Cannot find request",
|
|
"NS_BINDING_ABORTED [nsIInterceptedChannel.resetInterceptionWithURI]", the next wording) is not the client's error."""
|
|
send = _methods(_route_dispatcher())["_send"]
|
|
handlers = [n for n in ast.walk(send) if isinstance(n, ast.ExceptHandler)]
|
|
caught = {ast.unparse(h.type) for h in handlers if h.type is not None}
|
|
assert caught == {"juggler.ProtocolError", "juggler.TargetClosedError"}, caught
|
|
assert not any(isinstance(n, ast.Raise) for h in handlers for n in ast.walk(h)), \
|
|
"an error of a route command must never reach the client: it would be raised on its NEXT route command"
|
|
source = ast.get_source_segment(SERVER.read_text(encoding="utf-8"), send)
|
|
assert source.index("self.dispose()") > source.index("except juggler.TargetClosedError"), \
|
|
"the route is disposed after a swallowed error too"
|
|
|
|
|
|
@pytest.mark.parametrize("message", [
|
|
'Network.resumeInterceptedRequest: Cannot find request "123"',
|
|
"Network.resumeInterceptedRequest: Component returned failure code: 0x804b0002 (NS_BINDING_ABORTED) "
|
|
"[nsIInterceptedChannel.resetInterceptionWithURI]",
|
|
"Network.abortInterceptedRequest: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)",
|
|
])
|
|
def test_a_protocol_error_from_the_engine_is_not_the_clients_error(message):
|
|
from invisible_playwright._juggler import server as srv
|
|
|
|
class Page:
|
|
def send(self, command, params):
|
|
raise srv.juggler.ProtocolError(message)
|
|
|
|
class Request:
|
|
page = Page()
|
|
request_id = "r1"
|
|
|
|
route = object.__new__(srv.RouteDispatcher)
|
|
route.request, route.answered, route.dispose = Request(), False, lambda: None
|
|
assert route._send("Network.resumeInterceptedRequest", {}) is None
|
|
|
|
|
|
def test_the_stock_client_the_networkidle_e2e_drives_the_server_with_is_a_pinned_dev_dependency():
|
|
"""That e2e fails (not skips) without the stock Playwright client, so CI must install it: the `dev` extra pins it to the
|
|
version of scripts/playwright_pin.txt."""
|
|
import tomllib
|
|
|
|
root = SERVER.parents[3]
|
|
dev = tomllib.loads((root / "pyproject.toml").read_text(encoding="utf-8"))["project"]["optional-dependencies"]["dev"]
|
|
pin = (root / "scripts" / "playwright_pin.txt").read_text(encoding="utf-8").strip()
|
|
assert "playwright==%s" % pin in dev, dev
|