0.37.0: the pin moves to invisible-core 49.44.0, on the firefox-49 engine (#363)

The pin moves to invisible-core 49.44.0, on the firefox-49 engine.

With it: your code's evaluate runs in a world of its own; the favicon no longer reaches routes or events; route.abort() with no code fails like Playwright's; a route that sends a navigation elsewhere lands there; a held request released after interception went off no longer stalls the browser; request.post_data is the body without a route; and the response names its certificate and its service worker.

Measured on the firefox-49 candidate: the full e2e and Playwright's own suite against the recorded reference, no regression. tests/gates/upstream_baseline.json is recorded again with a cause per entry; one correction to its commit message: test_scroll is pinned failed because of a scroll position two worlds read differently after scrollTo, not because of test order.
This commit is contained in:
Federico Elia authored and GitHub committed 2026-10-17 13:19:57 +02:00
1 parent 0433b18aa7
commit 0dd99b7638
16 files changed
+995 -235

No files matched your search

+63
View File
@@ -6,6 +6,69 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
## [Unreleased]
## [0.37.0] - 2026-10-17
The pin moves to invisible-core 49.44.0, on the firefox-49 engine.
### Changed
- **Your code runs in a world of its own, where a page that replaced a
standard API cannot count your calls.** `evaluate`, `evaluate_handle`,
`wait_for_function`, `eval_on_selector(_all)`, `locator.evaluate`,
`handle.evaluate` and `set_content` ran in the page's own realm, so a
call to `document.querySelector` went through whatever the page had
put in its place: a Cloudflare challenge wraps it, and one lookup of
its token field from an evaluate got the clearance refused. They now
run in a world with the page's principal where a name the standard
defines is the native one, and every other name is the page's:
`window.__NEXT_DATA__`, a node's `__vue__` and the page's functions
answer as before.
On what the page created (its classes, their instances, its plain objects)
the page's definitions win, `toString` and `valueOf` included, and an
object your code hands to the page keeps its identity and looks to the
page like its own (`instanceof Array` holds, its `constructor` is the
page's). What changes, and it is declared rather than accidental: a name
the standard defines for one of the browser's own objects wins even where
the page redefined it on that object itself (a setter the page put on one
input's `value` does not run; `.wrappedJSObject` gives the page's own
view); a bare assignment to an undeclared name creates a global of your
world, not of the page (`window.x = 1` still reaches the page); and your
code's own `eval` is not governed by the page's Content-Security-Policy,
which governs the page's (`window.eval`) as before. Needs firefox-49.
- **`request.post_data` holds the body with no route as well.** Until
firefox-48 the engine read a request's body only while a route was set, so
every POST of a page with no route answered `None`, like a form sent empty.
It now reads every body up to 10 MB, as Playwright's does, and the upload
reaches the site whole. Needs firefox-49.
- **`response.security_details()` names the certificate, and
`response.from_service_worker` says when a service worker answered.**
The engine reported neither (`None` and `False` for every response); it now
reports both as Playwright's does. Needs firefox-49.
### Fixed
- **`eval_on_selector`, `eval_on_selector_all`, `locator.evaluate` and
`handle.evaluate` see what the page put on an element.** They ran
behind the automation's own view, where `el.__vue__` and the methods
of a custom element's class do not exist.
- **The browser's favicon request no longer reaches the client.** A
`page.route("**/*")` handler saw `GET /favicon.ico` now and then, as did the
`request`, `response` and `requestfinished` listeners, and a
`route.fallback(post_data=...)` rewrote it too. As in Playwright, the favicon,
and a request it redirects to, now sends no event, reaches no route handler
and is not a request `networkidle` waits on. Unlike Playwright it is not
aborted under a route: it goes to the site, as from any Firefox.
- **A request held after interception was switched off no longer stalls the
session.** Its release was sent from the thread that delivers the engine's
events and waited for a reply only that thread could read; the next command
of the page then waited forever.
- **`route.abort()` with no error code fails the request with
`NS_ERROR_FAILURE`, as in Playwright on Firefox.** It failed with
`NS_ERROR_ABORT`, the code of `route.abort("aborted")`.
- **A route that sends a navigation to another URL lands there.**
`route.fallback(url=...)` or `route.continue_(url=...)` on a document
request made `goto` fail with "reported committed on ..., which is not where
it went", and the response kept the URL the request was sent with. The
response is now the routed URL's, and `goto` lands on it.
## [0.36.2] - 2026-10-17
The pin moves to invisible-core 48.43.0, still on the firefox-48 engine.
+2 -2
View File
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "invisible_playwright"
version = "0.36.2"
version = "0.37.0"
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==48.43.0",
"invisible_core==49.44.0",
# ⛔ playwright is NO LONGER a dependency: since the full fork, the Python
# client lives in src/invisible_playwright/_pw/ and the Node driver in
# src/invisible_playwright/_driver/. Reintroducing it would not visibly
@@ -75,15 +75,16 @@ def _invocation(expression: str, argument: Any, *receivers: str) -> str:
"""The statements that evaluate the caller's expression and, when it is a
function, call it with `receivers` first and the argument last.
<M> THE ONLY PLACE THAT SPELLS THE CALL. The main-world wrapper above and
<M> THE ONLY PLACE THAT SPELLS THE CALL. The caller's-world wrapper above and
the three element-scoped ones (`handle.evaluate`, `eval_on_selector`,
`eval_on_selector_all`) used to write it out each on its own, and that is
how the argument reached `handle.evaluate` and was dropped by the other
two: a callback reading its second parameter got `undefined` there.
The main-world output is pinned byte for byte by
`test_the_argument_does_not_rewrite_the_expression.py`, because that one
runs as the page.
That wrapper's output is pinned byte for byte by
`test_the_argument_does_not_rewrite_the_expression.py`, because the page
can read it: a function the caller hands to the page shows its source to
the page's toString.
"""
return ("const r = (%s); return typeof r === 'function' ? r(%s) : r;"
% (expression,
@@ -100,7 +101,8 @@ def _called_on(params: Dict, receiver: str) -> str:
def _element_function(params: Dict) -> str:
"""The declaration `handle.evaluate` and `eval_on_selector` both send: one
element, then the argument. Both run in the utility world."""
element, then the argument. Both run in the caller's world
(`FrameDispatcher._call_on_elements`)."""
return "(injected, el) => { %s }" % _called_on(params, "el")
+192 -98
View File
@@ -349,15 +349,15 @@ class ElementHandleDispatcher(Dispatcher):
remote: Optional[Dict] = None) -> None:
self.frame = frame
self.object_id = object_id
# A main-world PRIMITIVE has no objectId: its value is the engine's
# A caller-world PRIMITIVE has no objectId: its value is the engine's
# RemoteObject, kept here so `json_value` can answer it [B324].
self.remote = remote or {}
# ⛔ WHICH WORLD THE objectId BELONGS TO, and every operation below
# runs there. Almost every handle is born in the utility world, where
# the rest of this server lives. A value the CALLER'S code produced in
# the page's own world is made into a handle by
# `FrameDispatcher._handle_from_main`: a node is adopted into utility,
# anything else stays "main". An objectId is not portable between
# its own world is made into a handle by
# `FrameDispatcher._handle_from_caller`: a node is adopted into
# utility, anything else stays "caller". An objectId is not portable between
# worlds, and until 0.36.0 only `json_value` read this field: every
# other operation on an `evaluate_handle` or `wait_for_function` result
# asked the utility world about an objectId it had never seen and
@@ -391,20 +391,20 @@ class ElementHandleDispatcher(Dispatcher):
def page(self) -> "PageDispatcher":
return self.frame.page
def _in_main(self, declaration: str, *args: Dict, by_value: bool) -> Dict:
"""`declaration` called in the main world, where this handle lives,
with `null` where the utility world passes the injected script: the
same declarations serve both worlds, so there is one of each."""
def _in_caller(self, declaration: str, *args: Dict, by_value: bool) -> Dict:
"""`declaration` called in the caller's world, where this handle
lives, with `null` where the utility world passes the injected script:
the same declarations serve both worlds, so there is one of each."""
return self.injected.call_raw(
self.injected.main_context(self.frame.frame_id), declaration,
self.injected.caller_context(self.frame.frame_id), declaration,
[{"value": None}, {"objectId": self.object_id}] + list(args),
by_value=by_value)
def op_dispose(self, params: Dict) -> Any:
if self.world == "main":
if self.world == "caller":
if self.object_id:
self.injected.release(
self.injected.main_context(self.frame.frame_id), self.object_id)
self.injected.caller_context(self.frame.frame_id), self.object_id)
self.dispose()
return None
try:
@@ -460,12 +460,11 @@ class ElementHandleDispatcher(Dispatcher):
It was found by diffing the protocol against the Node driver: the
driver's `click` carried a `position` and ours did not.
"""
if self.world == "main":
return {"value": _serialize(self._in_main(
_element_function(params), by_value=True).get("value"))}
return {"value": _serialize(self.injected.call(
self.frame.frame_id, _element_function(params),
{"objectId": self.object_id}))}
if self.world == "caller":
return {"value": _serialize(_remote_value(self._in_caller(
_element_function(params), by_value=True)))}
return {"value": _serialize(self.frame._call_on_elements(
self.frame.frame_id, [self.object_id], _element_function(params)))}
def op_text_content(self, params: Dict) -> Any:
return {"value": self.injected.text_content(
@@ -488,10 +487,10 @@ class ElementHandleDispatcher(Dispatcher):
self.frame.frame_id, self.object_id, params["name"])}
def op_get_property(self, params: Dict) -> Any:
if self.world == "main":
remote = self._in_main("(injected, o, n) => o[n]",
if self.world == "caller":
remote = self._in_caller("(injected, o, n) => o[n]",
{"value": params["name"]}, by_value=False)
return {"handle": self.frame._handle_from_main(remote).channel}
return {"handle": self.frame._handle_from_caller(remote).channel}
object_id = self.injected.call(
self.frame.frame_id,
"(injected, o, n) => o[n]",
@@ -504,12 +503,12 @@ class ElementHandleDispatcher(Dispatcher):
large object this is the most expensive call in the file, which is why
`json_value` exists and should be preferred when the values are
serialisable."""
if self.world == "main":
names = self._in_main(
if self.world == "caller":
names = self._in_caller(
"(injected, o) => o === Object(o) ? Object.keys(o) : []",
by_value=True).get("value") or []
return {"properties": [
{"name": name, "value": self.frame._handle_from_main(self._in_main(
{"name": name, "value": self.frame._handle_from_caller(self._in_caller(
"(injected, o, n) => o[n]", {"value": name},
by_value=False)).channel}
for name in names]}
@@ -537,11 +536,11 @@ class ElementHandleDispatcher(Dispatcher):
caller can act on - it is an evaluation failure on a handle they were
just given.
"""
if self.world == "main":
if self.world == "caller":
if not self.object_id:
return {"value": _serialize(_remote_value(self.remote))}
return {"value": _serialize(self.injected.json_value_in(
self.frame.frame_id, "main", self.object_id))}
self.frame.frame_id, "caller", self.object_id))}
return {"value": _serialize(self.injected.call(
self.frame.frame_id, "(injected, o) => o",
{"objectId": self.object_id}))}
@@ -928,27 +927,34 @@ class FrameDispatcher(Dispatcher):
return self._read(params, "state", "editable")
def op_evaluate(self, params: Dict) -> Any:
"""⛔ THE PAGE'S OWN WORLD, not the utility one, and the distinction
is the semantics of the API rather than a preference.
"""⛔ THE CALLER'S WORLD, not the utility one, and the distinction is
the semantics of the API rather than a preference.
`page.evaluate()` is the user asking to run code AS THE PAGE: it must
see the page's globals, the page's prototypes, and whatever the site
has monkey-patched. The utility world sees the same DOM through an
Xray, so those are exactly what it does NOT see.
`page.evaluate()` is the user's code, and it must see what the page
added: its globals, its functions, the expandos a framework puts on
nodes. The utility world sees the same DOM through a plain Xray, so
those are exactly what it does NOT see. The caller's world (invisible-
core's `evaluate_in_caller`, [B322]) sees them, and resolves every
name the standard defines to the native definition: a site that
wrapped `querySelector` to count its callers does not see this code's
calls. Until firefox-49 this ran in the page's own realm, and a
Cloudflare challenge refused the clearance of a session whose evaluate
had looked up its token field.
The first draft ran it in utility and it was caught by the opposite
assertion to the one you would expect: a test checking that the PAGE
cannot see a closed shadow root found that it could - because the code
asking was not running as the page at all.
Everything else in this file stays in utility on purpose. This one
method leaves, because the caller asked for it.
Everything else in this file stays in utility on purpose. The
caller's code leaves it, because the caller asked for the page's
additions.
"""
# ⛔ `repeatable` comes only from the fork's `evaluate_read`, a read
# its caller declares free of effects: made again on the page that
# replaced the one it went to. Everything else is the caller's code,
# sent once ([B285]).
return {"value": _serialize(self.injected.evaluate_in_main(
return {"value": _serialize(self.injected.evaluate_in_caller(
self.frame_id, _with_argument(params),
repeatable=params.get("repeatable") is True))}
@@ -1215,14 +1221,15 @@ class FrameDispatcher(Dispatcher):
return None
def op_set_content(self, params: Dict) -> Any:
"""⛔ Goes through `document.open/write/close` in the MAIN world.
"""⛔ Goes through `document.open/write/close` in the CALLER'S world.
The utility world has an EXTENDED principal, and Gecko requires
`document.open()` to run under a principal EQUAL to the document's, so
from there it answers `The operation is insecure` every single time -
the same defect the fork already fixed inside the driver.
the same defect the fork already fixed inside the driver. The caller's
world has the page's principal.
"""
self.injected.evaluate_in_main(
self.injected.evaluate_in_caller(
self.frame_id,
"(() => { document.open(); document.write(%s); document.close(); })()"
% _js_string(params["html"]), by_value=True)
@@ -1271,35 +1278,68 @@ class FrameDispatcher(Dispatcher):
self.server, self.page.frame_for(frame_id), object_id)
return {"element": handle.channel}
def _handle_from_main(self, remote: Dict) -> "ElementHandleDispatcher":
"""A handle for a value the CALLER'S code produced in the main world.
def _call_on_elements(self, frame_id: str, elements: List[str],
declaration: str) -> Any:
"""The caller's `declaration(injected, ...elements)` in the caller's
world, on elements this server holds in the utility world. THE ONE
PLACE element-scoped caller code runs [B322].
`handle.evaluate`, `eval_on_selector` and `eval_on_selector_all` run
the caller's code as much as `evaluate` does, so they run where it
runs. Until firefox-49 they ran in the utility world, behind a plain
Xray, where what the page added to a node (`el.__vue__`, the methods
of a custom element's class) does not exist, while Playwright runs
them as the page. The elements cross with `Page.adoptNode` (the same
node, in the other world) and the copies are released after the call.
The caller's code is sent once ([B285]); finding the elements is this
package's read, made before it. `injected` is null there: the caller's
code never sees this package's script."""
context = self.injected.caller_context(frame_id)
adopted: List[str] = []
try:
for element in elements:
copy = self.injected.node_to_caller(frame_id, element)
if not copy:
raise ProtocolException("Element is not attached to the DOM")
adopted.append(copy)
return _remote_value(self.injected.call_raw(
context, declaration,
[{"value": None}] + [{"objectId": a} for a in adopted],
by_value=True))
finally:
for copy in adopted:
self.injected.release(context, copy)
def _handle_from_caller(self, remote: Dict) -> "ElementHandleDispatcher":
"""A handle for a value the CALLER'S code produced in its world.
THE ONE PLACE such a handle is made [B324].
A node is adopted into the utility world, where every element read and
action of this server runs - the same node, as `add_script_tag` and
`fileChooserOpened` hand theirs back - and its main-world objectId is
released. Any other object, and a primitive, stays in the main world,
and its handle's operations run there. Until 0.36.0 `evaluate_handle`
made every result a utility handle, and `wait_for_function` a main one
that only `json_value` honoured."""
`fileChooserOpened` hand theirs back - and its caller-world objectId is
released. Any other object, and a primitive, stays in the caller's
world, and its handle's operations run there. Until 0.36.0
`evaluate_handle` made every result a utility handle, and
`wait_for_function` one of the page's world that only `json_value`
honoured."""
object_id = remote.get("objectId")
if object_id and remote.get("subtype") == "node":
adopted = self.injected.adopt(self.frame_id, object_id)
if not adopted:
raise ProtocolException(
"the node the expression returned could not be handed back")
self.injected.release(self.injected.main_context(self.frame_id), object_id)
self.injected.release(self.injected.caller_context(self.frame_id), object_id)
return ElementHandleDispatcher(self.server, self, adopted)
return ElementHandleDispatcher(self.server, self, object_id or "",
world="main", remote=remote)
world="caller", remote=remote)
def op_wait_for_function(self, params: Dict) -> Any:
"""Poll the CALLER'S expression until it is truthy.
⛔ IN THE PAGE'S OWN WORLD, and it used to poll in the utility one.
⛔ IN THE CALLER'S WORLD, and it used to poll in the utility one.
`wait_for_function` has exactly the semantics of `evaluate`: it is the
caller asking to run THEIR code as the page. From behind the Xray a
page global does not exist, so an expression like
caller asking to run THEIR code against the page. From behind a plain
Xray a page global does not exist, so an expression like
`() => !!window.Fingerprint` is false forever and the call dies on its
own timeout naming an expression that was true in the page all along.
@@ -1308,29 +1348,28 @@ class FrameDispatcher(Dispatcher):
Nothing else in the suite waits on a page global, which is why 181 of
186 were green and the gap looked like a detector problem.
⛔ AND IT IS THE SECOND METHOD THAT LEAVES THE XRAY, on purpose and
for the same reason as `op_evaluate`: everything else in this server
stays in utility so a site cannot count our reads, and these two leave
because the caller asked for the page's own world by name. The cost is
real - a polled expression is repeated page-visible work - so the
interval stays coarse.
⛔ AND IT LEAVES THE UTILITY WORLD for the same reason as
`op_evaluate`, into the same caller's world, where the standard APIs
the predicate calls are the native ones ([B322]). What the predicate
reads of the page's own additions is still the page's, so the interval
stays coarse.
"""
deadline = Deadline(self._timeout(params))
expression = _with_argument(params)
while True:
# ⛔ A NAVIGATION DOES NOT END THE POLL. The predicate is sent once
# per turn (the page's world is never sent the caller's code twice,
# per turn (the caller's code is never sent twice,
# [B285]), and a world that went under it means the next turn asks
# the new document, as Playwright's polling survives a navigation.
# ⛔ TRUTHY AS JAVASCRIPT JUDGES IT, from ONE run by reference
# (`poll_in_main`, [B323]). This used to run the predicate by value
# (`poll_in_caller`, [B323]). This used to run the predicate by value
# and let Python judge the serialized result, so a predicate that
# returns a node - `() => document.querySelector('#x')`, the most
# common wait there is - never ended: a node serializes to nothing
# truthy. A truthy value now IS the handle, and the caller's code
# no longer runs a second time to get one.
try:
remote = self.injected.poll_in_main(self.frame_id, expression)
remote = self.injected.poll_in_caller(self.frame_id, expression)
except ContextDestroyed:
remote = None
if remote is not None:
@@ -1339,7 +1378,7 @@ class FrameDispatcher(Dispatcher):
# it is `AttributeError: 'NoneType' object has no attribute
# '_object'` raised inside the client on a call that had just
# succeeded. It stayed hidden while the poll timed out first.
return {"handle": self._handle_from_main(remote).channel}
return {"handle": self._handle_from_caller(remote).channel}
if deadline.passed():
# A TimeoutError, which the client receives as Playwright's,
# as upstream raises for this wait (until 0.34.0 a plain Error).
@@ -1567,11 +1606,11 @@ class FrameDispatcher(Dispatcher):
" (document.head || document.documentElement).appendChild(el);"
" return el; })()" % (build, _js_string(content)))
object_id = self.injected.evaluate_in_main(
object_id = self.injected.evaluate_in_caller(
self.frame_id, body, by_value=False)
# ⛔ THE TAG IS BORN IN THE MAIN WORLD AND THE HANDLE LIVES IN UTILITY.
# Every ElementHandle call goes through the utility world, where a
# main-world objectId answers `Cannot find object with id`. Adopted,
# ⛔ THE TAG IS BORN IN THE CALLER'S WORLD AND THE HANDLE LIVES IN
# UTILITY. Every ElementHandle call goes through the utility world,
# where a caller-world objectId answers `Cannot find object with id`. Adopted,
# as `fileChooserOpened` adopts its input, it is the same node.
adopted = self.injected.adopt(self.frame_id, object_id)
if not adopted:
@@ -1621,8 +1660,8 @@ class FrameDispatcher(Dispatcher):
raise ProtocolException(
"failed to find element matching selector %r" % selector)
try:
return {"value": _serialize(self.injected.call(
frame_id, _element_function(params), {"objectId": object_id}))}
return {"value": _serialize(self._call_on_elements(
frame_id, [object_id], _element_function(params)))}
finally:
self.injected.dispose(frame_id, object_id)
@@ -1646,18 +1685,19 @@ class FrameDispatcher(Dispatcher):
frame that navigates under it is `ContextDestroyed`, as Playwright
raises; sending it again ran it twice ([B285])."""
frame_id, selector = self.enter_frames(params["selector"])
value = self.injected.call(
frame_id,
"(injected, sel) => { const els = injected.querySelectorAll("
" injected.parseSelector(sel), document); %s }"
% _called_on(params, "els"),
selector, repeatable=False)
return {"value": _serialize(value)}
ids = self.injected.query_selector_all(frame_id, selector)
try:
return {"value": _serialize(self._call_on_elements(
frame_id, ids,
"(injected, ...els) => { %s }" % _called_on(params, "els")))}
finally:
for object_id in ids:
self.injected.dispose(frame_id, object_id)
def op_evaluate_handle(self, params: Dict) -> Any:
remote = self.injected.evaluate_in_main_remote(
remote = self.injected.evaluate_in_caller_remote(
self.frame_id, _with_argument(params))
return {"handle": self._handle_from_main(remote).channel}
return {"handle": self._handle_from_caller(remote).channel}
# ⛔ `DialogDispatcher` LIVED HERE AND IS GONE, fused into `_pw._impl._dialog`
@@ -1690,6 +1730,10 @@ class RequestDispatcher(Dispatcher):
#: heuristic - which is what makes `PageDispatcher.navigation_response`
#: able to answer `goto` with the response of the document it loaded.
self.navigation_id = params.get("navigationId")
#: Where the request went: the URL it was sent with, until a route
#: sends it on somewhere else (`continued_at`). Its response is that
#: URL's, as Playwright's server has it.
self.url = params.get("url") or ""
self.raw_headers = _headers_array(params.get("headers"))
self.response: Optional["ResponseDispatcher"] = None
#: Filled by `Network.requestFailed`. ⛔ None until it fails: an
@@ -1698,7 +1742,7 @@ class RequestDispatcher(Dispatcher):
self.failure: Optional[str] = None
frame_id = params.get("frameId") or page.frame.frame_id
super().__init__(server, page, {
"url": params.get("url") or "",
"url": self.url,
"method": params.get("method") or "GET",
"headers": self.raw_headers,
# ⛔ OMITTED WHEN ABSENT, never sent as null. The client reads
@@ -1707,13 +1751,13 @@ class RequestDispatcher(Dispatcher):
# corruption tomorrow; the driver omits the key entirely and this
# matches it.
#
# ⛔ THE ENGINE SENDS IT ONLY WHILE A ROUTE IS SET on the page or
# its context. A stealth patch dated 2026-08-24 stopped reading
# the body of every POST; through firefox-35 that left
# `request.post_data` None for every POST, inside a route guard
# too (feder-cr/invisible_core#90). Engines carrying the fix read
# it again while interception is on, so a route handler and the
# `request` event see the body then, and None without a route.
# ⛔ WHICH ENGINE SENDS IT. A stealth patch dated 2026-08-24
# stopped reading the body of every POST; through firefox-35 that
# left `request.post_data` None for every POST, inside a route
# guard too (feder-cr/invisible_core#90). From firefox-36 to
# firefox-48 the engine read it only while interception was on, so
# without a route it was None, like a form sent empty. From
# firefox-49 it reads every body up to 10 MB, as upstream's does.
# It is recorded here because this is where somebody will come
# looking.
**({"postData": params["postData"]}
@@ -1723,6 +1767,21 @@ class RequestDispatcher(Dispatcher):
"frame": page.frame_for(frame_id).channel,
})
def continued_at(self, url: str) -> None:
"""A route sent this request on to `url`.
⛔ THE ENGINE SAYS NOTHING OF IT: it applies a route's URL as an
internal redirect, as upstream's does, so this is the one place that
knows. Two things follow from it, and both are told here: the
response is `url`'s (Playwright's server answers `response.url` with
the overridden URL), and a navigation's document went to `url`, which
is where the lifecycle judges its commit. Until this, a
`route.fallback(url=...)` on a navigation made `goto` refuse the page
the route had sent it to (B326)."""
self.url = url
if self.navigation_id:
self.page.lifecycle.went_to(self.navigation_id, url)
def op_response(self, params: Dict) -> Any:
return {"response": self.response.channel if self.response else None}
@@ -1765,7 +1824,7 @@ class ResponseDispatcher(Dispatcher):
# and a response outliving its request is not a shape anybody has
# thought about. Matching the driver costs one word.
super().__init__(server, request, {
"url": request.initializer["url"],
"url": request.url,
"status": params.get("status") or 0,
"statusText": params.get("statusText") or "",
"headers": self.raw_headers,
@@ -1912,9 +1971,15 @@ class RouteDispatcher(Dispatcher):
"""⛔ The error code travels: `NS_ERROR_ABORT` and `NS_ERROR_FAILURE`
are not the same thing to a page that inspects the failure, and
collapsing every reason into one is the sort of flattening a detector
can read."""
can read.
⛔ AND A `route.abort()` WITH NO CODE IS "failed", as Playwright's own
server has it (`errorCode || "failed"`), which the engine turns into
`NS_ERROR_FAILURE`. This defaulted to "aborted", so the navigation
failed with `NS_ERROR_ABORT` where Playwright's Firefox says
`NS_ERROR_FAILURE` (B325)."""
return self._send("Network.abortInterceptedRequest",
{"errorCode": params.get("errorCode") or "aborted"})
{"errorCode": params.get("errorCode") or "failed"})
def op_continue(self, params: Dict) -> Any:
payload = only_set({
@@ -1924,6 +1989,10 @@ class RouteDispatcher(Dispatcher):
if params.get("headers") is not None else None,
"postData": params.get("postData"),
})
# Before the command, not after: the document may commit before its
# reply is read, and the lifecycle judges the commit by this.
if params.get("url"):
self.request.continued_at(params["url"])
return self._send("Network.resumeInterceptedRequest", payload)
def op_fulfill(self, params: Dict) -> Any:
@@ -2414,6 +2483,17 @@ class PageDispatcher(Dispatcher):
# reaches `load` leaves a wait on it hanging forever.
self.frame_for(params["frameId"]).emit(
"loadstate", {"add": state})
elif (method.startswith("Network.")
and self.lifecycle.favicons.is_favicon(params.get("requestId"))):
# The browser's own favicon request, as Playwright treats it
# (`invisible_core.juggler.favicon`): no event reaches the client
# and no route handler sees it. Held by a route, it goes on to the
# network instead of being aborted, as from any Firefox.
# ⛔ ASKED, NOT KEPT: the lifecycle read this event first and holds
# the session's one memory of it, so this page and the lifecycle
# cannot disagree about a request, a redirect or a replay.
if method == "Network.requestWillBeSent" and params.get("isIntercepted"):
self._let_through(params.get("requestId"))
elif method == "Network.requestWillBeSent":
request = RequestDispatcher(self.server, self, params)
self._requests[params.get("requestId")] = request
@@ -2632,19 +2712,32 @@ class PageDispatcher(Dispatcher):
elif self.context.intercepting:
owner = self.context
else:
# ⛔ The engine may have released it already: turning the PAGE's
# interception off resumes every request it holds, so this answer
# can find nothing and say "Cannot find request". Turning the
# CONTEXT's off releases nothing, which is the case this is for.
try:
self.send("Network.resumeInterceptedRequest",
{"requestId": request.request_id})
except (juggler.ProtocolError, juggler.TargetClosedError):
pass
self._let_through(request.request_id)
return
route = RouteDispatcher(self.server, request)
owner.emit("route", {"route": route.channel, "page": self.channel})
def _let_through(self, request_id: str) -> None:
"""Release a held request to the network, unchanged.
Two requests come here: one held while the context's interception was
switched off (turning the CONTEXT's off releases nothing), and the
favicon, which no handler may see.
⛔ POSTED, NOT SENT. This runs inside the handler of the request's own
event, on the reader thread, and `send` waits for a reply only that
thread can read: a deadlock (`Connection.post`). Measured 2026-10-17
the moment the favicon came here: the page's next `evaluate` waited
30 s for an answer behind it. The context branch had the same `send`
from the same thread, unnoticed only because that path is rare. An
error reply is dropped with the rest, which is what this wants: the
engine may have released the request already (turning the PAGE's
interception off resumes every request it holds) and say "Cannot find
request".
"""
self.conn.post("Network.resumeInterceptedRequest",
{"requestId": request_id}, session=self.session)
def send(self, command: str, params: Dict,
timeout: Optional[float] = None) -> Any:
"""A Juggler command on THIS page's session.
@@ -2941,8 +3034,9 @@ class PageDispatcher(Dispatcher):
def _storage(self, params: Dict, code: str, *args) -> Any:
"""localStorage or sessionStorage, in the PAGE's own world.
⛔ THE MAIN WORLD, and this one is not a style choice: web storage is
keyed by ORIGIN and the utility world sandbox has an ExpandedPrincipal.
⛔ THE CALLER'S WORLD, and this one is not a style choice: web storage
is keyed by ORIGIN and the utility world sandbox has an ExpandedPrincipal,
while the caller's world has the page's principal.
Reading it from there does not raise - it answers a DIFFERENT store,
empty, and the caller concludes the site saved nothing.
@@ -2955,7 +3049,7 @@ class PageDispatcher(Dispatcher):
raise ProtocolException(
"unknown storage kind %r: the two are localStorage and "
"sessionStorage" % kind)
return self.injected.evaluate_in_main(
return self.injected.evaluate_in_caller(
self.frame.frame_id, code % ((kind,) + args))
def op_storage_items(self, params: Dict) -> Any:
@@ -3031,7 +3125,7 @@ class PageDispatcher(Dispatcher):
`beforeunload` dialog. Answering it is the CALLER's job through the
dialog event, so this must not close the page itself - doing that
would dismiss the very dialog the option exists to raise."""
self.injected.evaluate_in_main(self.frame.frame_id, "window.close()")
self.injected.evaluate_in_caller(self.frame.frame_id, "window.close()")
return None
def op_touchscreen_tap(self, params: Dict) -> Any:
+99 -99
View File
@@ -12,27 +12,27 @@
"tests.sync.test_assertions::test_assertions_boolean_checked_with_intermediate_true[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_boolean_checked_with_intermediate_true_and_checked[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_boolean_fail_with_indeterminate_true[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_checked[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_disabled_enabled[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_checked[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_disabled_enabled[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_editable[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_editable_throws[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_editable_with_false[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_editable_with_false_and_throw_good_exception[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_editable_with_false_and_throw_good_exception[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_editable_with_not_and_false[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_editable_with_true[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_empty[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_enabled_eventually[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_enabled_eventually_with_not[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_enabled_with_false[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_enabled_with_false_throws_good_exception[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_enabled_with_false_throws_good_exception[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_enabled_with_not_and_false[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_enabled_with_true[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_focused[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_hidden_visible[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_hidden_visible[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_visible_eventually[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_visible_eventually_with_not[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_visible_with_false[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_visible_with_false_throws_good_exception[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_be_visible_with_false_throws_good_exception[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_visible_with_not_and_false[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_be_visible_with_true[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_contain_class[firefox]": "failed",
@@ -40,7 +40,7 @@
"tests.sync.test_assertions::test_assertions_locator_to_have_attribute[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_have_attribute_ignore_case[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_have_class[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_have_count[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_have_count[firefox]": "passed",
"tests.sync.test_assertions::test_assertions_locator_to_have_css[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_have_id[firefox]": "failed",
"tests.sync.test_assertions::test_assertions_locator_to_have_js_property[firefox]": "failed",
@@ -60,17 +60,17 @@
"tests.sync.test_assertions::test_should_be_able_to_set_custom_global_timeout[firefox]": "failed",
"tests.sync.test_assertions::test_should_be_able_to_set_custom_timeout[firefox]": "failed",
"tests.sync.test_assertions::test_should_be_attached_default[firefox]": "passed",
"tests.sync.test_assertions::test_should_be_attached_eventually[firefox]": "failed",
"tests.sync.test_assertions::test_should_be_attached_eventually[firefox]": "passed",
"tests.sync.test_assertions::test_should_be_attached_eventually_with_not[firefox]": "passed",
"tests.sync.test_assertions::test_should_be_attached_fail[firefox]": "failed",
"tests.sync.test_assertions::test_should_be_attached_fail[firefox]": "passed",
"tests.sync.test_assertions::test_should_be_attached_fail_with_not[firefox]": "failed",
"tests.sync.test_assertions::test_should_be_attached_with_attached_false[firefox]": "failed",
"tests.sync.test_assertions::test_should_be_attached_with_attached_false_and_throw_good_error[firefox]": "failed",
"tests.sync.test_assertions::test_should_be_attached_with_attached_false[firefox]": "passed",
"tests.sync.test_assertions::test_should_be_attached_with_attached_false_and_throw_good_error[firefox]": "passed",
"tests.sync.test_assertions::test_should_be_attached_with_attached_true[firefox]": "passed",
"tests.sync.test_assertions::test_should_be_attached_with_hidden_element[firefox]": "passed",
"tests.sync.test_assertions::test_should_be_attached_with_impossible_timeout[firefox]": "passed",
"tests.sync.test_assertions::test_should_be_attached_with_impossible_timeout_not[firefox]": "failed",
"tests.sync.test_assertions::test_should_be_attached_with_not[firefox]": "failed",
"tests.sync.test_assertions::test_should_be_attached_with_impossible_timeout_not[firefox]": "passed",
"tests.sync.test_assertions::test_should_be_attached_with_not[firefox]": "passed",
"tests.sync.test_assertions::test_should_be_attached_with_not_and_attached_false[firefox]": "passed",
"tests.sync.test_assertions::test_should_print_expected_value_with_custom_message[firefox]": "failed",
"tests.sync.test_assertions::test_should_print_response_with_text_content_type_if_to_be_ok_fails[firefox]": "failed",
@@ -115,34 +115,34 @@
"tests.sync.test_browsercontext_events::test_dialog_event_should_work_in_immdiately_closed_popup[firefox]": "skipped",
"tests.sync.test_browsercontext_events::test_dialog_event_should_work_in_popup1[firefox]": "failed",
"tests.sync.test_browsercontext_events::test_dialog_event_should_work_in_popup_2[firefox]": "skipped",
"tests.sync.test_browsercontext_events::test_dialog_event_should_work_with_inline_script_tag[firefox]": "failed",
"tests.sync.test_browsercontext_events::test_dialog_event_should_work_with_inline_script_tag[firefox]": "passed",
"tests.sync.test_browsercontext_events::test_download_event_should_work[firefox]": "failed",
"tests.sync.test_browsercontext_events::test_frameattached_event_should_work[firefox]": "failed",
"tests.sync.test_browsercontext_events::test_framedetached_event_should_work[firefox]": "failed",
"tests.sync.test_browsercontext_events::test_frameattached_event_should_work[firefox]": "passed",
"tests.sync.test_browsercontext_events::test_framedetached_event_should_work[firefox]": "passed",
"tests.sync.test_browsercontext_events::test_framenavigated_event_should_work[firefox]": "passed",
"tests.sync.test_browsercontext_events::test_pageclose_event_should_work[firefox]": "passed",
"tests.sync.test_browsercontext_events::test_pageload_event_should_work[firefox]": "passed",
"tests.sync.test_browsercontext_events::test_weberror_event_should_include_location[firefox]": "failed",
"tests.sync.test_browsercontext_events::test_weberror_event_should_work[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_amend_binary_post_data[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_amend_http_headers[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_amend_method[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_amend_post_data[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_chain_fallback_into_page[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_chain_once[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_delete_header_with_undefined_value[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_fall_back[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_fall_back_after_exception[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_fall_back_async_delayed[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_not_chain_abort[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_not_chain_fulfill[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_override_request_url[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_work[firefox]": "failed",
"tests.sync.test_browsercontext_request_fallback::test_should_amend_binary_post_data[firefox]": "passed",
"tests.sync.test_browsercontext_request_fallback::test_should_amend_http_headers[firefox]": "passed",
"tests.sync.test_browsercontext_request_fallback::test_should_amend_method[firefox]": "passed",
"tests.sync.test_browsercontext_request_fallback::test_should_amend_post_data[firefox]": "passed",
"tests.sync.test_browsercontext_request_fallback::test_should_chain_fallback_into_page[firefox]": "passed",
"tests.sync.test_browsercontext_request_fallback::test_should_chain_once[firefox]": "passed",
"tests.sync.test_browsercontext_request_fallback::test_should_delete_header_with_undefined_value[firefox]": "passed",
"tests.sync.test_browsercontext_request_fallback::test_should_fall_back[firefox]": "passed",
"tests.sync.test_browsercontext_request_fallback::test_should_fall_back_after_exception[firefox]": "passed",
"tests.sync.test_browsercontext_request_fallback::test_should_fall_back_async_delayed[firefox]": "passed",
"tests.sync.test_browsercontext_request_fallback::test_should_not_chain_abort[firefox]": "passed",
"tests.sync.test_browsercontext_request_fallback::test_should_not_chain_fulfill[firefox]": "passed",
"tests.sync.test_browsercontext_request_fallback::test_should_override_request_url[firefox]": "passed",
"tests.sync.test_browsercontext_request_fallback::test_should_work[firefox]": "passed",
"tests.sync.test_browsercontext_request_intercept::test_should_fulfill_intercepted_response[firefox]": "failed",
"tests.sync.test_browsercontext_request_intercept::test_should_fulfill_response_with_empty_body[firefox]": "failed",
"tests.sync.test_browsercontext_request_intercept::test_should_fulfill_with_any_response[firefox]": "failed",
"tests.sync.test_browsercontext_request_intercept::test_should_override_with_defaults_when_intercepted_response_not_provided[firefox]": "failed",
"tests.sync.test_browsercontext_request_intercept::test_should_show_exception_after_fulfill[firefox]": "failed",
"tests.sync.test_browsercontext_request_intercept::test_should_show_exception_after_fulfill[firefox]": "passed",
"tests.sync.test_browsercontext_request_intercept::test_should_support_fulfill_after_intercept[firefox]": "failed",
"tests.sync.test_browsercontext_service_worker_policy::test_block_blocks_service_worker_registration[firefox]": "failed",
"tests.sync.test_browsercontext_service_worker_policy::test_should_allow_service_workers_by_default[firefox]": "passed",
@@ -196,29 +196,29 @@
"tests.sync.test_element_handle::test_bounding_box_when_inline_box_child_is_outside_of_viewport[firefox]": "passed",
"tests.sync.test_element_handle::test_bounding_box_with_SVG_nodes[firefox]": "failed",
"tests.sync.test_element_handle::test_bounding_box_with_page_scale[firefox]": "skipped",
"tests.sync.test_element_handle::test_check_the_box[firefox]": "failed",
"tests.sync.test_element_handle::test_click[firefox]": "failed",
"tests.sync.test_element_handle::test_check_the_box[firefox]": "passed",
"tests.sync.test_element_handle::test_click[firefox]": "passed",
"tests.sync.test_element_handle::test_click_for_TextNodes[firefox]": "failed",
"tests.sync.test_element_handle::test_click_for_shadow_dom_v1[firefox]": "failed",
"tests.sync.test_element_handle::test_click_for_shadow_dom_v1[firefox]": "passed",
"tests.sync.test_element_handle::test_click_throw_for__br__elements_with_force[firefox]": "failed",
"tests.sync.test_element_handle::test_click_throw_for_detached_nodes[firefox]": "failed",
"tests.sync.test_element_handle::test_click_throw_for_hidden_nodes_with_force[firefox]": "failed",
"tests.sync.test_element_handle::test_click_throw_for_recursively_hidden_nodes_with_force[firefox]": "failed",
"tests.sync.test_element_handle::test_click_with_node_removed[firefox]": "failed",
"tests.sync.test_element_handle::test_content_frame[firefox]": "failed",
"tests.sync.test_element_handle::test_click_with_node_removed[firefox]": "passed",
"tests.sync.test_element_handle::test_content_frame[firefox]": "passed",
"tests.sync.test_element_handle::test_content_frame_for_document_element[firefox]": "passed",
"tests.sync.test_element_handle::test_content_frame_for_non_iframes[firefox]": "passed",
"tests.sync.test_element_handle::test_double_click_the_button[firefox]": "failed",
"tests.sync.test_element_handle::test_fill_input[firefox]": "failed",
"tests.sync.test_element_handle::test_fill_input_when_Node_is_removed[firefox]": "failed",
"tests.sync.test_element_handle::test_focus_a_button[firefox]": "failed",
"tests.sync.test_element_handle::test_fill_input[firefox]": "passed",
"tests.sync.test_element_handle::test_fill_input_when_Node_is_removed[firefox]": "passed",
"tests.sync.test_element_handle::test_focus_a_button[firefox]": "passed",
"tests.sync.test_element_handle::test_get_attribute[firefox]": "passed",
"tests.sync.test_element_handle::test_hover[firefox]": "failed",
"tests.sync.test_element_handle::test_hover_when_node_is_removed[firefox]": "failed",
"tests.sync.test_element_handle::test_hover[firefox]": "passed",
"tests.sync.test_element_handle::test_hover_when_node_is_removed[firefox]": "passed",
"tests.sync.test_element_handle::test_inner_html[firefox]": "passed",
"tests.sync.test_element_handle::test_inner_text[firefox]": "passed",
"tests.sync.test_element_handle::test_inner_text_should_throw[firefox]": "failed",
"tests.sync.test_element_handle::test_input_value[firefox]": "failed",
"tests.sync.test_element_handle::test_input_value[firefox]": "passed",
"tests.sync.test_element_handle::test_is_checked_should_work[firefox]": "failed",
"tests.sync.test_element_handle::test_is_editable_should_work[firefox]": "failed",
"tests.sync.test_element_handle::test_is_enabled_and_is_disabled_should_work[firefox]": "failed",
@@ -232,15 +232,15 @@
"tests.sync.test_element_handle::test_scroll[firefox]": "failed",
"tests.sync.test_element_handle::test_scroll_should_throw_for_detached_element[firefox]": "failed",
"tests.sync.test_element_handle::test_select_input[firefox]": "failed",
"tests.sync.test_element_handle::test_select_single_option[firefox]": "failed",
"tests.sync.test_element_handle::test_select_single_option[firefox]": "passed",
"tests.sync.test_element_handle::test_select_text_select_plain_div[firefox]": "failed",
"tests.sync.test_element_handle::test_select_text_timeout_waiting_for_invisible_element[firefox]": "failed",
"tests.sync.test_element_handle::test_select_textarea[firefox]": "failed",
"tests.sync.test_element_handle::test_set_checked[firefox]": "failed",
"tests.sync.test_element_handle::test_set_checked[firefox]": "passed",
"tests.sync.test_element_handle::test_should_allow_disposing_twice[firefox]": "passed",
"tests.sync.test_element_handle::test_should_timeout_waiting_for_visible[firefox]": "failed",
"tests.sync.test_element_handle::test_text_content[firefox]": "passed",
"tests.sync.test_element_handle::test_uncheck_the_box[firefox]": "failed",
"tests.sync.test_element_handle::test_uncheck_the_box[firefox]": "passed",
"tests.sync.test_element_handle_wait_for_element_state::test_should_throw_waiting_for_enabled_when_detached[firefox]": "failed",
"tests.sync.test_element_handle_wait_for_element_state::test_should_throw_waiting_for_visible_when_detached[firefox]": "failed",
"tests.sync.test_element_handle_wait_for_element_state::test_should_timeout_waiting_for_visible[firefox]": "failed",
@@ -253,8 +253,8 @@
"tests.sync.test_element_handle_wait_for_element_state::test_should_wait_for_hidden_when_detached[firefox]": "failed",
"tests.sync.test_element_handle_wait_for_element_state::test_should_wait_for_visible[firefox]": "failed",
"tests.sync.test_expect_misc::test_to_be_in_viewport_should_have_good_stack[firefox]": "failed",
"tests.sync.test_expect_misc::test_to_be_in_viewport_should_report_intersection_even_if_fully_covered_by_other_element[firefox]": "passed",
"tests.sync.test_expect_misc::test_to_be_in_viewport_should_respect_ratio_option[firefox]": "passed",
"tests.sync.test_expect_misc::test_to_be_in_viewport_should_report_intersection_even_if_fully_covered_by_other_element[firefox]": "failed",
"tests.sync.test_expect_misc::test_to_be_in_viewport_should_respect_ratio_option[firefox]": "failed",
"tests.sync.test_expect_misc::test_to_be_in_viewport_should_work[firefox]": "failed",
"tests.sync.test_extension::test_should_give_access_to_the_service_worker[firefox]": "skipped",
"tests.sync.test_extension::test_should_give_access_to_the_service_worker_when_recording_video[firefox]": "skipped",
@@ -383,45 +383,45 @@
"tests.sync.test_launcher::test_browser_type_launch_should_throw_if_page_argument_is_passed[firefox]": "skipped",
"tests.sync.test_launcher::test_browser_type_name_should_work[firefox]": "passed",
"tests.sync.test_listeners::test_listeners[firefox]": "passed",
"tests.sync.test_locator_get_by::test_get_by_alt_text[firefox]": "failed",
"tests.sync.test_locator_get_by::test_get_by_alt_text[firefox]": "passed",
"tests.sync.test_locator_get_by::test_get_by_escaping[firefox]": "failed",
"tests.sync.test_locator_get_by::test_get_by_label[firefox]": "failed",
"tests.sync.test_locator_get_by::test_get_by_label[firefox]": "passed",
"tests.sync.test_locator_get_by::test_get_by_label_with_nested_elements[firefox]": "failed",
"tests.sync.test_locator_get_by::test_get_by_placeholder[firefox]": "failed",
"tests.sync.test_locator_get_by::test_get_by_role[firefox]": "failed",
"tests.sync.test_locator_get_by::test_get_by_placeholder[firefox]": "passed",
"tests.sync.test_locator_get_by::test_get_by_role[firefox]": "passed",
"tests.sync.test_locator_get_by::test_get_by_test_id[firefox]": "failed",
"tests.sync.test_locator_get_by::test_get_by_test_id_escape_id[firefox]": "failed",
"tests.sync.test_locator_get_by::test_get_by_text[firefox]": "failed",
"tests.sync.test_locator_get_by::test_get_by_title[firefox]": "failed",
"tests.sync.test_locators::test_drag_to[firefox]": "failed",
"tests.sync.test_locator_get_by::test_get_by_text[firefox]": "passed",
"tests.sync.test_locator_get_by::test_get_by_title[firefox]": "passed",
"tests.sync.test_locators::test_drag_to[firefox]": "passed",
"tests.sync.test_locators::test_drop_should_drop_a_file_payload[firefox]": "failed",
"tests.sync.test_locators::test_drop_should_drop_clipboard_like_data[firefox]": "failed",
"tests.sync.test_locators::test_frame_locator_owner_should_work[firefox]": "failed",
"tests.sync.test_locators::test_frame_locator_owner_should_work[firefox]": "passed",
"tests.sync.test_locators::test_get_by_role_with_description[firefox]": "passed",
"tests.sync.test_locators::test_get_by_role_with_description_whitespace_normalization[firefox]": "passed",
"tests.sync.test_locators::test_locator_all_should_work[firefox]": "passed",
"tests.sync.test_locators::test_locator_click_timeout_error_should_contain_call_log[firefox]": "failed",
"tests.sync.test_locators::test_locator_content_frame_should_work[firefox]": "failed",
"tests.sync.test_locators::test_locator_count_should_work_with_deleted_map_in_main_world[firefox]": "failed",
"tests.sync.test_locators::test_locator_frame_locator_should_not_throw_on_first_last_nth[firefox]": "failed",
"tests.sync.test_locators::test_locator_count_should_work_with_deleted_map_in_main_world[firefox]": "passed",
"tests.sync.test_locators::test_locator_frame_locator_should_not_throw_on_first_last_nth[firefox]": "passed",
"tests.sync.test_locators::test_locator_frame_locator_should_throw_on_ambiguity[firefox]": "failed",
"tests.sync.test_locators::test_locator_highlight_should_work[firefox]": "failed",
"tests.sync.test_locators::test_locator_locator_and_framelocator_locator_should_accept_locator[firefox]": "failed",
"tests.sync.test_locators::test_locator_locator_and_framelocator_locator_should_accept_locator[firefox]": "passed",
"tests.sync.test_locators::test_locator_query_should_filter_by_regex[firefox]": "failed",
"tests.sync.test_locators::test_locator_query_should_filter_by_regex_and_regexp_flags[firefox]": "failed",
"tests.sync.test_locators::test_locator_query_should_filter_by_regex_with_quotes[firefox]": "failed",
"tests.sync.test_locators::test_locator_query_should_filter_by_text[firefox]": "failed",
"tests.sync.test_locators::test_locator_query_should_filter_by_text_2[firefox]": "failed",
"tests.sync.test_locators::test_locator_query_should_filter_by_text_with_quotes[firefox]": "failed",
"tests.sync.test_locators::test_locator_should_enforce_same_frame_for_has_locator[firefox]": "failed",
"tests.sync.test_locators::test_locator_should_enforce_same_frame_for_has_locator[firefox]": "passed",
"tests.sync.test_locators::test_locator_should_ignore_deprecated_is_hidden_and_visible_timeout[firefox]": "passed",
"tests.sync.test_locators::test_locator_should_return_page[firefox]": "passed",
"tests.sync.test_locators::test_locator_should_support_has_locator[firefox]": "failed",
"tests.sync.test_locators::test_locator_should_support_has_locator[firefox]": "passed",
"tests.sync.test_locators::test_locator_should_support_locator_or[firefox]": "failed",
"tests.sync.test_locators::test_locators_all_inner_texts[firefox]": "passed",
"tests.sync.test_locators::test_locators_all_text_contents_should_work[firefox]": "passed",
"tests.sync.test_locators::test_locators_check_should_work[firefox]": "passed",
"tests.sync.test_locators::test_locators_clear_should_work[firefox]": "failed",
"tests.sync.test_locators::test_locators_clear_should_work[firefox]": "passed",
"tests.sync.test_locators::test_locators_click_should_work[firefox]": "passed",
"tests.sync.test_locators::test_locators_click_should_work_for_text_nodes[firefox]": "passed",
"tests.sync.test_locators::test_locators_click_should_work_with_node_removed[firefox]": "passed",
@@ -431,9 +431,9 @@
"tests.sync.test_locators::test_locators_evaluate_handle_should_work[firefox]": "failed",
"tests.sync.test_locators::test_locators_fill_should_work[firefox]": "passed",
"tests.sync.test_locators::test_locators_focus_should_work[firefox]": "passed",
"tests.sync.test_locators::test_locators_frame_should_work_for_nested_iframe[firefox]": "failed",
"tests.sync.test_locators::test_locators_frame_should_work_with_iframe[firefox]": "failed",
"tests.sync.test_locators::test_locators_frame_should_work_with_locator_frame_locator[firefox]": "failed",
"tests.sync.test_locators::test_locators_frame_should_work_for_nested_iframe[firefox]": "passed",
"tests.sync.test_locators::test_locators_frame_should_work_with_iframe[firefox]": "passed",
"tests.sync.test_locators::test_locators_frame_should_work_with_locator_frame_locator[firefox]": "passed",
"tests.sync.test_locators::test_locators_get_attribute_should_work[firefox]": "passed",
"tests.sync.test_locators::test_locators_has_does_not_encode_unicode[firefox]": "failed",
"tests.sync.test_locators::test_locators_hover_should_work[firefox]": "passed",
@@ -459,8 +459,8 @@
"tests.sync.test_locators::test_locators_should_scroll_into_view[firefox]": "failed",
"tests.sync.test_locators::test_locators_should_select_textarea[firefox]": "failed",
"tests.sync.test_locators::test_locators_should_support_locator_and[firefox]": "failed",
"tests.sync.test_locators::test_locators_should_throw_due_to_strictness[firefox]": "failed",
"tests.sync.test_locators::test_locators_should_throw_due_to_strictness_2[firefox]": "failed",
"tests.sync.test_locators::test_locators_should_throw_due_to_strictness[firefox]": "passed",
"tests.sync.test_locators::test_locators_should_throw_due_to_strictness_2[firefox]": "passed",
"tests.sync.test_locators::test_locators_should_throw_on_capture_without_nth[firefox]": "passed",
"tests.sync.test_locators::test_locators_should_type[firefox]": "passed",
"tests.sync.test_locators::test_locators_should_upload_a_file[firefox]": "failed",
@@ -470,26 +470,26 @@
"tests.sync.test_locators::test_should_combine_visible_with_other_selectors[firefox]": "failed",
"tests.sync.test_locators::test_should_filter_by_case_insensitive_regex_in_a_child[firefox]": "failed",
"tests.sync.test_locators::test_should_filter_by_case_insensitive_regex_in_multiple_children[firefox]": "failed",
"tests.sync.test_locators::test_should_filter_by_regex_with_special_symbols[firefox]": "error",
"tests.sync.test_locators::test_should_filter_by_regex_with_special_symbols[firefox]": "failed",
"tests.sync.test_locators::test_should_support_filter_visible[firefox]": "failed",
"tests.sync.test_locators::test_should_support_locator_filter[firefox]": "failed",
"tests.sync.test_locators::test_should_support_locator_that[firefox]": "failed",
"tests.sync.test_network::test_response_security_details[firefox]": "failed",
"tests.sync.test_network::test_response_security_details_none_without_https[firefox]": "failed",
"tests.sync.test_network::test_response_server_addr[firefox]": "failed",
"tests.sync.test_locators::test_should_support_locator_filter[firefox]": "passed",
"tests.sync.test_locators::test_should_support_locator_that[firefox]": "passed",
"tests.sync.test_network::test_response_security_details[firefox]": "passed",
"tests.sync.test_network::test_response_security_details_none_without_https[firefox]": "passed",
"tests.sync.test_network::test_response_server_addr[firefox]": "passed",
"tests.sync.test_network::test_should_fulfill_with_global_fetch_result[firefox]": "failed",
"tests.sync.test_network::test_should_report_if_response_was_from_service_worker[firefox]": "failed",
"tests.sync.test_network::test_should_report_if_response_was_from_service_worker[firefox]": "passed",
"tests.sync.test_network::test_should_report_service_worker_request[firefox]": "skipped",
"tests.sync.test_page::test_drag_and_drop_helper_method[firefox]": "failed",
"tests.sync.test_page::test_drag_and_drop_helper_method[firefox]": "passed",
"tests.sync.test_page::test_emitted_for_domcontentloaded_and_load[firefox]": "passed",
"tests.sync.test_page::test_input_value[firefox]": "failed",
"tests.sync.test_page::test_input_value[firefox]": "passed",
"tests.sync.test_page::test_page_pause_should_reset_custom_timeouts[firefox]": "failed",
"tests.sync.test_page::test_page_pause_should_reset_default_timeouts[firefox]": "failed",
"tests.sync.test_page::test_page_should_ignore_deprecated_is_hidden_and_visible_timeout[firefox]": "passed",
"tests.sync.test_page::test_should_check_box_using_set_checked[firefox]": "passed",
"tests.sync.test_page::test_should_set_bodysize_and_headersize[firefox]": "failed",
"tests.sync.test_page::test_should_set_bodysize_to_0[firefox]": "failed",
"tests.sync.test_page::test_sync_stacks_should_work[firefox]": "failed",
"tests.sync.test_page::test_sync_stacks_should_work[firefox]": "passed",
"tests.sync.test_page_add_locator_handler::test_should_not_work_with_force_true[firefox]": "failed",
"tests.sync.test_page_add_locator_handler::test_should_removeLocatorHandler[firefox]": "failed",
"tests.sync.test_page_add_locator_handler::test_should_throw_when_handler_times_out[firefox]": "failed",
@@ -569,28 +569,28 @@
"tests.sync.test_page_network_response::test_should_reject_response_finished_if_context_closes[firefox]": "passed",
"tests.sync.test_page_network_response::test_should_reject_response_finished_if_page_closes[firefox]": "passed",
"tests.sync.test_page_network_response::test_should_return_http_version[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_amend_binary_post_data[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_amend_http_headers[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_amend_json_post_data[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_amend_method[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_amend_post_data[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_chain_fallback_with_dynamic_url[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_chain_once[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_delete_header_with_undefined_value[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_fall_back[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_fall_back_after_exception[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_fall_back_async_delayed[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_not_chain_abort[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_not_chain_fulfill[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_override_request_url[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_work[firefox]": "failed",
"tests.sync.test_page_request_fallback::test_should_amend_binary_post_data[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_amend_http_headers[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_amend_json_post_data[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_amend_method[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_amend_post_data[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_chain_fallback_with_dynamic_url[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_chain_once[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_delete_header_with_undefined_value[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_fall_back[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_fall_back_after_exception[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_fall_back_async_delayed[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_not_chain_abort[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_not_chain_fulfill[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_override_request_url[firefox]": "passed",
"tests.sync.test_page_request_fallback::test_should_work[firefox]": "passed",
"tests.sync.test_page_request_gc::test_should_work[firefox]": "failed",
"tests.sync.test_page_request_intercept::test_should_intercept_with_url_override[firefox]": "failed",
"tests.sync.test_page_request_intercept::test_should_support_timeout_option_in_route_fetch[firefox]": "failed",
"tests.sync.test_page_request_timeout::test_context_request_should_support_timeout_option[firefox]": "failed",
"tests.sync.test_page_select_option::test_select_option_should_deselect_all_options_when_passed_no_values_for_a_multiple_select[firefox]": "passed",
"tests.sync.test_page_select_option::test_select_option_should_deselect_all_options_when_passed_no_values_for_a_select_without_multiple[firefox]": "passed",
"tests.sync.test_page_select_option::test_select_option_should_not_throw_when_select_causes_navigation[firefox]": "failed",
"tests.sync.test_page_select_option::test_select_option_should_not_throw_when_select_causes_navigation[firefox]": "passed",
"tests.sync.test_page_select_option::test_select_option_should_respect_event_bubbling[firefox]": "passed",
"tests.sync.test_page_select_option::test_select_option_should_return_an_array_of_matched_values[firefox]": "passed",
"tests.sync.test_page_select_option::test_select_option_should_return_an_array_of_one_element_when_multiple_is_not_set[firefox]": "passed",
@@ -604,7 +604,7 @@
"tests.sync.test_page_select_option::test_select_option_should_select_single_option_by_empty_label[firefox]": "passed",
"tests.sync.test_page_select_option::test_select_option_should_select_single_option_by_handle[firefox]": "failed",
"tests.sync.test_page_select_option::test_select_option_should_select_single_option_by_index[firefox]": "passed",
"tests.sync.test_page_select_option::test_select_option_should_select_single_option_by_index_0[firefox]": "passed",
"tests.sync.test_page_select_option::test_select_option_should_select_single_option_by_index_0[firefox]": "failed",
"tests.sync.test_page_select_option::test_select_option_should_select_single_option_by_label[firefox]": "passed",
"tests.sync.test_page_select_option::test_select_option_should_select_single_option_by_value[firefox]": "passed",
"tests.sync.test_page_select_option::test_select_option_should_throw_when_element_is_not_a__select_[firefox]": "passed",
@@ -617,14 +617,14 @@
"tests.sync.test_queryselector::test_selectors_register_should_work[firefox]": "failed",
"tests.sync.test_queryselector::test_selectors_register_should_work_in_main_and_isolated_world[firefox]": "failed",
"tests.sync.test_queryselector::test_selectors_register_should_work_with_path[firefox]": "failed",
"tests.sync.test_queryselector::test_should_work_with_layout_selectors[firefox]": "failed",
"tests.sync.test_queryselector::test_should_work_with_layout_selectors[firefox]": "passed",
"tests.sync.test_request_fulfill::test_should_fetch_original_request_and_fulfill[firefox]": "failed",
"tests.sync.test_request_fulfill::test_should_fulfill_json[firefox]": "failed",
"tests.sync.test_request_fulfill::test_should_fulfill_json[firefox]": "passed",
"tests.sync.test_request_fulfill::test_should_fulfill_json_overriding_existing_response[firefox]": "failed",
"tests.sync.test_request_intercept::test_should_fulfill_intercepted_response[firefox]": "failed",
"tests.sync.test_request_intercept::test_should_fulfill_response_with_empty_body[firefox]": "failed",
"tests.sync.test_request_intercept::test_should_fulfill_with_any_response[firefox]": "failed",
"tests.sync.test_request_intercept::test_should_intercept_by_glob[firefox]": "failed",
"tests.sync.test_request_intercept::test_should_intercept_by_glob[firefox]": "passed",
"tests.sync.test_request_intercept::test_should_not_follow_redirects_when_max_redirects_is_set_to_0_in_route_fetch[firefox]": "failed",
"tests.sync.test_request_intercept::test_should_override_with_defaults_when_intercepted_response_not_provided[firefox]": "failed",
"tests.sync.test_request_intercept::test_should_support_fulfill_after_intercept[firefox]": "failed",
@@ -662,7 +662,7 @@
"tests.sync.test_sync::test_sync_handle_multiple_pages[firefox]": "passed",
"tests.sync.test_sync::test_sync_make_existing_page_sync[firefox]": "passed",
"tests.sync.test_sync::test_sync_nested_query_selector[firefox]": "failed",
"tests.sync.test_sync::test_sync_network_events[firefox]": "failed",
"tests.sync.test_sync::test_sync_network_events[firefox]": "passed",
"tests.sync.test_sync::test_sync_playwright_multiple_times[firefox]": "passed",
"tests.sync.test_sync::test_sync_playwright_stop_multiple_times[firefox]": "passed",
"tests.sync.test_sync::test_sync_query_selector[firefox]": "passed",
@@ -689,8 +689,8 @@
"tests.sync.test_tracing::test_should_work_with_playwright_context_managers[firefox]": "failed",
"tests.sync.test_tracing::test_start_stop[firefox]": "failed",
"tests.sync.test_unroute_behavior::test_context_unroute_all_removes_all_handlers[firefox]": "passed",
"tests.sync.test_unroute_behavior::test_page_route_returns_disposable[firefox]": "failed",
"tests.sync.test_unroute_behavior::test_page_unroute_all_removes_all_routes[firefox]": "failed",
"tests.sync.test_unroute_behavior::test_page_route_returns_disposable[firefox]": "passed",
"tests.sync.test_unroute_behavior::test_page_unroute_all_removes_all_routes[firefox]": "passed",
"tests.sync.test_video::test_record_video_can_get_video_path_immediately[firefox]": "failed",
"tests.sync.test_video::test_record_video_to_path[firefox]": "failed",
"tests.sync.test_video::test_record_video_to_path_persistent[firefox]": "failed",
+12 -1
View File
@@ -54,10 +54,18 @@ def _serve():
def _what_the_page_could_do(page):
"""What the PAGE's own code could do under its policy.
⛔ THE PAGE'S `eval`, `window.eval`, NOT THE CALLER'S. Since firefox-49 the
caller's code runs in a world of its own ([B322]), and its own `eval` is
that world's, which the page's policy does not govern (see the last
assertion of the test). `window.eval` is the page's function, so calling it
asks the page's policy, as an `eval` in the page's own script would."""
page.add_script_tag(content="window.added = 7")
return {
"inline": page.evaluate("() => window.inline === 1"),
"eval": page.evaluate("() => { try { return eval('2 + 2'); } catch (e) { return e.name; } }"),
"eval": page.evaluate(
"() => { try { return window.eval('2 + 2'); } catch (e) { return e.name; } }"),
"added": page.evaluate("() => window.added === 7"),
}
@@ -79,6 +87,9 @@ def test_bypass_csp_lifts_the_page_policy_and_its_absence_keeps_it(firefox_binar
page.goto(base + path, wait_until="load")
assert _what_the_page_could_do(page) == blocked, (
"%s: without bypass_csp the page's policy must hold" % path)
# the caller's own eval is its world's, which the page's
# policy does not govern ([B322])
assert page.evaluate("() => eval('2 + 2')") == 4
ctx.close()
ctx = browser.new_context(bypass_csp=True)
page = ctx.new_page()
@@ -1,4 +1,4 @@
"""Handles of values the CALLER'S code produced in the page's own world.
"""Handles of values the CALLER'S code produced in its world.
Two defects of 0.36.0, one family. [B323]: `wait_for_function("() =>
document.querySelector('#x')")` - the most common wait there is - never ended
@@ -6,10 +6,11 @@ although the element existed, because the predicate ran by value and Python
judged the serialized result, where a node is nothing truthy. The judgement is
now invisible-core's `js_truthy`, from one run of the predicate. [B324]: every
handle `evaluate_handle` returned was unusable - `text_content`, `evaluate` and
`json_value` all failed with "Cannot find object" - because a main-world
objectId was made into a utility-world handle. A node is now adopted into the
utility world, and any other value's handle runs its operations in the main
world (`FrameDispatcher._handle_from_main`).
`json_value` all failed with "Cannot find object" - because an objectId of the
caller's code was made into a utility-world handle. A node is now adopted into
the utility world, and any other value's handle runs its operations in the
caller's world (`FrameDispatcher._handle_from_caller`), which since firefox-49
is a world of its own and no longer the page's realm ([B322]).
"""
from __future__ import annotations
+8 -2
View File
@@ -247,7 +247,10 @@ def test_every_element_callback_receives_the_caller_s_argument(page, method, rec
page.frame.enter_frames = Mock(return_value=("widget", "#target"))
page.injected.query_selector.return_value = "node"
page.injected.call.return_value = 6
page.injected.query_selector_all.return_value = ["node"]
page.injected.caller_context.return_value = "caller-ctx"
page.injected.node_to_caller.return_value = "copy"
page.injected.call_raw.return_value = {"value": 6}
params = {"selector": "compound", "expression": "(x, a) => a",
"arg": {"value": {"o": [{"k": "n", "v": {"n": 2}}]}, "handles": []}}
if method == "handle.evaluate":
@@ -255,7 +258,10 @@ def test_every_element_callback_receives_the_caller_s_argument(page, method, rec
"node").call("evaluateExpression", params)
else:
page.frame.call(method, params)
script = page.injected.call.call_args.args[1]
# the caller's code, in the caller's world, on the node carried there [B322]
context, script, args = page.injected.call_raw.call_args.args[:3]
assert context == "caller-ctx"
assert {"objectId": "copy"} in args
assert ("r(%s, {\"n\": 2})" % receiver) in script, script
+183 -1
View File
@@ -41,7 +41,9 @@ from types import SimpleNamespace
import pytest
from invisible_core.juggler.lifecycle import NavigationMark
from invisible_core.juggler.connection import EventListeners
from invisible_core.juggler.favicon import FaviconRequests
from invisible_core.juggler.lifecycle import Lifecycle, NavigationMark
# -- the unit half: the server, fed the events a navigation produces ---------
@@ -68,6 +70,9 @@ def _bare_page():
page._requests = {}
page._request_log = []
page._navigation_requests = {}
# The network branches ask the session's lifecycle which requests are the
# favicon; an empty memory answers "none", as for a page without one.
page.lifecycle = SimpleNamespace(favicons=FaviconRequests())
page.messages = up
page.context = SimpleNamespace(emit=lambda *a, **k: None, intercepting=False)
page.frame = SimpleNamespace(frame_id="F1")
@@ -361,6 +366,183 @@ def test_a_response_with_no_certificate_answers_None(sent):
assert response.op_security_details({}) == {"value": None}
class _Pipe(EventListeners):
"""The subscriber registry the session's lifecycle listens on, and the
`post` a held request is released with."""
def __init__(self, sent):
super().__init__()
self._sent = sent
def post(self, method, params=None, session=None):
self._sent.append((method, params, session))
def _favicon_page(intercepting):
"""A bare page with a REAL lifecycle on its session, recording what reaches
the client and what is posted to the engine."""
page = _bare_page()
told, sent = [], []
pipe = _Pipe(sent)
page.lifecycle = Lifecycle(pipe, "S1")
page.context = SimpleNamespace(
emit=lambda event, params: told.append(event), intercepting=intercepting,
browser=SimpleNamespace(conn=pipe))
page.session = "S1"
page.intercepting = False
def send(*a, **k):
# These events are handled on the reader thread, where a `send`
# waits for a reply only that thread could read.
pytest.fail("a held request was released with send, from the reader thread")
page.send = send
return page, told, sent
def _chain(*, intercepted):
"""The browser's favicon request, redirected once, in the engine's order:
a hop is finished BEFORE the next one is sent."""
out = []
for rid, url, came_from in (("FAV", "http://127.0.0.1/favicon.ico", None),
("FAV-redirect1", "http://127.0.0.1/icon.png", "FAV")):
params = {"requestId": rid, "url": url, "method": "GET", "frameId": "F1",
"isIntercepted": intercepted, "headers": []}
if came_from:
params["redirectedFrom"] = came_from
out += [("Network.requestWillBeSent", params),
("Network.responseReceived", {
"requestId": rid, "status": 302 if came_from is None else 200,
"statusText": "", "headers": []}),
("Network.requestFinished", {"requestId": rid})]
return out
def _deliver(page, events, *, held=False):
"""As the connection delivers: the session's lifecycle first, the page
after it. `held`: the page replays them only once the lifecycle has seen
the whole chain, as for the events a page holds at its birth."""
if held:
for method, params in events:
page.lifecycle.c.dispatch_event(method, params, "S1")
for method, params in events:
page._on_juggler_event(method, params)
return
for method, params in events:
page.lifecycle.c.dispatch_event(method, params, "S1")
page._on_juggler_event(method, params)
def _favicon_chain(page, *, intercepted, held=False):
_deliver(page, _chain(intercepted=intercepted), held=held)
def test_the_favicon_reaches_the_client_with_no_event():
"""B321: Playwright shows a client none of the favicon's events. Known bad:
without the favicon branch the client was told request, response and
requestFinished for both hops."""
page, told, _ = _favicon_page(intercepting=False)
_favicon_chain(page, intercepted=False)
assert told == []
assert page._requests == {} and page._request_log == []
def test_a_held_favicon_goes_to_the_network_and_to_no_route():
"""Upstream aborts it; a real Firefox asks the site for it, so it is let
through, unseen, instead (`invisible_core.juggler.favicon`)."""
page, told, sent = _favicon_page(intercepting=True)
_favicon_chain(page, intercepted=True)
assert "route" not in told and told == []
assert sent == [("Network.resumeInterceptedRequest", {"requestId": "FAV"}, "S1"),
("Network.resumeInterceptedRequest", {"requestId": "FAV-redirect1"}, "S1")]
def test_a_request_held_after_interception_went_off_is_released_without_blocking():
"""The other caller of the release: the engine held a request, and by its
event neither the page nor the context intercepts any more. It used to
`send` the release from the reader thread, the deadlock the favicon found."""
page, told, sent = _favicon_page(intercepting=False)
_deliver(page, [("Network.requestWillBeSent", {
"requestId": "R", "url": "http://127.0.0.1/data.json", "method": "GET",
"frameId": "F1", "isIntercepted": True, "headers": []})])
assert sent == [("Network.resumeInterceptedRequest", {"requestId": "R"}, "S1")]
assert told == ["request"]
def test_a_page_replaying_held_events_agrees_with_the_lifecycle():
"""The page replays the events it held at birth after the lifecycle has
seen the whole chain, finishes included. One memory, so the same answer."""
page, told, _ = _favicon_page(intercepting=False)
_favicon_chain(page, intercepted=False, held=True)
assert told == []
assert page.lifecycle.inflight == 0
def test_the_page_answers_with_the_lifecycles_memory_and_keeps_none():
"""Known bad: a page that classified requests on its own could disagree with
the lifecycle about one. Here the lifecycle and the page are handed the same
request id with different URLs, and the page must answer as the lifecycle
did, whatever its own copy of the event says."""
page, told, _ = _favicon_page(intercepting=False)
page.lifecycle.c.dispatch_event("Network.requestWillBeSent", {
"requestId": "X", "url": "http://127.0.0.1/favicon.ico"}, "S1")
page._on_juggler_event("Network.requestWillBeSent", {
"requestId": "X", "url": "http://127.0.0.1/data.json", "method": "GET",
"frameId": "F1", "isIntercepted": False, "headers": []})
assert told == []
# And a favicon URL the lifecycle has not seen is not hidden by the page.
page._on_juggler_event("Network.requestWillBeSent", {
"requestId": "Y", "url": "http://127.0.0.1/favicon.ico", "method": "GET",
"frameId": "F1", "isIntercepted": False, "headers": []})
assert told == ["request"]
def test_a_page_request_beside_the_favicon_is_still_reported():
page, told, _ = _favicon_page(intercepting=False)
_favicon_chain(page, intercepted=False)
_deliver(page, [("Network.requestWillBeSent", {
"requestId": "R", "url": "http://127.0.0.1/data.json", "method": "GET",
"frameId": "F1", "isIntercepted": False, "headers": []})])
assert told == ["request"]
def test_a_route_that_sends_a_navigation_on_tells_where_it_went():
"""B326: `route.fallback(url=...)` on a navigation. The engine applies the
URL as an internal redirect and says nothing, so the route tells the
request: its response is that URL's, and the lifecycle judges the commit
there. Known bad: the response kept the URL the request was sent with, and
`goto` refused the page as landed elsewhere."""
from invisible_playwright._juggler.server import RouteDispatcher
page, _told, _sent = _favicon_page(intercepting=True)
page.send = lambda command, params=None, timeout=None: {}
routed = "http://127.0.0.1/global-var.html"
_deliver(page, [("Network.requestWillBeSent", {
"requestId": "D", "url": "http://127.0.0.1/foo", "method": "GET",
"frameId": "F1", "navigationId": "NAV1", "isIntercepted": True,
"headers": []})])
request = page._requests["D"]
told_lifecycle = []
went_to = page.lifecycle.went_to
page.lifecycle.went_to = lambda nav, url: (told_lifecycle.append((nav, url)),
went_to(nav, url))
route = object.__new__(RouteDispatcher)
route.answered = False
route.request = request
route.dispose = lambda: None
route.op_continue({"url": routed})
assert request.url == routed
# What the lifecycle does with it is the core's own test
# (`test_a_goto_lands_where_it_went.py`); here, that it is told.
assert told_lifecycle == [("NAV1", routed)]
_deliver(page, [("Network.responseReceived", {
"requestId": "D", "status": 200, "statusText": "OK", "headers": []})])
assert request.response.initializer["url"] == routed
# The request keeps the URL it was sent with: the client applies the
# route's override to it on its side, as Playwright's does.
assert request.initializer["url"] == "http://127.0.0.1/foo"
# -- the e2e half: a real browser, and `.status` read off the answer ---------
PAGE = (b"<!doctype html><html><head><title>local</title></head>"
+76
View File
@@ -0,0 +1,76 @@
"""`route.abort()` with no code fails the request as Playwright's Firefox does (B325).
Measured 2026-10-17 with Playwright's own `test_should_not_chain_abort`, 10
runs out of 10: `page.goto` of an aborted navigation failed with
`NS_ERROR_ABORT`, where Playwright on Firefox says `NS_ERROR_FAILURE`.
Playwright's server sends `errorCode || "failed"` and the engine maps "failed"
to `NS_ERROR_FAILURE`; this server defaulted to "aborted". An error text is a
value a script reads.
"""
from __future__ import annotations
import http.server
import threading
from types import SimpleNamespace
import pytest
def _route():
from invisible_playwright._juggler.server import RouteDispatcher
sent = []
route = object.__new__(RouteDispatcher)
route.answered = False
route.request = SimpleNamespace(
request_id="R1",
page=SimpleNamespace(send=lambda command, params: sent.append((command, params))))
route.dispose = lambda: None
return route, sent
@pytest.mark.unit
def test_an_abort_with_no_code_is_failed():
route, sent = _route()
route.op_abort({})
assert sent == [("Network.abortInterceptedRequest",
{"errorCode": "failed", "requestId": "R1"})]
@pytest.mark.unit
def test_an_abort_with_a_code_keeps_it():
route, sent = _route()
route.op_abort({"errorCode": "aborted"})
assert sent[0][1]["errorCode"] == "aborted"
@pytest.mark.e2e
@pytest.mark.parametrize("code, text", [(None, "NS_ERROR_FAILURE"), ("aborted", "NS_ERROR_ABORT")])
def test_an_aborted_navigation_fails_with_the_engines_word_for_the_code(firefox_binary, code, text):
from invisible_playwright import InvisiblePlaywright
class H(http.server.BaseHTTPRequestHandler):
def do_GET(self):
body = b"<!doctype html><title>e</title>"
self.send_response(200)
self.send_header("Content-Type", "text/html")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *a):
pass
srv = http.server.ThreadingHTTPServer(("127.0.0.1", 0), H)
srv.daemon_threads = True
threading.Thread(target=srv.serve_forever, daemon=True).start()
try:
with InvisiblePlaywright(binary_path=firefox_binary, headless=True) as browser:
page = browser.new_page()
page.route("**/empty.html",
lambda route: route.abort() if code is None else route.abort(code))
with pytest.raises(Exception) as caught:
page.goto("http://127.0.0.1:%d/empty.html" % srv.server_address[1])
finally:
srv.shutdown()
assert text in str(caught.value), str(caught.value)
+12 -8
View File
@@ -5,8 +5,9 @@ every POST, including a page `fetch()` with a JSON body, both inside a context
route handler and on the `request` event fired for the same request. The
engine's `NetworkObserver.js` sent `postData: undefined` for every request
(feder-cr/invisible_core#90), so a route guard could check a POST's URL and
never its body. The engine now reads the body while interception is on for
the page or its context.
never its body. From 2026-10-03 the engine read the body while interception
was on for the page or its context; from firefox-49 it reads it always, as
Playwright's does, so `request.post_data` holds without a route too.
"""
from __future__ import annotations
@@ -99,11 +100,14 @@ def test_a_routed_post_carries_its_body(firefox_binary, where):
@pytest.mark.e2e
def test_without_a_route_the_engine_does_not_copy_the_body(firefox_binary):
"""The other half of the contract: the engine reads a POST body only
while interception is on, so a session with no route keeps the saving the
2026-08-24 engine change was made for, and the body still reaches the
server whole."""
def test_without_a_route_the_request_still_carries_its_body(firefox_binary):
"""The other half of the contract, which changed with firefox-49: with no
route at all the request event still carries the POST body, as
Playwright's does, and reading it leaves the upload whole.
Until firefox-48 the engine read a body only while interception was on, so
this asserted `None`; that answered like a form sent empty, and nothing
said so. The owner chose upstream's behaviour on 2026-10-16."""
from invisible_playwright import InvisiblePlaywright
srv, url, received = _serve()
@@ -121,5 +125,5 @@ def test_without_a_route_the_engine_does_not_copy_the_body(firefox_binary):
finally:
srv.shutdown()
sent = json.dumps(BODY, separators=(",", ":"), ensure_ascii=False)
assert on_event == [None], on_event
assert on_event == [sent], on_event
assert received == [sent.encode()], received
@@ -0,0 +1,63 @@
"""A route that sends a navigation to another URL lands there (B326).
Measured 2026-10-17 with Playwright's own `test_should_override_request_url`,
10 runs out of 10, page and context: `route.fallback(url=...)` on a document
request made `goto` raise "reported committed on .../target, which is not
where it went (.../asked)", and the response kept the URL the request was sent
with. The engine applies a route's URL as an internal redirect and sends no
event of it; the route tells the request (`RequestDispatcher.continued_at`),
which tells the lifecycle where the navigation went.
"""
from __future__ import annotations
import http.server
import threading
import pytest
pytestmark = pytest.mark.e2e
def _site():
seen = []
class H(http.server.BaseHTTPRequestHandler):
def do_GET(self):
seen.append(self.path)
body = (b"<!doctype html><title>target</title><script>window.landed = 'target'</script>"
if self.path == "/target" else b"<!doctype html><title>asked</title>")
self.send_response(200)
self.send_header("Content-Type", "text/html")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *a):
pass
srv = http.server.ThreadingHTTPServer(("127.0.0.1", 0), H)
srv.daemon_threads = True
threading.Thread(target=srv.serve_forever, daemon=True).start()
return srv, seen
@pytest.mark.parametrize("how", ["fallback", "continue"])
def test_a_navigation_a_route_sends_elsewhere_lands_there(firefox_binary, how):
from invisible_playwright import InvisiblePlaywright
srv, seen = _site()
base = "http://127.0.0.1:%d" % srv.server_address[1]
try:
with InvisiblePlaywright(binary_path=firefox_binary, headless=True) as browser:
page = browser.new_page()
if how == "fallback":
page.route("**/asked", lambda route: route.fallback(url=base + "/target"))
else:
page.route("**/asked", lambda route: route.continue_(url=base + "/target"))
response = page.goto(base + "/asked")
assert response is not None
assert response.url == base + "/target", response.url
assert page.evaluate("() => window.landed") == "target"
finally:
srv.shutdown()
assert "/target" in seen and "/asked" not in seen, seen
@@ -18,10 +18,11 @@ just a wrong answer that a caller builds its next decision on. The three
letters only have to appear inside a longer word, so MARGIN, LARGE and CHARGE
are all affected.
⛔ AND THE FIRST TEST HERE IS NOT ABOUT THE DEFECT. `op_evaluate` runs in the
MAIN world, as the page, which is the one place in this file that deliberately
leaves the utility world. That makes the emitted script something a site can
look at, so a change to its SHAPE is a stealth change even when it is a
⛔ AND THE FIRST TEST HERE IS NOT ABOUT THE DEFECT. `op_evaluate` runs the
caller's code, the one thing this server deliberately runs outside the utility
world, and a site can still look at it: a function the caller hands to the
page shows its source to the page's toString. That makes the emitted script
something a site can look at, so a change to its SHAPE is a stealth change even when it is a
correctness fix. The script is pinned byte for byte against what shipped
before: for an expression that never spelled the placeholder, this fix must
produce exactly the same characters, and that is what the first test proves.
@@ -0,0 +1,134 @@
"""The caller's code runs in a world of its own, where a page that replaced a
standard API cannot count its calls [B322].
Until firefox-49 `page.evaluate` ran in the page's own realm, so a call to a
standard API went through whatever the page had put in its place. A Cloudflare
challenge wraps `Document.prototype.querySelector` in a Proxy, and one lookup
of its token field from an evaluate got the clearance refused on the reload,
11 pairs out of 11. The caller's code now runs in the caller's world
(invisible-core's `evaluate_in_caller`): a name the standard defines is the
native one, every other name is the page's. These tests hold both halves on
a page that counts every call to the APIs it wrapped, and the one change the
rule declares.
"""
from __future__ import annotations
import pytest
PAGE = """<!doctype html><html><head><script>
window.__calls = 0;
function wrap(owner, name) {
const real = owner[name];
Object.defineProperty(owner, name, {configurable: true, writable: true,
value: new Proxy(real, {apply(t, self, args) {
window.__calls++; return Reflect.apply(t, self, args); }})});
}
wrap(Document.prototype, 'querySelector');
wrap(Document.prototype, 'querySelectorAll');
wrap(Element.prototype, 'querySelector');
wrap(Document.prototype, 'getElementById');
wrap(Array.prototype, 'map');
wrap(JSON, 'stringify');
window.__APP = {ready: true};
function pageFn(x) { return x * 2; }
class Point { constructor(x) { this.x = x; } toString() { return 'P' + this.x; } }
window.pt = new Point(3);
const pageConst = 'c';
window.pageRead = (n) => window[n];
</script></head><body>
<form><input name="cf-turnstile-response" value="tok"></form><div id="x">here</div>
<script>document.getElementById('x').__vue__ = {msg: 'hi'}; window.__calls = 0;</script>
</body></html>"""
@pytest.fixture
def page(firefox_binary):
from invisible_playwright import InvisiblePlaywright
with InvisiblePlaywright(seed=42, binary_path=firefox_binary,
humanize=False, headless=True) as browser:
page = browser.new_context().new_page()
page.set_default_timeout(5000)
page.set_content(PAGE)
yield page
def _calls(page):
# a data property of the page: reading it runs none of the page's code
return page.evaluate("() => window.__calls")
@pytest.mark.e2e
def test_the_token_field_is_found_without_the_page_counting(page):
assert page.evaluate(
"() => document.querySelector('input[name=\"cf-turnstile-response\"]').value") == "tok"
assert page.evaluate(
"() => [...document.querySelectorAll('input')].map(i => i.name)") == [
"cf-turnstile-response"]
assert page.evaluate("() => JSON.stringify(document.getElementById('x').id)") == '"x"'
assert _calls(page) == 0
@pytest.mark.e2e
def test_the_waits_and_the_handles_are_not_counted_either(page):
page.wait_for_function("() => document.querySelector('#x')")
handle = page.evaluate_handle("() => document.body.querySelector('#x')")
assert handle.as_element().text_content() == "here"
assert page.eval_on_selector("#x", "el => el.ownerDocument.querySelector('#x').id") == "x"
assert _calls(page) == 0
@pytest.mark.e2e
def test_what_the_page_added_is_the_pages(page):
assert page.evaluate("() => window.__APP.ready") is True
assert page.evaluate("() => pageFn(21)") == 42
assert page.evaluate("() => document.getElementById('x').__vue__.msg") == "hi"
# a top-level class or const of a page script is a binding of the page's
# global scope, not a property of its window: a bare name finds it, as in
# the page, and `window.pageConst` does not
assert page.evaluate("() => pt instanceof Point") is True
assert page.evaluate("() => pageConst") == "c"
assert page.evaluate("() => window.pageConst === undefined") is True
page.evaluate("() => { window.written = 5; }")
assert page.evaluate("() => pageRead('written')") == 5
@pytest.mark.e2e
def test_the_callers_code_on_an_element_sees_what_the_page_put_on_it(page):
"""`eval_on_selector`, `locator.evaluate`, `handle.evaluate` and
`eval_on_selector_all` are the caller's code too: until firefox-49 they ran
behind the utility world's plain Xray, where `el.__vue__` is undefined."""
assert page.eval_on_selector("#x", "el => el.__vue__.msg") == "hi"
assert page.locator("#x").evaluate("el => el.__vue__.msg") == "hi"
assert page.query_selector("#x").evaluate("(el, k) => el.__vue__[k]", "msg") == "hi"
assert page.eval_on_selector_all("div", "els => els.map(e => !!e.__vue__)") == [True]
assert _calls(page) == 0
@pytest.mark.e2e
def test_the_rule_goes_level_by_level_of_the_pages_chain(page):
"""A standard name is the native one on the browser's own objects, even
where the page replaced it on the object itself; on what the page created
(a class, its instances) the page's definition wins, as it does in the
page: `String(pt)` is the class's `toString`."""
# the page's own code: a replacement on `document` itself
page.add_script_tag(content="""
const realQs = Document.prototype.querySelector;
document.querySelector = new Proxy(realQs, {apply(t, self, args) {
window.__calls++; return Reflect.apply(t, self, args); }});""")
assert page.evaluate("() => document.querySelector('#x').id") == "x"
assert _calls(page) == 0
assert page.evaluate("() => String(pt)") == "P3"
@pytest.mark.e2e
def test_what_the_caller_hands_the_page_has_the_pages_own_prototypes(page):
"""An object the caller's code hands the page keeps its identity and its
own properties, but its standard prototypes are the page's own: through a
plain transparent wrapper the page saw an object of another realm, and a
callback's constructor compiled code in the caller's world."""
page.add_script_tag(content="""
window.probe = (a, f) => [a instanceof Array, a.map === Array.prototype.map,
f.constructor === Function,
f.constructor('return globalThis')() === window];""")
assert page.evaluate("() => probe([1, 2], () => 1)") == [True, True, True, True]
+41 -10
View File
@@ -25,17 +25,17 @@ class _Injected:
self.answers = list(answers)
self.calls = []
def evaluate_in_main(self, frame_id, expression, *, by_value=True, timeout=30.0,
repeatable=False):
self.calls.append(("evaluate_in_main", by_value))
def evaluate_in_caller(self, frame_id, expression, *, by_value=True, timeout=30.0,
repeatable=False):
self.calls.append(("evaluate_in_caller", by_value))
self.repeatable = repeatable
answer = self.answers.pop(0)
if isinstance(answer, BaseException):
raise answer
return answer
def poll_in_main(self, frame_id, expression, *, timeout=30.0):
self.calls.append(("poll_in_main", None))
def poll_in_caller(self, frame_id, expression, *, timeout=30.0):
self.calls.append(("poll_in_caller", None))
answer = self.answers.pop(0)
if isinstance(answer, BaseException):
raise answer
@@ -49,6 +49,27 @@ class _Injected:
self.calls.append(("read_all", what))
return ["a", "b"]
def query_selector_all(self, frame_id, selector):
self.calls.append(("query_selector_all", selector))
return ["u1", "u2"]
def caller_context(self, frame_id):
return "caller-ctx"
def node_to_caller(self, frame_id, element):
self.calls.append(("node_to_caller", element))
return "c-" + element
def call_raw(self, context, declaration, args, *, by_value=False, timeout=30.0):
self.calls.append(("call_raw", (context, [a.get("objectId") for a in args])))
return {"value": 2}
def release(self, context, object_id):
self.calls.append(("release", object_id))
def dispose(self, frame_id, object_id):
self.calls.append(("dispose", object_id))
def _frame(injected):
frame = server.FrameDispatcher.__new__(server.FrameDispatcher)
@@ -62,21 +83,31 @@ def test_a_poll_goes_on_through_a_world_that_went(monkeypatch):
monkeypatch.setattr(server, "ElementHandleDispatcher",
lambda *a, **k: SimpleNamespace(channel="handle"))
# A turn whose world went, then a falsy turn, then a truthy one. Each turn
# sends the caller's code ONCE (`poll_in_main`, [B323]): the truthy value
# sends the caller's code ONCE (`poll_in_caller`, [B323]): the truthy value
# is already the handle, and nothing runs the predicate again to get one.
injected = _Injected([ContextDestroyed("Execution context was destroyed"),
None, {"objectId": "oid", "type": "object"}])
answer = _frame(injected).op_wait_for_function(
{"expression": "() => window.ready", "isFunction": True, "timeout": 5000})
assert answer == {"handle": "handle"}
assert [c for c, _ in injected.calls] == ["poll_in_main"] * 3
assert [c for c, _ in injected.calls] == ["poll_in_caller"] * 3
def test_eval_on_selector_all_sends_the_callers_function_once():
def test_eval_on_selector_all_sends_the_callers_function_once_in_its_world():
"""The elements are this package's read; the caller's function runs ONCE
([B285]), in the caller's world, on the same nodes carried there ([B322]),
and the copies and the reads are released after it."""
injected = _Injected([])
_frame(injected).op_eval_on_selector_all(
answer = _frame(injected).op_eval_on_selector_all(
{"selector": "li", "expression": "els => els.length", "isFunction": True})
assert injected.calls == [("call", {"repeatable": False})]
assert answer == {"value": {"n": 2}}
assert injected.calls == [
("query_selector_all", "li"),
("node_to_caller", "u1"), ("node_to_caller", "u2"),
("call_raw", ("caller-ctx", [None, "c-u1", "c-u2"])),
("release", "c-u1"), ("release", "c-u2"),
("dispose", "u1"), ("dispose", "u2"),
]
def test_the_librarys_read_of_every_match_is_the_cores_repeatable_read():
@@ -0,0 +1,92 @@
"""The browser's favicon request reaches the site, and nothing of it reaches the
client (B321).
Measured 2026-10-16 on 0.36.0: a `page.route("**/*")` handler saw
`GET /favicon.ico` in 3 runs out of 6, which is what made Playwright's own
`test_should_amend_post_data` red now and then. Playwright never shows a client
the favicon: no `request`, `response`, `requestfinished` or `requestfailed`, no
route handler, and it is not one of the requests `networkidle` waits on. It
also aborts it when a route is on; a real Firefox always asks the site for its
favicon, so here it is let through instead (`invisible_core.juggler.favicon`).
The site HOLDS the favicon's answer until the test has its verdict, so the
proof does not lean on timing: were the favicon a request in flight,
`networkidle` could not arrive while it is held.
"""
from __future__ import annotations
import http.server
import threading
import pytest
pytestmark = pytest.mark.e2e
PAGE = b"<!doctype html><html><head><title>f</title></head><body>f</body></html>"
def _site():
seen, arrived, release = [], threading.Event(), threading.Event()
class H(http.server.BaseHTTPRequestHandler):
def do_GET(self):
seen.append(self.path)
if self.path == "/favicon.ico":
arrived.set()
release.wait(60)
body, ctype = b"\x00\x00\x01\x00", "image/x-icon"
else:
body, ctype = PAGE, "text/html"
self.send_response(200)
self.send_header("Content-Type", ctype)
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *a):
pass
srv = http.server.ThreadingHTTPServer(("127.0.0.1", 0), H)
srv.daemon_threads = True
threading.Thread(target=srv.serve_forever, daemon=True).start()
return srv, seen, arrived, release
@pytest.mark.parametrize("routed", [False, True], ids=["no-route", "route-on-everything"])
def test_the_favicon_goes_to_the_site_and_nothing_of_it_to_the_client(firefox_binary, routed):
from invisible_playwright import InvisiblePlaywright
srv, seen, arrived, release = _site()
url = "http://127.0.0.1:%d/" % srv.server_address[1]
told, routes = [], []
try:
with InvisiblePlaywright(binary_path=firefox_binary, headless=True) as browser:
page = browser.new_page()
for event in ("request", "response", "requestfinished", "requestfailed"):
page.on(event, lambda r, event=event: told.append((event, r.url)))
if routed:
page.route("**/*", lambda route: (routes.append(route.request.url),
route.continue_()))
page.goto(url)
# The favicon is asked for after the document; it is the precondition.
assert arrived.wait(30), ("the browser never asked for the favicon", seen)
# Held by the site, it is still not a request in flight.
page.wait_for_load_state("networkidle", timeout=30000)
# ⛔ And the session still answers. Letting the held favicon through
# with a `send` from the reader thread blocked that thread for good,
# and nothing above noticed: networkidle reaches the client from
# the lifecycle's timer, not from the reader. A round trip to the
# engine does need the reader.
page.wait_for_function("() => document.title === 'f'", timeout=10000)
release.set()
page.wait_for_timeout(500)
finally:
release.set()
srv.shutdown()
assert "/favicon.ico" in seen, seen
assert not [t for t in told if t[1].endswith("/favicon.ico")], told
assert not [u for u in routes if u.endswith("/favicon.ico")], routes
# And the page's own document is still reported, and routed when asked.
assert ("request", url) in told, told
if routed:
assert url in routes, routes