fix: a screenshot refuses what Playwright does by modifying the page: mask, style, animations="disabled", caret="initial"
PageDispatcher.op_screenshot never read these parameters, so the call succeeded with a picture that ignored them. It now refuses each by name with what to do instead, and answers Firefox's own `Not implemented` for omitBackground with png (jpeg is a no-op, as in stock). caret="hide" and an absent caret are served: the engine never draws the caret, which is what stock's default produces. The element's and a locator's screenshot reach the same call. The sentences are declared by (operation, parameter) in perimeter.REFUSED_PARAMETERS and raised through _refuse_parameter, which the declared-refusals test holds to that table both ways.
This commit is contained in:
1 parent
020fe74328
commit
3b362bab4b
2 files changed
+66
-1
No files matched your search
@@ -215,3 +215,45 @@ def refusal(operation):
|
||||
"invisible_playwright does not implement: the package covers the "
|
||||
"automation core, and " + feature + " is outside it by decision, "
|
||||
"not by omission. See 32-stacco-da-playwright.md section 5.4.")
|
||||
|
||||
|
||||
#: ⛔ A PARAMETER OF A SERVED OPERATION THAT IS REFUSED, keyed by (operation, parameter), and the sentence a caller reads.
|
||||
#: The operations above are refused whole; these are refused one parameter (or one value of it) at a time, and the call
|
||||
#: without them is served. They are raised in `server.py` by `_refuse_parameter(operation, parameter)`, the one function
|
||||
#: that reads this table, and `tests/test_every_refusal_is_declared.py` holds the two sides to each other.
|
||||
#:
|
||||
#: ⛔ WHY THESE FIVE. Stock Playwright honours `mask`, `style` and `animations="disabled"` by MODIFYING THE PAGE (an overlay,
|
||||
#: an injected `<style>`, animations finished or cancelled) before the picture and putting it back after. This package does
|
||||
#: not touch a page to photograph it, and until now it did not read them either: the call succeeded and the picture was as
|
||||
#: if they had not been written, which a caller cannot see. `caret="initial"` asks for the text caret to be drawn, and the
|
||||
#: engine never draws it (the capture does not set the flag that draws it), so the picture it takes is the one `"hide"`
|
||||
#: asks for, which is also Playwright's default: `"hide"` and an absent `caret` are served. `omitBackground` with png is
|
||||
#: Firefox's own `Not implemented` in stock (`FFPage.setBackgroundColor`), word for word; with jpeg stock does nothing and
|
||||
#: neither do we.
|
||||
REFUSED_PARAMETERS = {
|
||||
("screenshot", "mask"):
|
||||
"screenshot(mask=...) is not served: Playwright covers the masked elements by modifying the page (an overlay is "
|
||||
"put on it before the picture), and this package does not touch a page to take a picture. maskColor goes with "
|
||||
"mask and is refused with it. Hide the elements yourself before the screenshot (for example set their "
|
||||
"visibility to hidden in your own script) and restore them after.",
|
||||
("screenshot", "style"):
|
||||
"screenshot(style=...) is not served: Playwright applies it by modifying the page (a <style> element is "
|
||||
"injected before the picture and removed after), and this package does not touch a page to take a picture. Add "
|
||||
"the style yourself with page.add_style_tag() before the screenshot and remove the element it returns after.",
|
||||
("screenshot", "animations"):
|
||||
'screenshot(animations="disabled") is not served: Playwright does it by modifying the page (the finite '
|
||||
"animations are finished and the infinite ones cancelled), and this package does not touch a page to take a "
|
||||
"picture. Wait for the animations to end, or pause them in your own script (document.getAnimations()), before "
|
||||
'the screenshot. animations="allow" is what is served.',
|
||||
("screenshot", "caret"):
|
||||
'screenshot(caret="initial") is not served: it asks for the text caret to be drawn in the picture, and the '
|
||||
'engine never draws it (the picture is the one caret="hide" asks for, which is the default of Playwright). Leave '
|
||||
'caret out or pass "hide".',
|
||||
("screenshot", "omitBackground"):
|
||||
"Not implemented",
|
||||
}
|
||||
|
||||
|
||||
def parameter_refusal(operation, parameter):
|
||||
"""The sentence for a refused (operation, parameter): `KeyError` for one that is not declared."""
|
||||
return REFUSED_PARAMETERS[(operation, parameter)]
|
||||
@@ -47,7 +47,7 @@ from invisible_core.juggler import PageActs, popup_number
|
||||
from invisible_core.juggler import connection as juggler
|
||||
from invisible_core.juggler.actions import Actions
|
||||
from invisible_core.juggler.deadline import Deadline
|
||||
from . import _bindings, dialogs
|
||||
from . import _bindings, dialogs, perimeter
|
||||
from ._reaped import SessionRemoval
|
||||
from ._threads import ThreadStarterLease
|
||||
from .pointer import Pointer
|
||||
@@ -676,6 +676,14 @@ def _run_callers_code(injected: InjectedScript, frame_id: str, params: Dict,
|
||||
argument.release()
|
||||
|
||||
|
||||
def _refuse_parameter(operation: str, parameter: str):
|
||||
"""Refuse one parameter of a served operation with the sentence `perimeter.REFUSED_PARAMETERS` holds for it.
|
||||
|
||||
⛔ THE ONLY WAY A PARAMETER IS REFUSED, so that the inventory and the code cannot drift: the test of the refusals reads
|
||||
every call of this function in the file and holds it to that table, both ways."""
|
||||
raise ProtocolException(perimeter.parameter_refusal(operation, parameter))
|
||||
|
||||
|
||||
def _round_px(value: float) -> int:
|
||||
"""To the nearest whole pixel, halves up (Python's `round` goes to even: 0.5 -> 0, 1.5 -> 2)."""
|
||||
import math
|
||||
@@ -4477,6 +4485,21 @@ class PageDispatcher(Dispatcher):
|
||||
# A clip the CALLER supplied is passed through untouched. Playwright
|
||||
# documents it in page coordinates, which is what the engine wants, so
|
||||
# there is nothing to translate.
|
||||
# ⛔ WHAT STOCK DOES BY MODIFYING THE PAGE IS REFUSED, NOT IGNORED. `mask`, `style` and `animations="disabled"` change the
|
||||
# page before the picture in Playwright; this server took them without reading them, and the picture came back as if they
|
||||
# had not been written. `caret="initial"` asks for the text caret to be drawn, which the engine never does. `omitBackground`
|
||||
# with png is Firefox's own `Not implemented` (stock reaches it only for png). The element's screenshot comes through here
|
||||
# with the caller's parameters, so this is the one place; the sentences are `perimeter.REFUSED_PARAMETERS`'.
|
||||
if params.get("mask"):
|
||||
_refuse_parameter("screenshot", "mask")
|
||||
if params.get("style"):
|
||||
_refuse_parameter("screenshot", "style")
|
||||
if params.get("animations") == "disabled":
|
||||
_refuse_parameter("screenshot", "animations")
|
||||
if params.get("caret") == "initial":
|
||||
_refuse_parameter("screenshot", "caret")
|
||||
if params.get("omitBackground") and params.get("type") != "jpeg":
|
||||
_refuse_parameter("screenshot", "omitBackground")
|
||||
clip = params.get("clip")
|
||||
if not clip:
|
||||
box = self.injected.evaluate(
|
||||
|
||||
Reference in new issue
Block a user