Class: Puppeteer::Page::ScreenshotOptions
- Inherits:
-
Object
- Object
- Puppeteer::Page::ScreenshotOptions
- Defined in:
- lib/puppeteer/page/screenshot_options.rb
Overview
/**
-
@defaultValue ‘png’
*/ type?: ‘png’ | ‘jpeg’ | ‘webp’; /**
-
The file path to save the image to. The screenshot type will be inferred
-
from file extension. If path is a relative path, then it is resolved
-
relative to current working directory. If no path is provided, the image
-
won’t be saved to the disk.
*/ path?: string; /**
-
When true, takes a screenshot of the full page.
-
@defaultValue false
*/ fullPage?: boolean; /**
-
An object which specifies the clipping region of the page.
*/ clip?: ScreenshotClip; /**
-
Quality of the image, between 0-100. Not applicable to ‘png` images.
*/ quality?: number; /**
-
Hides default white background and allows capturing screenshots with transparency.
-
@defaultValue false
*/ omitBackground?: boolean; /**
-
Encoding of the image.
-
@defaultValue ‘binary’
*/ encoding?: ‘base64’ | ‘binary’; /**
-
Capture the screenshot beyond the viewport.
-
@defaultValue true
*/ captureBeyondViewport?: boolean; /**
-
Capture the screenshot from the surface, rather than the view.
-
@defaultValue true
*/ fromSurface?: boolean;
Instance Attribute Summary collapse
-
#clip ⇒ Object
readonly
Returns the value of attribute clip.
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#from_surface ⇒ Object
readonly
Returns the value of attribute from_surface.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#quality ⇒ Object
readonly
Returns the value of attribute quality.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #capture_beyond_viewport? ⇒ Boolean
- #full_page? ⇒ Boolean
-
#initialize(options) ⇒ ScreenshotOptions
constructor
A new instance of ScreenshotOptions.
- #omit_background? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ ScreenshotOptions
Returns a new instance of ScreenshotOptions.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/puppeteer/page/screenshot_options.rb', line 50 def initialize() if [:type] unless [:png, :jpeg, :webp].include?([:type].to_sym) raise ArgumentError.new("Unknown options.type value: #{[:type]}") end @type = [:type] elsif [:path] mime_types = MIME::Types.type_for([:path]) if mime_types.include?('image/png') @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: #{[:path]}") end end @type ||= 'png' if [:quality] if @type != 'jpeg' && @type != 'webp' raise ArgumentError.new("options.quality is unsupported for the #{@type} screenshots") end unless [:quality].is_a?(Numeric) raise ArgumentError.new("Expected options.quality to be a number but found #{[:quality].class}") end quality = [:quality].to_i unless (0..100).include?(quality) raise ArgumentError.new("Expected options.quality to be between 0 and 100 (inclusive), got #{quality}") end @quality = quality end if [:clip] && [:full_page] raise ArgumentError.new('options.clip and options.fullPage are exclusive') end # if (options.clip) { # assert(typeof options.clip.x === 'number', 'Expected options.clip.x to be a number but found ' + (typeof options.clip.x)); # assert(typeof options.clip.y === 'number', 'Expected options.clip.y to be a number but found ' + (typeof options.clip.y)); # assert(typeof options.clip.width === 'number', 'Expected options.clip.width to be a number but found ' + (typeof options.clip.width)); # assert(typeof options.clip.height === 'number', 'Expected options.clip.height to be a number but found ' + (typeof options.clip.height)); # assert(options.clip.width !== 0, 'Expected options.clip.width not to be 0.'); # assert(options.clip.height !== 0, 'Expected options.clip.height not to be 0.'); # } @path = [:path] @full_page = [:full_page] @clip = [:clip] @omit_background = [:omit_background] @encoding = [:encoding] @capture_beyond_viewport = if [:capture_beyond_viewport].nil? true else [:capture_beyond_viewport] end @from_surface = [:from_surface] end |
Instance Attribute Details
#clip ⇒ Object (readonly)
Returns the value of attribute clip.
111 112 113 |
# File 'lib/puppeteer/page/screenshot_options.rb', line 111 def clip @clip end |
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
111 112 113 |
# File 'lib/puppeteer/page/screenshot_options.rb', line 111 def encoding @encoding end |
#from_surface ⇒ Object (readonly)
Returns the value of attribute from_surface.
111 112 113 |
# File 'lib/puppeteer/page/screenshot_options.rb', line 111 def from_surface @from_surface end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
111 112 113 |
# File 'lib/puppeteer/page/screenshot_options.rb', line 111 def path @path end |
#quality ⇒ Object (readonly)
Returns the value of attribute quality.
111 112 113 |
# File 'lib/puppeteer/page/screenshot_options.rb', line 111 def quality @quality end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
111 112 113 |
# File 'lib/puppeteer/page/screenshot_options.rb', line 111 def type @type end |
Instance Method Details
#capture_beyond_viewport? ⇒ Boolean
121 122 123 |
# File 'lib/puppeteer/page/screenshot_options.rb', line 121 def @capture_beyond_viewport end |
#full_page? ⇒ Boolean
113 114 115 |
# File 'lib/puppeteer/page/screenshot_options.rb', line 113 def full_page? @full_page end |
#omit_background? ⇒ Boolean
117 118 119 |
# File 'lib/puppeteer/page/screenshot_options.rb', line 117 def omit_background? @omit_background end |