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

Add webp to screenshot options #144

Merged
merged 2 commits into from
Sep 27, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppeteer/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ 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]
Expand Down
4 changes: 3 additions & 1 deletion lib/puppeteer/page/screenshot_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ScreenshotOptions
# @params options [Hash]
def initialize(options)
if options[:type]
unless [:png, :jpeg].include?(options[:type].to_sym)
unless [:png, :jpeg, :webp].include?(options[:type].to_sym)
raise ArgumentError.new("Unknown options.type value: #{options[:type]}")
end
@type = options[:type]
Expand All @@ -25,6 +25,8 @@ def initialize(options)
@type = 'png'
elsif mime_types.include?('image/jpeg')
@type = 'jpeg'
elsif mime_types.include?('image/webp')
@type = 'webp'
else
raise ArgumentError.new("Unsupported screenshot mime type resolved: #{mime_types}, path: #{options[:path]}")
end
Expand Down
10 changes: 10 additions & 0 deletions spec/integration/screenshot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@
# });
# expect(screenshot).toBeGolden('white.jpg');
# });

it_fails_firefox 'should work with webp' do
screenshot = page.screenshot(type: :webp)
expect(screenshot.length).to be >= 1000
Dir.mktmpdir do |tmpdir|
path = File.join(tmpdir, 'image.webp')
page.screenshot(path: path)
end
end

# it('should work with odd clip size on Retina displays', async () => {
# const { page } = getTestState();

Expand Down