lib/puppeteer/page.rb in puppeteer-ruby-0.36.0 vs lib/puppeteer/page.rb in puppeteer-ruby-0.37.0
- old
+ new
@@ -402,12 +402,13 @@
# @param url [String?]
# @param path [String?]
# @param content [String?]
# @param type [String?]
- def add_script_tag(url: nil, path: nil, content: nil, type: nil)
- main_frame.add_script_tag(url: url, path: path, content: content, type: type)
+ # @param id [String?]
+ def add_script_tag(url: nil, path: nil, content: nil, type: nil, id: nil)
+ main_frame.add_script_tag(url: url, path: path, content: content, type: type, id: id)
end
# @param url [String?]
# @param path [String?]
# @param content [String?]
@@ -963,11 +964,11 @@
# @return [String]
def title
main_frame.title
end
- # @param type [String] "png"|"jpeg"
+ # @param type [String] "png"|"jpeg"|"webp"
# @param path [String]
# @param full_page [Boolean]
# @param clip [Hash]
# @param quality [Integer]
# @param omit_background [Boolean]
@@ -1057,14 +1058,23 @@
end
end
# @return [Enumerable<String>]
def create_pdf_stream(options = {})
+ timeout_helper = Puppeteer::TimeoutHelper.new('Page.printToPDF',
+ timeout_ms: options[:timeout],
+ default_timeout_ms: 30000)
pdf_options = PDFOptions.new(options)
omit_background = options[:omit_background]
set_transparent_background_color if omit_background
- result = @client.send_message('Page.printToPDF', pdf_options.page_print_args)
- reset_default_background_color if omit_background
+ result =
+ begin
+ timeout_helper.with_timeout do
+ @client.send_message('Page.printToPDF', pdf_options.page_print_args)
+ end
+ ensure
+ reset_default_background_color if omit_background
+ end
Puppeteer::ProtocolStreamReader.new(
client: @client,
handle: result['stream'],
).read_as_chunks