Skip to content

fix(node): await the scroll in scroll_to with an element or a location - #363

Open
top-sigrid wants to merge 1 commit into
rubycdp:mainfrom
top-sigrid:fix-await-scroll
Open

top-sigrid wants to merge 1 commit into
rubycdp:mainfrom
top-sigrid:fix-await-scroll

Conversation

@top-sigrid

Copy link
Copy Markdown

Fixes #362

scroll_to(element) and scroll_to(:top | :bottom | :center) evaluate this.scrollIntoView(...) and this.scrollTo(0, ...) without arguments, which Ferrum 0.20 runs the legacy way. Both return a promise in current Chrome, so Ferrum prints its promise deprecation once per script and call site, 6 times per Ruby version in CI on main.

Both scripts now await the promise. A script that awaits takes Ferrum's 0.21 path, which waits for the promise. scroll_to(x, y) and scroll_by already take that path because they pass named arguments, so all scroll methods now wait for the scroll.

The warning suggests void instead. That would silence it too, but leave these two as the only scroll methods that return before the scroll's promise settles.

With Ferrum's default browser options on Chrome 156, the promises resolved in every case tried and none rejected: instant and smooth scrollIntoView, a smooth scroll interrupted by another, scrollTo and scrollBy on an element, and an element that was detached or removed.

On Ferrum main the warning is gone without this change too, and the scroll specs pass with and without it. So this matters for releases that still require Ferrum 0.20.x.

Two specs run scroll_to(element, align: :bottom) and scroll_to(:bottom) with FERRUM_DEPRECATION_WARNINGS=raise and fail without the change. With it, on Chrome 156.0.8078.80:

  • FERRUM_DEPRECATION_WARNINGS=raise bundle exec rake: 1810 examples, 0 failures, 16 pending, on Ruby 3.3.3 and on 4.0.9
  • bundle exec rspec -e scroll against Ferrum main (6543f61) on Ruby 4.0.9: 25 examples, 0 failures, no deprecation
  • applied on top of Cuprite 0.20 in an app's Cucumber suite, the 81 scenarios that scroll this way pass with FERRUM_DEPRECATION_WARNINGS=raise

scrollIntoView and scrollTo return a promise in current Chrome. Run without arguments, both scripts took Ferrum 0.20's
legacy path, which warns that 0.21 will wait for the promise. Awaiting it takes the path that scroll_to(x, y) and
scroll_by already take with their arguments, so all scroll methods wait for the scroll.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scroll_to with an element or a location prints Ferrum 0.20's promise deprecation

1 participant