Skip to content

ref(wait): unify the wait family into await_* and wait_* with go_to! and friends - #716

Open
route wants to merge 1 commit into
mainfrom
ref/timeouts-and-wait-results
Open

route wants to merge 1 commit into
mainfrom
ref/timeouts-and-wait-results

Conversation

@route

@route route commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

The wait methods grew one at a time: positional timeouts with different hardcoded defaults, and different results on timeout (false, nil, raising, or nothing useful). This splits them by mechanism and gives them one naming and return convention.

  • await_* runs a block and waits for the event the block triggers: page.await_navigation { }, context.await_page { }, page.await_download { }.
  • wait_* polls a check: wait_css, wait_xpath, network.wait_idle, node.wait_still and page.wait_until { }.

Every one takes timeout: as a keyword (the page timeout by default, 5 seconds for downloads) and returns what it waited for, or nil on timeout. The ! version raises TimeoutError instead.

Navigation follows the same rule. go_to!, refresh!, back! and forward! raise NavigationTimeoutError. The plain versions return nil, and on_timeout: is gone. For code that may or may not navigate, await_navigation(watch: seconds) { } returns true when nothing starts within that window. The click keyword is now navigation_wait:, and false skips the wait. Navigation moves into Page::Navigation, and back on the first history entry no longer reloads the page.

Released names keep working as deprecated shims until 0.22: wait_for_navigation(!), wait_for_reload, wait_for_selector, network.wait_for_idle(!), downloads.wait, node.wait_for_stop_moving, positional idle?(n) and click(wait:).

Breaking: refresh, back and forward return nil instead of raising TimeoutError when the page doesn't load in time, and they return true instead of the raw CDP result.

…and friends

Waits split by mechanism. await_* runs a block and waits for the event it triggers, wait_* polls a check. Every one
returns what it waited for or nil on timeout, and a bang version raises TimeoutError.

- await_navigation(watch:) replaces wait_for_navigation and wait_for_reload, context.await_page replaces
  wait_for_new_page, page.await_download replaces downloads.wait and returns the download the block started
- wait_css/wait_xpath replace wait_for_selector, network.wait_idle replaces wait_for_idle, node.wait_still replaces
  wait_for_stop_moving, page.wait_until polls any block
- go_to!, refresh!, back! and forward! raise NavigationTimeoutError, the plain ones return nil; on_timeout: is gone
- click(navigation_wait:) replaces wait:, false skips the wait
- navigation moves to Page::Navigation; back on the first history entry no longer reloads the page
- released names stay as deprecated shims until 0.22
@route
route force-pushed the ref/timeouts-and-wait-results branch from d0931cb to 912e6ba Compare November 23, 2026 08:43
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.

1 participant