From b797ba042a520351c8b0fe79ee2fd60311c19174 Mon Sep 17 00:00:00 2001 From: divinity76 Date: Fri, 25 Oct 2024 09:29:07 +0200 Subject: [PATCH 1/2] fix precision loss (int vs float mixup) The origin X/Y comes from Page.getLayoutMetrics.cssContentSize which returns float values like -0.666748046875 , not integers, but the library erroneously treated it like integers, that can cause Mouse()->click to miss-click on very small targets, and with custom error handlers it can also cause ["trace":"Exception":private]=> array(9) { [0]=> array(4) { ["file"]=> string(52) "C:\temp\vendor\chrome-php\chrome\src\Input\Mouse.php" ["line"]=> int(338) ["function"]=> string(9) "{closure}" ["args"]=> array(4) { [0]=> int(8192) [1]=> string(69) "Implicit conversion from float -0.666748046875 to int loses precision" [2]=> string(52) "C:\temp\vendor\chrome-php\chrome\src\Input\Mouse.php" [3]=> int(338) } } --- src/Input/Mouse.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Input/Mouse.php b/src/Input/Mouse.php index c94e23b..47445f2 100644 --- a/src/Input/Mouse.php +++ b/src/Input/Mouse.php @@ -31,8 +31,8 @@ class Mouse */ protected $page; - protected $x = 0; - protected $y = 0; + protected $x = 0.0; + protected $y = 0.0; protected $button = self::BUTTON_NONE; @@ -54,7 +54,7 @@ public function __construct(Page $page) * * @return $this */ - public function move(int $x, int $y, array $options = null) + public function move(float $x, float $y, array $options = null) { $this->page->assertNotClosed(); @@ -329,13 +329,13 @@ public function findElement(Selector $selector, int $position = 1): self /** * Get the maximum distance to scroll a page. * - * @param int $distance Distance to scroll, positive or negative - * @param int $current Current position - * @param int $maximum Maximum possible distance + * @param float $distance Distance to scroll, positive or negative + * @param float $current Current position + * @param float $maximum Maximum possible distance * - * @return int allowed distance to scroll + * @return float allowed distance to scroll */ - private function getMaximumDistance(int $distance, int $current, int $maximum): int + private function getMaximumDistance(float $distance, float $current, float $maximum): float { $result = $current + $distance; From 3c6ca8b54421dda88185bc043cdc8d7b5d0d9a49 Mon Sep 17 00:00:00 2001 From: divinity76 Date: Fri, 25 Oct 2024 09:31:13 +0200 Subject: [PATCH 2/2] doc --- src/Input/Mouse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Input/Mouse.php b/src/Input/Mouse.php index 47445f2..ad9292c 100644 --- a/src/Input/Mouse.php +++ b/src/Input/Mouse.php @@ -45,8 +45,8 @@ public function __construct(Page $page) } /** - * @param int $x - * @param int $y + * @param float $x + * @param float $y * @param array|null $options * * @throws \HeadlessChromium\Exception\CommunicationException