ElementHandle pointer actions walk onto the element the way selector actions do, one hand for every door
click, dblclick, hover, tap, check and uncheck (and so set_checked) of an ElementHandle called the core's actions directly: with no client cursor the approach is one mousemove onto the exact centre of the quad and a press there, while the selector actions go through Frame._by_hand / Pointer.act (a drawn path, a landing point of the session's own). The handle now goes through the same _by_hand with element=<its object id>: Pointer.act aims at that node (no selector looked up, the handle not disposed), and trial/force/strict/position/modifiers are read as before. The keyboard and text actions (fill, type, press, focus, selectText, setInputFiles) already end in the same core action as their selector twins and are unchanged. The comment that said a handle click was the humanised pointer is now true. Version 0.59.1.
This commit is contained in:
1 parent
292d86a15a
commit
8bcc2a9ca1
4 files changed
+80
-36
No files matched your search
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.59.1] - 2026-11-25
|
||||
|
||||
### Changed
|
||||
- ElementHandle pointer actions (`click`, `dblclick`, `hover`, `tap`, `check`, `uncheck`, `set_checked`) now use the same humanised pointer walk as selector actions (they used to jump to the exact centre of the element in one move).
|
||||
|
||||
## [0.59.0] - 2026-11-24
|
||||
|
||||
### Changed
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "invisible_playwright"
|
||||
version = "0.59.0"
|
||||
version = "0.59.1"
|
||||
description = "Playwright wrapper for a patched Firefox with deterministic stealth profile."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.11"
|
||||
|
||||
@@ -22,9 +22,12 @@ used to answer, carried over unchanged):
|
||||
* NOT `Mouse.move`: an explicit move is the caller's. (The in-process client
|
||||
marks its own with `humanise`, see `_cursor._wrap_mouse_move`; a client that
|
||||
does not say so is answered with exactly the point it named.)
|
||||
* NOT the actions of an ElementHandle (they name a node, never a selector, and
|
||||
the in-process client never walked onto them either) and NOT `dragAndDrop`,
|
||||
whose travel the core's `Actions` already draws.
|
||||
* `ElementHandle.click / dblclick / hover / tap / check / uncheck` (and so
|
||||
`set_checked`): the same walk, onto the node the handle already names
|
||||
(`act(..., element=)`: the node is not looked up again and is not disposed).
|
||||
One click path is one fingerprint, so a handle click and a selector click
|
||||
arrive as the same kind of stroke;
|
||||
* NOT `dragAndDrop`, whose travel the core's `Actions` already draws.
|
||||
|
||||
HOW IT STAYS THE SAME AS THE CLIENT WAS. The stroke generator, the planners
|
||||
(`_behaviour`) and the discipline events are delivered under (`Pacer`) are the
|
||||
@@ -391,9 +394,14 @@ class Pointer:
|
||||
|
||||
# -- the probes --------------------------------------------------------
|
||||
|
||||
def _element_box(self, frame_id: str, selector: str) -> Tuple[Optional[str], Optional[dict]]:
|
||||
def _element_box(self, frame_id: str, selector: str,
|
||||
element: Optional[str] = None) -> Tuple[Optional[str], Optional[dict]]:
|
||||
"""Resolve the element and its box, or (None, None). Never raises.
|
||||
|
||||
``element`` is a node the caller already holds (an ElementHandle's): it is
|
||||
measured as it is, never looked up again from ``selector``, and it is not
|
||||
ours to dispose.
|
||||
|
||||
Deliberately non-blocking and deliberately forgiving: this is a hint
|
||||
used to aim a mouse path, never a correctness step. It resolves the
|
||||
element if it is already there and gives up otherwise, so it can
|
||||
@@ -401,6 +409,12 @@ class Pointer:
|
||||
failing one - the action itself still does its own waiting and raises
|
||||
its own errors.
|
||||
"""
|
||||
if element is not None:
|
||||
try:
|
||||
box = self.injected.bounding_box(frame_id, element)
|
||||
except _PROBE_ERRORS:
|
||||
return None, None # the handle's node is gone: the action meets that itself
|
||||
return (element, box) if box else (None, None)
|
||||
try:
|
||||
handle = self.injected.query_selector(frame_id, selector)
|
||||
except _PROBE_ERRORS:
|
||||
@@ -442,10 +456,11 @@ class Pointer:
|
||||
return False
|
||||
|
||||
def _choose_landing(self, frame_id: str, selector: str,
|
||||
position: Optional[dict]) -> Optional[_Aim]:
|
||||
position: Optional[dict],
|
||||
element: Optional[str] = None) -> Optional[_Aim]:
|
||||
"""Pick the point on the element this action will land on."""
|
||||
hand = self.hand
|
||||
handle, box = self._element_box(frame_id, selector)
|
||||
handle, box = self._element_box(frame_id, selector, element)
|
||||
if handle is None or box is None:
|
||||
return None
|
||||
try:
|
||||
@@ -476,7 +491,8 @@ class Pointer:
|
||||
return _Aim(box, (box["x"] + box["width"] / 2.0,
|
||||
box["y"] + box["height"] / 2.0), None)
|
||||
finally:
|
||||
self._dispose(frame_id, handle)
|
||||
if element is None: # a node the caller holds stays the caller's
|
||||
self._dispose(frame_id, handle)
|
||||
|
||||
# -- travelling --------------------------------------------------------
|
||||
|
||||
@@ -582,7 +598,8 @@ class Pointer:
|
||||
# -- the entry points --------------------------------------------------
|
||||
|
||||
def approach(self, frame_id: str, selector: str, position: Optional[dict],
|
||||
trial: bool = False) -> Optional[Dict[str, float]]:
|
||||
trial: bool = False,
|
||||
element: Optional[str] = None) -> Optional[Dict[str, float]]:
|
||||
"""Walk the pointer onto the element this action is about to touch.
|
||||
|
||||
Returns the `position` the action should run with, or None.
|
||||
@@ -598,7 +615,7 @@ class Pointer:
|
||||
hand.busy = True
|
||||
hand.action += 1
|
||||
try:
|
||||
aim = self._choose_landing(frame_id, selector, position)
|
||||
aim = self._choose_landing(frame_id, selector, position, element)
|
||||
if aim is None:
|
||||
return None
|
||||
w, h = self._viewport()
|
||||
@@ -614,9 +631,12 @@ class Pointer:
|
||||
|
||||
def act(self, frame_id: str, selector: str, position: Optional[dict],
|
||||
timeout: Optional[float], run: Callable[[Optional[dict], Optional[float]], Any],
|
||||
*, trial: bool = False) -> Any:
|
||||
*, trial: bool = False, element: Optional[str] = None) -> Any:
|
||||
"""Run a pointer action on an element the way a hand would.
|
||||
|
||||
``element`` is the object id of a node the caller already holds (an
|
||||
ElementHandle): the walk aims at THAT node and `selector` is not looked up.
|
||||
|
||||
`run(position, timeout)` performs the plain action with those two
|
||||
arguments. The approach comes first; if it chose a landing point the
|
||||
action is told to click it, within a bounded slice of the caller's
|
||||
@@ -626,7 +646,7 @@ class Pointer:
|
||||
"""
|
||||
override = None
|
||||
try:
|
||||
override = self.approach(frame_id, selector, position, trial)
|
||||
override = self.approach(frame_id, selector, position, trial, element)
|
||||
except _PROBE_ERRORS as exc: # motion never fails an action for what the engine or the page answers; a bug of ours is not that
|
||||
_cursor._warn_once(
|
||||
"approach-failed",
|
||||
|
||||
@@ -1123,17 +1123,24 @@ class ElementHandleDispatcher(Dispatcher):
|
||||
# `page.query_selector(...).click()` is ordinary code - and the rest keep
|
||||
# reporting themselves as missing rather than being filled in for symmetry.
|
||||
#
|
||||
# ⛔ THEY GO THROUGH THE SAME `actions` AS THE SELECTOR VERSIONS, and that is
|
||||
# the whole design. `click` here is the humanised pointer: approach, hover,
|
||||
# press, release, with the hit-target check and the actionability retry. A
|
||||
# second, simpler path would be quicker to write and would give this package
|
||||
# two click behaviours with two fingerprints, which is the one thing it
|
||||
# exists not to have.
|
||||
# ⛔ THEY GO THROUGH THE SAME `actions` AND THE SAME HAND AS THE SELECTOR
|
||||
# VERSIONS, and that is the whole design. The pointer actions (click,
|
||||
# dblclick, hover, tap, check, uncheck) are drawn by `FrameDispatcher._by_hand`
|
||||
# (`Pointer.act`): a path onto the element, a landing point of the session's
|
||||
# own, and then the core's action with the hit-target check and the
|
||||
# actionability retry. They used to call `actions` directly, and the core's
|
||||
# approach with no client cursor is ONE `mousemove` onto the exact centre of the
|
||||
# element's box and a press there: a handle click was a jump to the centre where
|
||||
# the selector's was a walk, two click behaviours with two fingerprints, which
|
||||
# is the one thing this package exists not to have.
|
||||
#
|
||||
# What differs from a selector click is exactly what SHOULD differ: the node
|
||||
# is not looked up again, because a handle names one node and re-querying
|
||||
# would find a different element with the same description; and the node is
|
||||
# not disposed afterwards, because the caller still holds it.
|
||||
# would find a different element with the same description (the hand aims at
|
||||
# the handle's own object, `element=`); and the node is not disposed
|
||||
# afterwards, because the caller still holds it. The keyboard and text
|
||||
# actions (fill, type, press, focus, selectText, setInputFiles) have no hand to
|
||||
# draw: their rhythm lives in the core's action, which both doors call.
|
||||
#
|
||||
# The parameter helpers are the frame's. `self.frame._timeout` rather than a
|
||||
# copy: the rules for reading a timeout, a position and the pointer flags out
|
||||
@@ -1151,29 +1158,37 @@ class ElementHandleDispatcher(Dispatcher):
|
||||
"element_id": self.object_id,
|
||||
**self.frame._act_opts(params)}
|
||||
|
||||
def _by_hand(self, params: Dict, run: Callable[[Any, Any], Any]) -> Any:
|
||||
"""A pointer action of THIS node with the session's hand in front of it: the Frame's own (`FrameDispatcher._by_hand`, the one
|
||||
walk), aimed at the handle's object and not at a selector. `run(position, timeout)` is the plain action; it takes the position
|
||||
and the timeout the hand chose, and everything else from `_act_args`."""
|
||||
return self.frame._by_hand(params, self.frame.frame_id, _HANDLE, run, element=self.object_id)
|
||||
|
||||
def op_click(self, params: Dict) -> Any:
|
||||
self.frame._waiting_after(params, lambda: self.frame.actions.click(
|
||||
_HANDLE, position=self.frame._position(params),
|
||||
**self.frame._pointer(params), **self._act_args(params)))
|
||||
pointer = self.frame._pointer(params)
|
||||
self.frame._waiting_after(params, lambda: self._by_hand(
|
||||
params, lambda position, timeout: self.frame.actions.click(
|
||||
_HANDLE, **{**self._act_args(params), "timeout": timeout},
|
||||
position=position, **pointer)))
|
||||
return None
|
||||
|
||||
def op_hover(self, params: Dict) -> Any:
|
||||
self.frame.actions.hover(_HANDLE, position=self.frame._position(params),
|
||||
**self._act_args(params))
|
||||
self._by_hand(params, lambda position, timeout: self.frame.actions.hover(
|
||||
_HANDLE, **{**self._act_args(params), "timeout": timeout}, position=position))
|
||||
return None
|
||||
|
||||
def op_dblclick(self, params: Dict) -> Any:
|
||||
pointer = self.frame._pointer(params)
|
||||
# dblclick sets its own clickCount; the caller's is not a second one.
|
||||
pointer.pop("clicks", None)
|
||||
self.frame.actions.dblclick(
|
||||
_HANDLE, position=self.frame._position(params), **pointer,
|
||||
**self._act_args(params))
|
||||
self._by_hand(params, lambda position, timeout: self.frame.actions.dblclick(
|
||||
_HANDLE, **{**self._act_args(params), "timeout": timeout},
|
||||
position=position, **pointer))
|
||||
return None
|
||||
|
||||
def op_tap(self, params: Dict) -> Any:
|
||||
self.frame.actions.tap(_HANDLE, position=self.frame._position(params),
|
||||
**self._act_args(params))
|
||||
self._by_hand(params, lambda position, timeout: self.frame.actions.tap(
|
||||
_HANDLE, **{**self._act_args(params), "timeout": timeout}, position=position))
|
||||
return None
|
||||
|
||||
def op_select_text(self, params: Dict) -> Any:
|
||||
@@ -1187,13 +1202,13 @@ class ElementHandleDispatcher(Dispatcher):
|
||||
return None
|
||||
|
||||
def op_check(self, params: Dict) -> Any:
|
||||
self.frame.actions.check(_HANDLE, position=self.frame._position(params),
|
||||
**self._act_args(params))
|
||||
self._by_hand(params, lambda position, timeout: self.frame.actions.check(
|
||||
_HANDLE, **{**self._act_args(params), "timeout": timeout}, position=position))
|
||||
return None
|
||||
|
||||
def op_uncheck(self, params: Dict) -> Any:
|
||||
self.frame.actions.uncheck(_HANDLE, position=self.frame._position(params),
|
||||
**self._act_args(params))
|
||||
self._by_hand(params, lambda position, timeout: self.frame.actions.uncheck(
|
||||
_HANDLE, **{**self._act_args(params), "timeout": timeout}, position=position))
|
||||
return None
|
||||
|
||||
def op_fill(self, params: Dict) -> Any:
|
||||
@@ -1807,7 +1822,7 @@ class FrameDispatcher(Dispatcher):
|
||||
return result
|
||||
|
||||
def _by_hand(self, params: Dict, frame_id: str, selector: str,
|
||||
run: Callable[[Any, Any], Any]) -> Any:
|
||||
run: Callable[[Any, Any], Any], *, element: Optional[str] = None) -> Any:
|
||||
"""Run a pointer action with the hand of the session in front of it.
|
||||
|
||||
⛔ THE WALK ONTO THE ELEMENT IS DRAWN HERE, once, for every client: it
|
||||
@@ -1816,13 +1831,17 @@ class FrameDispatcher(Dispatcher):
|
||||
`run(position, timeout)` is the plain action; with no hand (humanising
|
||||
off, the engine's own expansion) it is all that happens, with the
|
||||
caller's own arguments.
|
||||
|
||||
⛔ ONE WALK FOR EVERY DOOR. An ElementHandle's pointer actions come through
|
||||
here too, with `element` the object id of the node they name: the hand then
|
||||
aims at THAT node (`selector` is not looked up) and leaves it undisposed.
|
||||
"""
|
||||
hand = self.page.pointer
|
||||
if hand is None or not hand.active:
|
||||
return run(self._position(params), self._timeout(params))
|
||||
return hand.act(frame_id, selector, self._position(params),
|
||||
self._timeout(params), run,
|
||||
trial=self._act_opts(params)["trial"])
|
||||
trial=self._act_opts(params)["trial"], element=element)
|
||||
|
||||
def op_click(self, params: Dict) -> Any:
|
||||
frame_id, selector = self.enter_frames(params["selector"])
|
||||
|
||||
Reference in new issue
Block a user