Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: waitForNavigation in OOPIFs #207

Merged
merged 1 commit into from Mar 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/puppeteer/events.rb
Expand Up @@ -96,6 +96,7 @@ module FrameManagerEmittedEvents ; end
FrameAttached: EventsDefinitionUtils.symbol('FrameManager.FrameAttached'),
FrameNavigated: EventsDefinitionUtils.symbol('FrameManager.FrameNavigated'),
FrameDetached: EventsDefinitionUtils.symbol('FrameManager.FrameDetached'),
FrameSwapped: EventsDefinitionUtils.symbol('FrameManager.FrameSwapped'),
LifecycleEvent: EventsDefinitionUtils.symbol('FrameManager.LifecycleEvent'),
FrameNavigatedWithinDocument: EventsDefinitionUtils.symbol('FrameManager.FrameNavigatedWithinDocument'),
ExecutionContextCreated: EventsDefinitionUtils.symbol('FrameManager.ExecutionContextCreated'),
Expand Down
2 changes: 2 additions & 0 deletions lib/puppeteer/frame_manager.rb
Expand Up @@ -353,6 +353,8 @@ def handle_frame_detached(frame_id, reason)
if frame
remove_frame_recursively(frame)
end
elsif reason == 'swap'
emit_event(FrameManagerEmittedEvents::FrameSwapped, frame)
end
end

Expand Down
11 changes: 11 additions & 0 deletions lib/puppeteer/lifecycle_watcher.rb
Expand Up @@ -77,6 +77,7 @@ def initialize(frame_manager, frame, wait_until, timeout)
check_lifecycle_complete
end,
@frame_manager.add_event_listener(FrameManagerEmittedEvents::FrameNavigatedWithinDocument, &method(:navigated_within_document)),
@frame_manager.add_event_listener(FrameManagerEmittedEvents::FrameSwapped, &method(:handle_frame_swapped)),
@frame_manager.add_event_listener(FrameManagerEmittedEvents::FrameDetached, &method(:handle_frame_detached)),
]
@listener_ids['network_manager'] = @frame_manager.network_manager.add_event_listener(NetworkManagerEmittedEvents::Request, &method(:handle_request))
Expand Down Expand Up @@ -142,11 +143,21 @@ def timeout_or_termination_promise
check_lifecycle_complete
end

private def handle_frame_swapped(frame)
return if frame != @frame
@swapped = true
check_lifecycle_complete
end

private def check_lifecycle_complete
# We expect navigation to commit.
return unless @expected_lifecycle.completed?(@frame)
@lifecycle_promise.fulfill(true) if @lifecycle_promise.pending?
if @frame.loader_id == @initial_loader_id && !@has_same_document_navigation
if @swapped
@swapped = false
@new_document_navigation_promise.fulfill(true)
end
return
end
if @has_same_document_navigation && @same_document_navigation_promise.pending?
Expand Down
1 change: 0 additions & 1 deletion lib/puppeteer/page.rb
Expand Up @@ -508,7 +508,6 @@ class PageError < StandardError ; end
end

private def handle_console_api(event)
puts "~~~~~~~~~~~~~~#{event}"
if event['executionContextId'] == 0
# DevTools protocol stores the last 1000 console messages. These
# messages are always reported even for removed execution contexts. In
Expand Down
16 changes: 16 additions & 0 deletions spec/integration/oopif_spec.rb
Expand Up @@ -80,6 +80,22 @@ def oopifs(context)
expect(page.frames.size).to eq(1)
end

it 'should support wait for navigation for transitions from local to OOPIF' do
page.goto(server_empty_page)
predicate = -> (frame) { page.frames.index { |_frame| _frame == frame } == 1 }
frame = page.wait_for_frame(predicate: predicate) do
attach_frame(page, 'frame1', server_empty_page)
end
expect(frame).not_to be_oop_frame

frame.wait_for_navigation do
navigate_frame(page, 'frame1', "#{server_cross_process_prefix}/empty.html")
end
expect(frame).to be_oop_frame
detach_frame(page, 'frame1')
expect(page.frames.count).to eq(1)
end

it 'should keep track of a frames OOP state' do
page.goto(server_empty_page)
predicate = -> (frame) { page.frames.index { |_frame| _frame == frame } == 1 }
Expand Down