Skip to content

Commit

Permalink
Merge pull request #254 from YusukeIwaki/porting/8717
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeIwaki committed Sep 12, 2022
2 parents a665441 + d6f2ee0 commit 6dfb093
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/puppeteer/frame_manager.rb
Expand Up @@ -110,11 +110,13 @@ def navigate_frame(frame, url, referer: nil, timeout: nil, wait_until: nil)
option_timeout = timeout || @timeout_settings.navigation_timeout

watcher = Puppeteer::LifecycleWatcher.new(self, frame, option_wait_until, option_timeout)
ensure_new_document_navigation = false

begin
navigate = future do
result = @client.send_message('Page.navigate', navigate_params)

loader_id = result['loaderId']
ensure_new_document_navigation = !!loader_id
if result['errorText']
raise NavigationError.new("#{result['errorText']} at #{url}")
end
Expand All @@ -125,9 +127,12 @@ def navigate_frame(frame, url, referer: nil, timeout: nil, wait_until: nil)
)

await_any(
watcher.new_document_navigation_promise,
watcher.same_document_navigation_promise,
watcher.timeout_or_termination_promise,
if ensure_new_document_navigation
watcher.new_document_navigation_promise
else
watcher.same_document_navigation_promise
end,
)
rescue Puppeteer::TimeoutError => err
raise NavigationError.new(err)
Expand Down
3 changes: 2 additions & 1 deletion lib/puppeteer/lifecycle_watcher.rb
Expand Up @@ -65,6 +65,7 @@ def initialize(frame_manager, frame, wait_until, timeout)
@expected_lifecycle = ExpectedLifecycle.new(wait_until)
@frame_manager = frame_manager
@frame = frame
@initial_loader_id = frame.loader_id
@timeout = timeout

@listener_ids = {}
Expand Down Expand Up @@ -162,7 +163,7 @@ def timeout_or_termination_promise
if @has_same_document_navigation && @same_document_navigation_promise.pending?
@same_document_navigation_promise.fulfill(true)
end
if (@swapped || @new_document_navigation) && @new_document_navigation_promise.pending?
if (@swapped || @frame.loader_id != @initial_loader_id) && @new_document_navigation_promise.pending?
@new_document_navigation_promise.fulfill(true)
end
end
Expand Down

0 comments on commit 6dfb093

Please sign in to comment.