Skip to content

Commit 80346f8

Browse files
authored
Merge pull request #77 from betelgeuse/fix_main_frame_for_new_tab_links
Fix main_frame for target _blank links
2 parents 3727388 + ad62a02 commit 80346f8

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

lib/ferrum/page/frames.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ def frames_subscribe
7575
frame_id = params.dig("context", "auxData", "frameId")
7676

7777
unless @main_frame.id
78-
@main_frame.id = frame_id
79-
@frames[frame_id] = @main_frame
78+
root_frame = command('Page.getFrameTree').dig('frameTree', 'frame', 'id')
79+
if frame_id == root_frame
80+
@main_frame.id = frame_id
81+
@frames[frame_id] = @main_frame
82+
end
8083
end
8184

8285
frame = @frames[frame_id] || Frame.new(frame_id, self)

spec/frame_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ module Ferrum
2727
expect(frame.url).to end_with("/ferrum/get_cookie")
2828
end
2929

30+
it 'finds main frame properly' do
31+
browser.goto("/ferrum/popup_frames")
32+
browser.at_xpath("//a[text()='pop up']").click
33+
expect(browser.pages.size).to eq(2)
34+
opened_page = browser.pages.last
35+
expect(opened_page.main_frame.url).to end_with("/frames")
36+
end
37+
3038
it "waits for the frame to load" do
3139
browser.go_to
3240
browser.execute <<-JS

spec/support/views/popup_frames.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a href="frames" target="_blank">pop up</a>

0 commit comments

Comments
 (0)