Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.13] Fix precision loss (int vs float mixup) #655

Open
wants to merge 2 commits into
base: 1.13
Choose a base branch
from

Conversation

divinity76
Copy link
Contributor

@divinity76 divinity76 commented Oct 25, 2024

The origin X/Y comes from Page.getLayoutMetrics.cssContentSize ( https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-getLayoutMetrics ) which returns float values like -0.666748046875 , not integers, but the library erroneously treated it like integers, that can cause Mouse()->find(...)->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)
        }
      }

(and that is exactly what happened to me and how I noticed the problem)

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)
        }
      }
@divinity76
Copy link
Contributor Author

is it possible that float scroll position is a recent change in chrome itself? seems much of the code is written with the expectation that scroll position is int, not float 🤔 but window.scrollY is float (and very floaty like X.5), not int

@divinity76
Copy link
Contributor Author

fixing this actually requires breaking the public api a little bit: $page->mouse()->getPosition()
used to return array(int, int); but when fixing this it returns array(float, float) 🤔

@enricodias
Copy link
Member

This would change the public api, although changing to float shouldn't be a breaking change and old implementations using integers should still work 🤔

But if those tests shouldn't fail.

@GrahamCampbell GrahamCampbell reopened this Dec 9, 2024
@GrahamCampbell GrahamCampbell changed the base branch from 1.11 to 1.13 December 9, 2024 11:54
@GrahamCampbell GrahamCampbell changed the title fix precision loss (int vs float mixup) [1.13] Fix precision loss (int vs float mixup) Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants