Skip to content

Commit

Permalink
fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeIwaki committed Jul 12, 2020
1 parent b788bab commit 9e6c3aa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 40 deletions.
31 changes: 20 additions & 11 deletions lib/puppeteer/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,14 @@ def reload(timeout: nil, wait_until: nil)
).first
end

# @param timeout [number|nil]
# @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
private def wait_for_navigation(timeout: nil, wait_until: nil)
main_frame.send(:wait_for_navigation, timeout: timeout, wait_until: wait_until)
end

# @!method async_wait_for_navigation(timeout: nil, wait_until: nil)
#
# @param timeout [number|nil]
# @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
define_async_method :async_wait_for_navigation

private def wait_for_network_manager_event(event_name, predicate:, timeout:)
Expand Down Expand Up @@ -725,13 +727,6 @@ def reload(timeout: nil, wait_until: nil)
end
end

# - Waits until request URL matches
# `wait_for_request(url: 'https://example.com/awesome')`
# - Waits until request matches the given predicate
# `wait_for_request(predicate: -> (req){ req.url.start_with?('https://example.com/search') })`
#
# @param url [String]
# @param predicate [Proc(Puppeteer::Request -> Boolean)]
private def wait_for_request(url: nil, predicate: nil, timeout: nil)
if !url && !predicate
raise ArgumentError.new('url or predicate must be specified')
Expand All @@ -752,10 +747,20 @@ def reload(timeout: nil, wait_until: nil)
)
end

define_async_method :async_wait_for_request

# @!method async_wait_for_request(url: nil, predicate: nil, timeout: nil)
#
# Waits until request URL matches or request matches the given predicate.
#
# Waits until request URL matches
# wait_for_request(url: 'https://example.com/awesome')
#
# Waits until request matches the given predicate
# wait_for_request(predicate: -> (req){ req.url.start_with?('https://example.com/search') })
#
# @param url [String]
# @param predicate [Proc(Puppeteer::Request -> Boolean)]
define_async_method :async_wait_for_request

private def wait_for_response(url: nil, predicate: nil, timeout: nil)
if !url && !predicate
raise ArgumentError.new('url or predicate must be specified')
Expand All @@ -776,6 +781,10 @@ def reload(timeout: nil, wait_until: nil)
)
end

# @!method async_wait_for_response(url: nil, predicate: nil, timeout: nil)
#
# @param url [String]
# @param predicate [Proc(Puppeteer::Request -> Boolean)]
define_async_method :async_wait_for_response

# @param timeout [number|nil]
Expand Down
52 changes: 23 additions & 29 deletions lib/puppeteer/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,15 @@ def initialize
#
# Example:
#
# ````
# page.on 'request' do |req|
# # Override headers
# headers = req.headers.merge(
# foo: 'bar', # set "foo" header
# origin: nil, # remove "origin" header
# )
# req.continue(headers: headers)
# end
# ```
#`
# page.on 'request' do |req|
# # Override headers
# headers = req.headers.merge(
# foo: 'bar', # set "foo" header
# origin: nil, # remove "origin" header
# )
# req.continue(headers: headers)
# end
#
# @param error_code [String|Symbol]
def continue(url: nil, method: nil, post_data: nil, headers: nil)
# Request interception is not supported for data: urls.
Expand Down Expand Up @@ -152,15 +150,13 @@ def continue(url: nil, method: nil, post_data: nil, headers: nil)
#
# Example:
#
# ```
# page.on 'request' do |req|
# req.respond(
# status: 404,
# content_type: 'text/plain',
# body: 'Not Found!'
# )
# end
# ````
# page.on 'request' do |req|
# req.respond(
# status: 404,
# content_type: 'text/plain',
# body: 'Not Found!'
# )
# end
#
# @param status [Integer]
# @param headers [Hash<String, String>]
Expand Down Expand Up @@ -211,16 +207,14 @@ def respond(status: nil, headers: nil, content_type: nil, body: nil)
#
# Example:
#
# ````
# page.on 'request' do |req|
# if req.url.include?("porn")
# req.abort
# else
# req.continue
# page.on 'request' do |req|
# if req.url.include?("porn")
# req.abort
# else
# req.continue
# end
# end
# end
# ```
#`
#
# @param error_code [String|Symbol]
def abort(error_code: :failed)
# Request interception is not supported for data: urls.
Expand Down

0 comments on commit 9e6c3aa

Please sign in to comment.