From 49627d36b422266537efa638dd5c73b2431abec9 Mon Sep 17 00:00:00 2001 From: Dmitry Vorotilin Date: Fri, 16 Oct 2026 11:56:48 +0300 Subject: [PATCH] fix(client): raise NodeNotFoundError for a node from another JavaScript world --- CHANGELOG.md | 4 ++++ lib/ferrum/client.rb | 3 ++- spec/frame/runtime_spec.rb | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47002bbb..9c6f90e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ ### Changed ### Fixed +- Passing a node resolved on the previous page to `evaluate`, e.g. when the page navigates while Cuprite searches + within an element, raised `Ferrum::BrowserError: Argument should belong to the same JavaScript world as target + object`. It's `Ferrum::NodeNotFoundError` now, so callers can treat the node as stale and find it again + [rubycdp/cuprite#233] ### Removed diff --git a/lib/ferrum/client.rb b/lib/ferrum/client.rb index 9c02992e..67158d1e 100644 --- a/lib/ferrum/client.rb +++ b/lib/ferrum/client.rb @@ -376,7 +376,8 @@ def raise_browser_error(error) # Node has disappeared while we were trying to get it when "No node with given id found", "Could not find node with given id", - "Inspected target navigated or closed" + "Inspected target navigated or closed", + "Argument should belong to the same JavaScript world as target object" raise NodeNotFoundError, error # Context is lost, page is reloading when "Cannot find context with specified id" diff --git a/spec/frame/runtime_spec.rb b/spec/frame/runtime_spec.rb index 12504a63..f8406eeb 100644 --- a/spec/frame/runtime_spec.rb +++ b/spec/frame/runtime_spec.rb @@ -236,6 +236,18 @@ expect(elapsed).to be < Ferrum::Frame::Runtime::INTERMITTENT_SLEEP end + + it "raises NodeNotFoundError for a node resolved on the previous page" do + browser.go_to("/table") + node = browser.at_xpath(".//td") + object_id = browser.page.command("DOM.resolveNode", nodeId: node.node_id).dig("object", "objectId") + + browser.go_to("/table") + + expect do + browser.evaluate("arguments[0].textContent", { "objectId" => object_id }) + end.to raise_error(Ferrum::NodeNotFoundError, /same JavaScript world/) + end end describe "#add_script_tag" do