Skip to content

Race condition leading to Argument should belong to the same JavaScript world as target object #233

Closed
rubycdp/ferrum
#647

Description

@aaronjensen

We are occasionally seeing this error come from Ferrum:

Argument should belong to the same JavaScript world as target object

From what I can tell, it may have to do with how cuprite handles finding within elements. If the page navigates in the middle of a find (in between the time when the within is resolved in Ruby to when the find is done) then the crash occurs.

page.within(:css, ".some-class") do
  page.find(:css, ".some-other-class")
end

Activity

  1. emilkarl commented on Feb 6, 2024

    @emilkarl

    Did you solve this?

  2. aaronjensen commented on Feb 6, 2024

    @aaronjensen
    Author

    No, we have tended to avoid within for this reason. I haven't looked into it recently as a result.

  3. markedmondson commented on Feb 1, 2025

    @markedmondson

    Just started seeing this occurring frequently, but with no obvious changes. We do use within quite a lot as above but it had been fine for months/years...

  4. route commented on Feb 1, 2025

    @route
    Member

    @markedmondson something has changed on the js side maybe?

  5. markedmondson commented on Feb 3, 2025

    @markedmondson

    @route I don't see anything immediately obvious but that's a good callout.

    What's interesting is that it fails in CI (using CircleCI) only and not locally. Also it seems intermittent (so basically the worst kind!).

    Edit: Got it - there was a Stimulus controller occasionally raising which seems to have caused this!

  6. route commented on Feb 4, 2025

    @route
    Member

    Intermittent issues like that often manifest themselves on CI due to its slowness. Lower memory ceiling, slower CPU and it fails more often in comparison to flying macbooks

  7. route commented on Oct 16, 2026

    @route
    Member

    Fixed in rubycdp/ferrum#647, which ships in the next Ferrum release.

    When the page navigated between Cuprite resolving the within element and running the find inside it, Chrome rejected the search with Argument should belong to the same JavaScript world as target object: the element belonged to the previous page. Ferrum raised that as a plain Ferrum::BrowserError, which Capybara doesn't retry, so the test failed immediately. Now it's Ferrum::NodeNotFoundError. Cuprite turns that into ObsoleteNode, and Capybara finds the within element again and retries, the same as when the navigation finishes before the find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions