Skip to content

fix(node): ignore a lost execution context when refocusing a field after typing - #382

Merged
route merged 1 commit into
mainfrom
fix/refocus-after-navigation
Nov 25, 2026
Merged

route merged 1 commit into
mainfrom
fix/refocus-after-navigation

Conversation

@route

@route route commented Nov 25, 2026

Copy link
Copy Markdown
Member

Capybara's #set should submit single text input forms if ended with \n spec failed on CI in #381 (job) with ObsoleteNode. That PR doesn't touch this code. The bug came in with the real key presses from #377.

When a value ends in \n, Enter submits the form. After typing, set refocuses the field (blur(); focus()). If the page has already started navigating, Chrome has dropped the field's JS context and raises Ferrum::NoExecutionContextError. Capybara treats that error as retryable, so it ran set again on a node that no longer exists and raised ObsoleteNode.

  • Typing#refocus rescues Ferrum::NoExecutionContextError the same way it already rescued Ferrum::NodeNotFoundError.
  • A local loop of 300 Enter-submitting set calls hit the error 9 times before the fix and 0 times after.
  • The race can't be triggered on purpose from a page, so the new Node#set spec stubs the refocus to raise the error Chrome sends. It calls the driver node directly, because otherwise Capybara would reload the element and retry, which hides the error. It fails without the fix and passes with it.
  • CHANGELOG line under Fixed.

…ter typing

Typing a value that ends in \n can submit the form, and the page may navigate away before set refocuses the field. The
refocus then raised Ferrum::NoExecutionContextError, which Capybara retries on, so it set the obsolete node again and
raised ObsoleteNode. It's rescued like Ferrum::NodeNotFoundError already was.
@route
route merged commit 77b9470 into main Nov 25, 2026
5 of 6 checks passed
@route
route deleted the fix/refocus-after-navigation branch November 25, 2026 09:51
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