Class: Puppeteer::Page
- Inherits:
-
Object
show all
- Includes:
- EventCallbackable, IfPresent
- Defined in:
- lib/puppeteer/page.rb,
lib/puppeteer/page/pdf_options.rb,
lib/puppeteer/page/screenshot_options.rb
Defined Under Namespace
Classes: FileChooserTimeoutError, PDFOptions, PrintToPdfIsNotImplementedError, ProtocolStreamReader, ScreenshotOptions, ScriptTag, StyleTag, TargetCrashedError
Constant Summary
collapse
- EVENT_MAPPINGS =
{
close: 'Events.Page.Close',
domcontentloaded: 'Events.Page.DOMContentLoaded',
frameattached: 'Events.Page.FrameAttached',
framedetached: 'Events.Page.FrameDetached',
framenavigated: 'Events.Page.FrameNavigated',
load: 'Events.Page.Load',
popup: 'Events.Page.Popup',
request: 'Events.Page.Request',
requestfailed: 'Events.Page.RequestFailed',
requestfinished: 'Events.Page.RequestFinished',
response: 'Events.Page.Response',
}
Instance Attribute Summary collapse
-
#accessibility ⇒ Object
readonly
Returns the value of attribute accessibility.
-
#coverage ⇒ Object
readonly
Returns the value of attribute coverage.
-
#javascript_enabled ⇒ Object
/** * @param number, latitude: number, accuracy: (number|undefined)} options */ async setGeolocation(options) { const { longitude, latitude, accuracy = 0} = options; if (longitude < -180 || longitude > 180) throw new Error(‘Invalid longitude “$longitude”: precondition -180 <= LONGITUDE <= 180 failed.`); if (latitude < -90 || latitude > 90) throw new Error(`Invalid latitude “$latitude”: precondition -90 <= LATITUDE <= 90 failed.`); if (accuracy < 0) throw new Error(`Invalid accuracy “$accuracy”: precondition 0 <= ACCURACY failed.`); await this._client.send(’Emulation.setGeolocationOverride’, latitude, accuracy); }.
-
#mouse ⇒ Object
readonly
Returns the value of attribute mouse.
-
#target ⇒ Object
readonly
/** * @param number, latitude: number, accuracy: (number|undefined)} options */ async setGeolocation(options) { const { longitude, latitude, accuracy = 0} = options; if (longitude < -180 || longitude > 180) throw new Error(‘Invalid longitude “$longitude”: precondition -180 <= LONGITUDE <= 180 failed.`); if (latitude < -90 || latitude > 90) throw new Error(`Invalid latitude “$latitude”: precondition -90 <= LATITUDE <= 90 failed.`); if (accuracy < 0) throw new Error(`Invalid accuracy “$accuracy”: precondition 0 <= ACCURACY failed.`); await this._client.send(’Emulation.setGeolocationOverride’, latitude, accuracy); }.
-
#touch_screen ⇒ Object
readonly
Returns the value of attribute touch_screen.
-
#viewport ⇒ Object
Returns the value of attribute viewport.
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_script_tag(script_tag) ⇒ !Promise<!ElementHandle>
-
#add_style_tag(style_tag) ⇒ !Promise<!ElementHandle>
-
#async_wait_for_navigation(timeout: nil, wait_until: nil) ⇒ Object
-
#async_wait_for_request(url: nil, predicate: nil, timeout: nil) ⇒ Object
Waits until request URL matches or request matches the given predicate.
-
#async_wait_for_response(url: nil, predicate: nil, timeout: nil) ⇒ Object
-
#authenticate(username: nil, password: nil) ⇒ Object
-
#browser ⇒ Object
-
#browser_context ⇒ Object
-
#bypass_csp=(enabled) ⇒ Object
-
#cache_enabled=(enabled) ⇒ Object
-
#click(selector, delay: nil, button: nil, click_count: nil) ⇒ Object
-
#close(run_before_unload: false) ⇒ Object
-
#closed? ⇒ boolean
-
#content ⇒ String
-
#content=(html) ⇒ Object
-
#default_navigation_timeout=(timeout) ⇒ Object
-
#default_timeout=(timeout) ⇒ Object
-
#emulate(device) ⇒ Object
-
#emulate_media_type(media_type) ⇒ Object
-
#emulate_timezone(timezone_id) ⇒ Object
-
#evaluate(page_function, *args) ⇒ !Promise<*>
-
#evaluate_handle(page_function, *args) ⇒ !Promise<!Puppeteer.JSHandle>
-
#extra_http_headers=(headers) ⇒ Object
-
#focus(selector) ⇒ Object
-
#frames ⇒ Object
-
#go_back(timeout: nil, wait_until: nil) ⇒ Object
-
#go_forward(timeout: nil, wait_until: nil) ⇒ Object
-
#goto(url, referer: nil, timeout: nil, wait_until: nil) ⇒ Object
-
#handle_file_chooser(event) ⇒ Object
-
#hover(selector) ⇒ Object
-
#init ⇒ Object
-
#initialize(client, target, ignore_https_errors, screenshot_task_queue) ⇒ Page
constructor
-
#keyboard(&block) ⇒ Object
-
#main_frame ⇒ Object
-
#offline_mode=(enabled) ⇒ Object
-
#on(event_name, &block) ⇒ Object
-
#once(event_name, &block) ⇒ Object
-
#pdf(options = {}) ⇒ String
-
#query_objects(prototype_handle) ⇒ !Promise<!Puppeteer.JSHandle>
-
#reload(timeout: nil, wait_until: nil) ⇒ Puppeteer::Response
-
#request_interception=(value) ⇒ Object
-
#S(selector) ⇒ !Promise<?Puppeteer.ElementHandle>
-
#screenshot(options = {}) ⇒ Object
/** * @param !ScreenshotOptions= options * @return !Promise<!Buffer|!String> */.
-
#select(selector, *values) ⇒ !Promise<!Array<string>>
-
#set_content(html, timeout: nil, wait_until: nil) ⇒ Object
-
#Seval(selector, page_function, *args) ⇒ Object
-
#SS(selector) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>
-
#SSeval(selector, page_function, *args) ⇒ Object
‘$$eval()` in JavaScript.
-
#Sx(expression) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>
-
#tap(selector: nil, &block) ⇒ Object
-
#title ⇒ String
-
#type_text(selector, text, delay: nil) ⇒ Object
-
#url ⇒ String
-
#user_agent=(user_agent) ⇒ Object
-
#wait_for_file_chooser(timeout: nil) ⇒ Puppeteer::FileChooser
-
#wait_for_function(page_function, args: [], polling: nil, timeout: nil) ⇒ Puppeteer::JSHandle
-
#wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) ⇒ Object
-
#wait_for_timeout(milliseconds) ⇒ Object
-
#wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) ⇒ Object
-
#workers ⇒ Object
Methods included from IfPresent
#if_present
#add_event_listener, #emit_event, #observe_first, #on_event, #remove_event_listener
Constructor Details
#initialize(client, target, ignore_https_errors, screenshot_task_queue) ⇒ Page
Returns a new instance of Page.
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
110
111
112
113
114
115
116
117
118
|
# File 'lib/puppeteer/page.rb', line 31
def initialize(client, target, ignore_https_errors, screenshot_task_queue)
@closed = false
@client = client
@target = target
@keyboard = Puppeteer::Keyboard.new(client)
@mouse = Puppeteer::Mouse.new(client, @keyboard)
@timeout_settings = Puppeteer::TimeoutSettings.new
@touchscreen = Puppeteer::TouchScreen.new(client, @keyboard)
@frame_manager = Puppeteer::FrameManager.new(client, self, ignore_https_errors, @timeout_settings)
@emulation_manager = Puppeteer::EmulationManager.new(client)
@page_bindings = {}
@javascript_enabled = true
@screenshot_task_queue = screenshot_task_queue
@workers = {}
@client.on_event 'Target.attachedToTarget' do |event|
if event['targetInfo']['type'] != 'worker'
await @client.send_message('Target.detachFromTarget', sessionId: event['sessionId'])
next
end
session = Puppeteer::Connection.from_session(@client).session(event['sessionId']) end
@client.on_event 'Target.detachedFromTarget' do |event|
session_id = event['sessionId']
worker = @workers[session_id]
next unless worker
emit_event('Events.Page.WorkerDestroyed', worker)
@workers.delete(session_id)
end
@frame_manager.on_event 'Events.FrameManager.FrameAttached' do |event|
emit_event 'Events.Page.FrameAttached', event
end
@frame_manager.on_event 'Events.FrameManager.FrameDetached' do |event|
emit_event 'Events.Page.FrameDetached', event
end
@frame_manager.on_event 'Events.FrameManager.FrameNavigated' do |event|
emit_event 'Events.Page.FrameNavigated', event
end
network_manager = @frame_manager.network_manager
network_manager.on_event 'Events.NetworkManager.Request' do |event|
emit_event 'Events.Page.Request', event
end
network_manager.on_event 'Events.NetworkManager.Response' do |event|
emit_event 'Events.Page.Response', event
end
network_manager.on_event 'Events.NetworkManager.RequestFailed' do |event|
emit_event 'Events.Page.RequestFailed', event
end
network_manager.on_event 'Events.NetworkManager.RequestFinished' do |event|
emit_event 'Events.Page.RequestFinished', event
end
@file_chooser_interception_is_disabled = false
@file_chooser_interceptors = Set.new
@client.on_event 'Page.domContentEventFired' do |event|
emit_event 'Events.Page.DOMContentLoaded'
end
@client.on_event 'Page.loadEventFired' do |event|
emit_event 'Events.Page.Load'
end
@client.on_event 'Log.entryAdded' do |event|
handle_log_entry_added(event)
end
@client.on_event 'Page.fileChooserOpened' do |event|
handle_file_chooser(event)
end
@target.is_closed_promise.then do
emit_event 'Events.Page.Close'
@closed = true
end
end
|
Instance Attribute Details
#accessibility ⇒ Object
Returns the value of attribute accessibility.
269
270
271
|
# File 'lib/puppeteer/page.rb', line 269
def accessibility
@accessibility
end
|
#coverage ⇒ Object
Returns the value of attribute coverage.
269
270
271
|
# File 'lib/puppeteer/page.rb', line 269
def coverage
@coverage
end
|
#javascript_enabled ⇒ Object
/**
* @param {!{longitude: number, latitude: number, accuracy: (number|undefined)}} options
*/
async setGeolocation(options)
const { longitude, latitude, accuracy = 0 = options;
if (longitude < -180 || longitude > 180)
throw new Error(`Invalid longitude "$longitude": precondition -180 <= LONGITUDE <= 180 failed.`);
if (latitude < -90 || latitude > 90)
throw new Error(`Invalid latitude "$latitude": precondition -90 <= LATITUDE <= 90 failed.`);
if (accuracy < 0)
throw new Error(`Invalid accuracy "$accuracy": precondition 0 <= ACCURACY failed.`);
await this._client.send('Emulation.setGeolocationOverride', latitude, accuracy);
}
226
227
228
|
# File 'lib/puppeteer/page.rb', line 226
def javascript_enabled
@javascript_enabled
end
|
#mouse ⇒ Object
Returns the value of attribute mouse.
1055
1056
1057
|
# File 'lib/puppeteer/page.rb', line 1055
def mouse
@mouse
end
|
#target ⇒ Object
/**
* @param {!{longitude: number, latitude: number, accuracy: (number|undefined)}} options
*/
async setGeolocation(options)
const { longitude, latitude, accuracy = 0 = options;
if (longitude < -180 || longitude > 180)
throw new Error(`Invalid longitude "$longitude": precondition -180 <= LONGITUDE <= 180 failed.`);
if (latitude < -90 || latitude > 90)
throw new Error(`Invalid latitude "$latitude": precondition -90 <= LATITUDE <= 90 failed.`);
if (accuracy < 0)
throw new Error(`Invalid accuracy "$accuracy": precondition 0 <= ACCURACY failed.`);
await this._client.send('Emulation.setGeolocationOverride', latitude, accuracy);
}
226
227
228
|
# File 'lib/puppeteer/page.rb', line 226
def target
@target
end
|
#touch_screen ⇒ Object
Returns the value of attribute touch_screen.
269
270
271
|
# File 'lib/puppeteer/page.rb', line 269
def touch_screen
@touch_screen
end
|
#viewport ⇒ Object
Returns the value of attribute viewport.
881
882
883
|
# File 'lib/puppeteer/page.rb', line 881
def viewport
@viewport
end
|
Class Method Details
.create(client, target, ignore_https_errors, default_viewport, screenshot_task_queue) ⇒ !Promise<!Page>
18
19
20
21
22
23
24
25
|
# File 'lib/puppeteer/page.rb', line 18
def self.create(client, target, ignore_https_errors, default_viewport, screenshot_task_queue)
page = Puppeteer::Page.new(client, target, ignore_https_errors, screenshot_task_queue)
page.init
if default_viewport
page.viewport = default_viewport
end
page
end
|
Instance Method Details
#add_script_tag(script_tag) ⇒ !Promise<!ElementHandle>
423
424
425
|
# File 'lib/puppeteer/page.rb', line 423
def add_script_tag(script_tag)
main_frame.add_script_tag(script_tag)
end
|
#add_style_tag(style_tag) ⇒ !Promise<!ElementHandle>
439
440
441
|
# File 'lib/puppeteer/page.rb', line 439
def add_style_tag(style_tag)
main_frame.add_style_tag(style_tag)
end
|
#async_wait_for_navigation(timeout: nil, wait_until: nil) ⇒ Object
698
|
# File 'lib/puppeteer/page.rb', line 698
define_async_method :async_wait_for_navigation
|
#async_wait_for_request(url: nil, predicate: nil, timeout: nil) ⇒ Object
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') })
768
|
# File 'lib/puppeteer/page.rb', line 768
define_async_method :async_wait_for_request
|
#async_wait_for_response(url: nil, predicate: nil, timeout: nil) ⇒ Object
794
|
# File 'lib/puppeteer/page.rb', line 794
define_async_method :async_wait_for_response
|
#authenticate(username: nil, password: nil) ⇒ Object
477
478
479
|
# File 'lib/puppeteer/page.rb', line 477
def authenticate(username: nil, password: nil)
@frame_manager.network_manager.authenticate(username: username, password: password)
end
|
#browser ⇒ Object
228
229
230
|
# File 'lib/puppeteer/page.rb', line 228
def browser
@target.browser
end
|
#browser_context ⇒ Object
232
233
234
|
# File 'lib/puppeteer/page.rb', line 232
def browser_context
@target.browser_context
end
|
#bypass_csp=(enabled) ⇒ Object
834
835
836
|
# File 'lib/puppeteer/page.rb', line 834
def bypass_csp=(enabled)
@client.send_message('Page.setBypassCSP', enabled: enabled)
end
|
#cache_enabled=(enabled) ⇒ Object
902
903
904
|
# File 'lib/puppeteer/page.rb', line 902
def cache_enabled=(enabled)
@frame_manager.network_manager.cache_enabled = enabled
end
|
#click(selector, delay: nil, button: nil, click_count: nil) ⇒ Object
1061
1062
1063
|
# File 'lib/puppeteer/page.rb', line 1061
def click(selector, delay: nil, button: nil, click_count: nil)
main_frame.click(selector, delay: delay, button: button, click_count: click_count)
end
|
#close(run_before_unload: false) ⇒ Object
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
|
# File 'lib/puppeteer/page.rb', line 1037
def close(run_before_unload: false)
unless @client.connection
raise 'Protocol error: Connection closed. Most likely the page has been closed.'
end
if run_before_unload
@client.send_message('Page.close')
else
@client.connection.send_message('Target.closeTarget', targetId: @target.target_id)
await @target.is_closed_promise
end
end
|
#closed? ⇒ boolean
1051
1052
1053
|
# File 'lib/puppeteer/page.rb', line 1051
def closed?
@closed
end
|
#content ⇒ String
656
657
658
|
# File 'lib/puppeteer/page.rb', line 656
def content
main_frame.content
end
|
#content=(html) ⇒ Object
668
669
670
|
# File 'lib/puppeteer/page.rb', line 668
def content=(html)
main_frame.set_content(html)
end
|
#default_navigation_timeout=(timeout) ⇒ Object
295
296
297
|
# File 'lib/puppeteer/page.rb', line 295
def default_navigation_timeout=(timeout)
@timeout_settings.default_navigation_timeout = timeout
end
|
#default_timeout=(timeout) ⇒ Object
300
301
302
|
# File 'lib/puppeteer/page.rb', line 300
def default_timeout=(timeout)
@timeout_settings.default_timeout = timeout
end
|
#emulate(device) ⇒ Object
821
822
823
824
|
# File 'lib/puppeteer/page.rb', line 821
def emulate(device)
self.viewport = device.viewport
self.user_agent = device.user_agent
end
|
839
840
841
842
843
844
845
|
# File 'lib/puppeteer/page.rb', line 839
def emulate_media_type(media_type)
media_type_str = media_type.to_s
unless ['screen', 'print', ''].include?(media_type_str)
raise ArgumentError.new("Unsupported media type: #{media_type}")
end
@client.send_message('Emulation.setEmulatedMedia', media: media_type_str)
end
|
#emulate_timezone(timezone_id) ⇒ Object
864
865
866
867
868
869
870
871
872
|
# File 'lib/puppeteer/page.rb', line 864
def emulate_timezone(timezone_id)
@client.send_message('Emulation.setTimezoneOverride', timezoneId: timezone_id || '')
rescue => err
if err.message.include?('Invalid timezone')
raise ArgumentError.new("Invalid timezone ID: #{timezone_id}")
else
raise err
end
end
|
#evaluate(page_function, *args) ⇒ !Promise<*>
886
887
888
|
# File 'lib/puppeteer/page.rb', line 886
def evaluate(page_function, *args)
main_frame.evaluate(page_function, *args)
end
|
#evaluate_handle(page_function, *args) ⇒ !Promise<!Puppeteer.JSHandle>
325
326
327
328
|
# File 'lib/puppeteer/page.rb', line 325
def evaluate_handle(page_function, *args)
context = main_frame.execution_context
context.evaluate_handle(page_function, *args)
end
|
482
483
484
|
# File 'lib/puppeteer/page.rb', line 482
def ()
@frame_manager.network_manager. =
end
|
#focus(selector) ⇒ Object
1068
1069
1070
|
# File 'lib/puppeteer/page.rb', line 1068
def focus(selector)
main_frame.focus(selector)
end
|
#frames ⇒ Object
277
278
279
|
# File 'lib/puppeteer/page.rb', line 277
def frames
@frame_manager.frames
end
|
#go_back(timeout: nil, wait_until: nil) ⇒ Object
798
799
800
|
# File 'lib/puppeteer/page.rb', line 798
def go_back(timeout: nil, wait_until: nil)
go(-1, timeout: timeout, wait_until: wait_until)
end
|
#go_forward(timeout: nil, wait_until: nil) ⇒ Object
804
805
806
|
# File 'lib/puppeteer/page.rb', line 804
def go_forward(timeout: nil, wait_until: nil)
go(+1, timeout: timeout, wait_until: wait_until)
end
|
#goto(url, referer: nil, timeout: nil, wait_until: nil) ⇒ Object
676
677
678
|
# File 'lib/puppeteer/page.rb', line 676
def goto(url, referer: nil, timeout: nil, wait_until: nil)
main_frame.goto(url, referer: referer, timeout: timeout, wait_until: wait_until)
end
|
#handle_file_chooser(event) ⇒ Object
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/puppeteer/page.rb', line 168
def handle_file_chooser(event)
return if @file_chooser_interceptors.empty?
frame = @frame_manager.frame(event['frameId'])
context = frame.execution_context
element = context.adopt_backend_node_id(event['backendNodeId'])
interceptors = @file_chooser_interceptors.to_a
@file_chooser_interceptors.clear
file_chooser = Puppeteer::FileChooser.new(element, event)
interceptors.each do |promise|
promise.fulfill(file_chooser)
end
end
|
#hover(selector) ⇒ Object
1075
1076
1077
|
# File 'lib/puppeteer/page.rb', line 1075
def hover(selector)
main_frame.hover(selector)
end
|
#init ⇒ Object
120
121
122
123
124
125
126
127
|
# File 'lib/puppeteer/page.rb', line 120
def init
await_all(
@frame_manager.async_init,
@client.async_send_message('Target.setAutoAttach', autoAttach: true, waitForDebuggerOnStart: false, flatten: true),
@client.async_send_message('Performance.enable'),
@client.async_send_message('Log.enable'),
)
end
|
#keyboard(&block) ⇒ Object
271
272
273
274
275
|
# File 'lib/puppeteer/page.rb', line 271
def keyboard(&block)
@keyboard.instance_eval(&block) unless block.nil?
@keyboard
end
|
#main_frame ⇒ Object
265
266
267
|
# File 'lib/puppeteer/page.rb', line 265
def main_frame
@frame_manager.main_frame
end
|
#offline_mode=(enabled) ⇒ Object
290
291
292
|
# File 'lib/puppeteer/page.rb', line 290
def offline_mode=(enabled)
@frame_manager.network_manager.offline_mode = enabled
end
|
#on(event_name, &block) ⇒ Object
151
152
153
154
155
156
157
|
# File 'lib/puppeteer/page.rb', line 151
def on(event_name, &block)
unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
end
add_event_listener(EVENT_MAPPINGS[event_name.to_sym], &block)
end
|
#once(event_name, &block) ⇒ Object
160
161
162
163
164
165
166
|
# File 'lib/puppeteer/page.rb', line 160
def once(event_name, &block)
unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
end
observe_first(EVENT_MAPPINGS[event_name.to_sym], &block)
end
|
#pdf(options = {}) ⇒ String
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
|
# File 'lib/puppeteer/page.rb', line 1024
def pdf(options = {})
pdf_options = PDFOptions.new(options)
result = @client.send_message('Page.printToPDF', pdf_options.page_print_args)
ProtocolStreamReader.new(client: @client, handle: result['stream'], path: pdf_options.path).read
rescue => err
if err.message.include?('PrintToPDF is not implemented')
raise PrintToPdfIsNotImplementedError.new
else
raise
end
end
|
#query_objects(prototype_handle) ⇒ !Promise<!Puppeteer.JSHandle>
334
335
336
337
|
# File 'lib/puppeteer/page.rb', line 334
def query_objects(prototype_handle)
context = main_frame.execution_context
context.query_objects(prototype_handle)
end
|
#reload(timeout: nil, wait_until: nil) ⇒ Puppeteer::Response
683
684
685
686
687
688
|
# File 'lib/puppeteer/page.rb', line 683
def reload(timeout: nil, wait_until: nil)
await_all(
async_wait_for_navigation(timeout: timeout, wait_until: wait_until),
@client.async_send_message('Page.reload'),
).first
end
|
#request_interception=(value) ⇒ Object
286
287
288
|
# File 'lib/puppeteer/page.rb', line 286
def request_interception=(value)
@frame_manager.network_manager.request_interception = value
end
|
‘$()` in JavaScript. $ is not allowed to use as a method name in Ruby.
307
308
309
|
# File 'lib/puppeteer/page.rb', line 307
def S(selector)
main_frame.S(selector)
end
|
#screenshot(options = {}) ⇒ Object
/**
* @param {!ScreenshotOptions=} options
* @return {!Promise<!Buffer|!String>}
*/
915
916
917
918
919
920
|
# File 'lib/puppeteer/page.rb', line 915
def screenshot(options = {})
screenshot_options = ScreenshotOptions.new(options)
screenshot_task(screenshot_options.type, screenshot_options)
end
|
#select(selector, *values) ⇒ !Promise<!Array<string>>
1082
1083
1084
|
# File 'lib/puppeteer/page.rb', line 1082
def select(selector, *values)
main_frame.select(selector, *values)
end
|
#set_content(html, timeout: nil, wait_until: nil) ⇒ Object
663
664
665
|
# File 'lib/puppeteer/page.rb', line 663
def set_content(html, timeout: nil, wait_until: nil)
main_frame.set_content(html, timeout: timeout, wait_until: wait_until)
end
|
#Seval(selector, page_function, *args) ⇒ Object
‘$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
343
344
345
|
# File 'lib/puppeteer/page.rb', line 343
def Seval(selector, page_function, *args)
main_frame.Seval(selector, page_function, *args)
end
|
‘$$()` in JavaScript. $ is not allowed to use as a method name in Ruby.
316
317
318
|
# File 'lib/puppeteer/page.rb', line 316
def SS(selector)
main_frame.SS(selector)
end
|
#SSeval(selector, page_function, *args) ⇒ Object
‘$$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
353
354
355
|
# File 'lib/puppeteer/page.rb', line 353
def SSeval(selector, page_function, *args)
main_frame.SSeval(selector, page_function, *args)
end
|
‘$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
362
363
364
|
# File 'lib/puppeteer/page.rb', line 362
def Sx(expression)
main_frame.Sx(expression)
end
|
#tap(selector: nil, &block) ⇒ Object
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
|
# File 'lib/puppeteer/page.rb', line 1089
def tap(selector: nil, &block)
if selector.nil? && block
super(&block)
else
main_frame.tap(selector)
end
end
|
#title ⇒ String
907
908
909
|
# File 'lib/puppeteer/page.rb', line 907
def title
main_frame.title
end
|
#type_text(selector, text, delay: nil) ⇒ Object
1109
1110
1111
|
# File 'lib/puppeteer/page.rb', line 1109
def type_text(selector, text, delay: nil)
main_frame.type_text(selector, text, delay: delay)
end
|
#url ⇒ String
651
652
653
|
# File 'lib/puppeteer/page.rb', line 651
def url
main_frame.url
end
|
#user_agent=(user_agent) ⇒ Object
487
488
489
|
# File 'lib/puppeteer/page.rb', line 487
def user_agent=(user_agent)
@frame_manager.network_manager.user_agent = user_agent
end
|
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'lib/puppeteer/page.rb', line 190
def wait_for_file_chooser(timeout: nil)
if @file_chooser_interceptors.empty?
@client.send_message('Page.setInterceptFileChooserDialog', enabled: true)
end
option_timeout = timeout || @timeout_settings.timeout
promise = resolvable_future
@file_chooser_interceptors << promise
begin
Timeout.timeout(option_timeout / 1000.0) do
promise.value!
end
rescue Timeout::Error
raise FileChooserTimeoutError.new(timeout: option_timeout)
ensure
@file_chooser_interceptors.delete(promise)
end
end
|
#wait_for_function(page_function, args: [], polling: nil, timeout: nil) ⇒ Puppeteer::JSHandle
1145
1146
1147
|
# File 'lib/puppeteer/page.rb', line 1145
def wait_for_function(page_function, args: [], polling: nil, timeout: nil)
main_frame.wait_for_function(page_function, args: args, polling: polling, timeout: timeout)
end
|
#wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) ⇒ Object
1119
1120
1121
|
# File 'lib/puppeteer/page.rb', line 1119
def wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil)
main_frame.wait_for_selector(selector, visible: visible, hidden: hidden, timeout: timeout)
end
|
#wait_for_timeout(milliseconds) ⇒ Object
1126
1127
1128
|
# File 'lib/puppeteer/page.rb', line 1126
def wait_for_timeout(milliseconds)
main_frame.wait_for_timeout(milliseconds)
end
|
#wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) ⇒ Object
1134
1135
1136
|
# File 'lib/puppeteer/page.rb', line 1134
def wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil)
main_frame.wait_for_xpath(xpath, visible: visible, hidden: hidden, timeout: timeout)
end
|
#workers ⇒ Object
281
282
283
|
# File 'lib/puppeteer/page.rb', line 281
def workers
@workers.values
end
|