Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/3-navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) } # => [#<Ferrum::Page>]
```

The target of an opened page has the id of the page that opened it:

```ruby
Expand Down
5 changes: 5 additions & 0 deletions lib/ferrum/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading