Skip to content

Commit

Permalink
fix: consider existing frames when waiting for a frame
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeIwaki committed Jun 20, 2022
1 parent c5d4e41 commit 42f24f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/puppeteer/page.rb
Expand Up @@ -814,6 +814,10 @@ def wait_for_frame(url: nil, predicate: nil, timeout: nil)
predicate
end

frames.each do |frame|
return frame if frame_predicate.call(frame)
end

wait_for_frame_manager_event(
FrameManagerEmittedEvents::FrameAttached,
FrameManagerEmittedEvents::FrameNavigated,
Expand Down
8 changes: 8 additions & 0 deletions spec/integration/oopif_spec.rb
Expand Up @@ -221,4 +221,12 @@ def oopifs(context)
expect(result_bounding_box.x).to be > 150 # padding + margin + border left
expect(result_bounding_box.y).to be > 150 # padding + margin + border top
end

it 'should resolve immediately if the frame already exists' do
page.goto(server_empty_page)
attach_frame(page, 'frame2', "#{server_cross_process_prefix}/empty.html")
predicate = ->(frame) { frame.url&.end_with?('/empty.html') }
frame = page.wait_for_frame(predicate: predicate)
expect(frame.url).to end_with("/empty.html")
end
end

0 comments on commit 42f24f3

Please sign in to comment.