From e588c3f63d5e7abfa8a89cfdb4d0533cab612a3c Mon Sep 17 00:00:00 2001 From: Dmitry Vorotilin Date: Fri, 20 Nov 2026 21:21:15 +0300 Subject: [PATCH] docs(context): note that wait_for_new_page misses pages opened by a modifier or middle click --- docs/3-navigation.md | 10 ++++++++++ lib/ferrum/context.rb | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/docs/3-navigation.md b/docs/3-navigation.md index d00ebfec..dbf7f8be 100644 --- a/docs/3-navigation.md +++ b/docs/3-navigation.md @@ -168,6 +168,16 @@ opened = browser.wait_for_new_page(opener: page) { page.at_css("a[target=_blank] Same as `wait_for_new_page`, but raises `Ferrum::TimeoutError` if no page opens in time. +Both only see a page that another page opened, through `window.open` or a link with `target="_blank"`, with or +without `noopener`. Chrome reports no opener for a page the user opens from a link: a click with Ctrl, Cmd or Shift +held, or a middle click. Such a page is not returned, compare the targets before and after the click instead: + +```ruby +known = browser.targets.keys +browser.at_css("a").click(keys: [:ctrl]) # :meta on macOS +browser.pages { |t| !known.include?(t.id) } # => [#] +``` + The target of an opened page has the id of the page that opened it: ```ruby diff --git a/lib/ferrum/context.rb b/lib/ferrum/context.rb index 0bb23202..c9bfb311 100644 --- a/lib/ferrum/context.rb +++ b/lib/ferrum/context.rb @@ -134,6 +134,11 @@ def windows(pos = nil, size = 1) # Runs the block and returns the page it opens, in a tab or a window, # e.g. through `window.open` or a link with `target="_blank"`. # + # Only a page that another page opened is seen. Chrome reports no opener + # for a page the user opens from a link, i.e. a click with Ctrl, Cmd or + # Shift held, or a middle click, so such a page is not returned. Compare + # {#targets} before and after the click to find it. + # # @param [Page, nil] opener # Only return a page opened by this page. By default a page opened by # any page of the context is returned.