Class: Puppeteer::Page

Inherits:
Object
  • Object
show all
Includes:
EventCallbackable, IfPresent
Defined in:
lib/puppeteer/page.rb,
lib/puppeteer/page/screenshot_options.rb

Defined Under Namespace

Classes: FileChooserTimeoutError, ScreenshotOptions, ScriptTag, StyleTag, TargetCrashedError

Constant Summary collapse

EVENT_MAPPINGS =
{
  close: 'Events.Page.Close',
  # console: 'Events.Page.Console',
  # dialog: 'Events.Page.Dialog',
  domcontentloaded: 'Events.Page.DOMContentLoaded',
  # error:
  frameattached: 'Events.Page.FrameAttached',
  framedetached: 'Events.Page.FrameDetached',
  framenavigated: 'Events.Page.FrameNavigated',
  load: 'Events.Page.Load',
  # metrics: 'Events.Page.Metrics',
  # pageerror: 'Events.Page.PageError',
  popup: 'Events.Page.Popup',
  request: 'Events.Page.Request',
  requestfailed: 'Events.Page.RequestFailed',
  requestfinished: 'Events.Page.RequestFinished',
  response: 'Events.Page.Response',
  # workercreated: 'Events.Page.WorkerCreated',
  # workerdestroyed: 'Events.Page.WorkerDestroyed',
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IfPresent

#if_present

Methods included from EventCallbackable

#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.

Parameters:



29
30
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
# File 'lib/puppeteer/page.rb', line 29

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)
  # @accessibility = Accessibility.new(client)
  @frame_manager = Puppeteer::FrameManager.new(client, self, ignore_https_errors, @timeout_settings)
  @emulation_manager = Puppeteer::EmulationManager.new(client)
  # @tracing = Tracing.new(client)
  @page_bindings = {}
  # @coverage = Coverage.new(client)
  @javascript_enabled = true
  @screenshot_task_queue = screenshot_task_queue

  @workers = {}
  @client.on_event 'Target.attachedToTarget' do |event|
    if event['targetInfo']['type'] != 'worker'
      # If we don't detach from service workers, they will never die.
      await @client.send_message('Target.detachFromTarget', sessionId: event['sessionId'])
      next
    end

    session = Puppeteer::Connection.from_session(@client).session(event['sessionId']) # rubocop:disable Lint/UselessAssignment
    #   const worker = new Worker(session, event.targetInfo.url, this._addConsoleMessage.bind(this), this._handleException.bind(this));
    #   this._workers.set(event.sessionId, worker);
    #   this.emit(Events.Page.WorkerCreated, worker);
  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('Runtime.consoleAPICalled', event => this._onConsoleAPI(event));
  # client.on('Runtime.bindingCalled', event => this._onBindingCalled(event));
  # client.on('Page.javascriptDialogOpening', event => this._onDialog(event));
  # client.on('Runtime.exceptionThrown', exception => this._handleException(exception.exceptionDetails));
  # client.on('Inspector.targetCrashed', event => this._onTargetCrashed());
  # client.on('Performance.metrics', event => this._emitMetrics(event));
  @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

#accessibilityObject (readonly)

Returns the value of attribute accessibility.



272
273
274
# File 'lib/puppeteer/page.rb', line 272

def accessibility
  @accessibility
end

#coverageObject (readonly)

Returns the value of attribute coverage.



272
273
274
# File 'lib/puppeteer/page.rb', line 272

def coverage
  @coverage
end

#javascript_enabledObject

/**

* @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);

}



229
230
231
# File 'lib/puppeteer/page.rb', line 229

def javascript_enabled
  @javascript_enabled
end

#keyboardObject (readonly)

Returns the value of attribute keyboard.



272
273
274
# File 'lib/puppeteer/page.rb', line 272

def keyboard
  @keyboard
end

#mouseObject (readonly)

Returns the value of attribute mouse.



1002
1003
1004
# File 'lib/puppeteer/page.rb', line 1002

def mouse
  @mouse
end

#targetObject (readonly)

/**

* @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);

}



229
230
231
# File 'lib/puppeteer/page.rb', line 229

def target
  @target
end

#touch_screenObject (readonly)

Returns the value of attribute touch_screen.



272
273
274
# File 'lib/puppeteer/page.rb', line 272

def touch_screen
  @touch_screen
end

#viewportObject

Returns the value of attribute viewport.



825
826
827
# File 'lib/puppeteer/page.rb', line 825

def viewport
  @viewport
end

Class Method Details

.create(client, target, ignore_https_errors, default_viewport, screenshot_task_queue) ⇒ !Promise<!Page>

Parameters:

Returns:



16
17
18
19
20
21
22
23
# File 'lib/puppeteer/page.rb', line 16

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>

Parameters:

Returns:



424
425
426
# File 'lib/puppeteer/page.rb', line 424

def add_script_tag(script_tag)
  main_frame.add_script_tag(script_tag)
end

#add_style_tag(style_tag) ⇒ !Promise<!ElementHandle>

Parameters:

Returns:



440
441
442
# File 'lib/puppeteer/page.rb', line 440

def add_style_tag(style_tag)
  main_frame.add_style_tag(style_tag)
end

#async_clickFuture

Parameters:

  • selector (String)
  • delay (Number)
  • button (String)

    “left”|“right”|“middle”

  • click_count (Number)

Returns:

  • (Future)


1017
1018
1019
# File 'lib/puppeteer/page.rb', line 1017

async def async_click(selector, delay: nil, button: nil, click_count: nil)
  click(selector, delay: delay, button: button, click_count: click_count)
end

#async_SevalFuture

`$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.

Parameters:

  • selector (String)
  • page_function (String)

Returns:

  • (Future)


342
343
344
# File 'lib/puppeteer/page.rb', line 342

async def async_Seval(selector, page_function, *args)
  Seval(selector, page_function, *args)
end

#async_SSevalFuture

`$$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.

Parameters:

  • selector (String)
  • page_function (String)

Returns:

  • (Future)


358
359
360
# File 'lib/puppeteer/page.rb', line 358

async def async_SSeval(selector, page_function, *args)
  SSeval(selector, page_function, *args)
end

#async_wait_for_file_chooserFuture<Puppeteer::FileChooser>

Parameters:

  • timeout (Integer)

Returns:



210
211
212
# File 'lib/puppeteer/page.rb', line 210

async def async_wait_for_file_chooser(timeout: nil)
  wait_for_file_chooser(timeout: timeout)
end

#async_wait_for_navigationFuture

Parameters:

  • timeout (number|nil)
  • wait_until (string|nil)

    'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'

Returns:

  • (Future)


699
700
701
# File 'lib/puppeteer/page.rb', line 699

async def async_wait_for_navigation(timeout: nil, wait_until: nil)
  wait_for_navigation(timeout: timeout, wait_until: wait_until)
end

#authenticate(username: nil, password: nil) ⇒ Object

Parameters:

  • username (String?) (defaults to: nil)
  • password (String?) (defaults to: nil)


478
479
480
# File 'lib/puppeteer/page.rb', line 478

def authenticate(username: nil, password: nil)
  @frame_manager.network_manager.authenticate(username: username, password: password)
end

#browserObject



231
232
233
# File 'lib/puppeteer/page.rb', line 231

def browser
  @target.browser
end

#browser_contextObject



235
236
237
# File 'lib/puppeteer/page.rb', line 235

def browser_context
  @target.browser_context
end

#cache_enabled=(enabled) ⇒ Object

Parameters:

  • enabled (boolean)


844
845
846
# File 'lib/puppeteer/page.rb', line 844

def cache_enabled=(enabled)
  @frame_manager.network_manager.cache_enabled = enabled
end

#click(selector, delay: nil, button: nil, click_count: nil) ⇒ Object

Parameters:

  • selector (String)
  • delay (Number) (defaults to: nil)
  • button (String) (defaults to: nil)

    “left”|“right”|“middle”

  • click_count (Number) (defaults to: nil)


1008
1009
1010
# File 'lib/puppeteer/page.rb', line 1008

def click(selector, delay: nil, button: nil, click_count: nil)
  main_frame.click(selector, delay: delay, button: button, click_count: click_count)
end

#closeObject

Parameters:

  • options (!{runBeforeUnload: (boolean|undefined)}=)


986
987
988
989
990
991
992
993
994
995
# File 'lib/puppeteer/page.rb', line 986

def close
  # assert(!!this._client._connection, 'Protocol error: Connection closed. Most likely the page has been closed.');
  # const runBeforeUnload = !!options.runBeforeUnload;
  # if (runBeforeUnload) {
  #   await this._client.send('Page.close');
  # } else {
  #   await this._client._connection.send('Target.closeTarget', { targetId: this._target._targetId });
  #   await this._target._isClosedPromise;
  # }
end

#closed?boolean

Returns:

  • (boolean)


998
999
1000
# File 'lib/puppeteer/page.rb', line 998

def closed?
  @closed
end

#contentString

Returns:

  • (String)


657
658
659
# File 'lib/puppeteer/page.rb', line 657

def content
  main_frame.content
end

#content=(html) ⇒ Object

Parameters:

  • html (string)


668
669
670
# File 'lib/puppeteer/page.rb', line 668

def content=(html)
  main_frame.set_content(html)
end

#default_navigation_timeout=(timeout) ⇒ Object

Parameters:

  • timeout (number)


292
293
294
# File 'lib/puppeteer/page.rb', line 292

def default_navigation_timeout=(timeout)
  @timeout_settings.default_navigation_timeout = timeout
end

#default_timeout=(timeout) ⇒ Object

Parameters:

  • timeout (number)


297
298
299
# File 'lib/puppeteer/page.rb', line 297

def default_timeout=(timeout)
  @timeout_settings.default_timeout = timeout
end

#emulate(device) ⇒ Object

Parameters:



764
765
766
767
# File 'lib/puppeteer/page.rb', line 764

def emulate(device)
  self.viewport = device.viewport
  self.user_agent = device.user_agent
end

#emulate_timezone(timezone_id) ⇒ Object

Parameters:

  • timezone_id (String?)


808
809
810
811
812
813
814
815
816
# File 'lib/puppeteer/page.rb', line 808

def emulate_timezone(timezone_id)
  @client.send_message('Emulation.setTimezoneOverride', timezoneId: timezoneId || '')
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<*>

Parameters:

  • pageFunction (Function|string)
  • args (!Array<*>)

Returns:

  • (!Promise<*>)


830
831
832
# File 'lib/puppeteer/page.rb', line 830

def evaluate(page_function, *args)
  main_frame.evaluate(page_function, *args)
end

#evaluate_handle(page_function, *args) ⇒ !Promise<!Puppeteer.JSHandle>

Parameters:

  • pageFunction (Function|string)
  • args (!Array<*>)

Returns:



318
319
320
321
# File 'lib/puppeteer/page.rb', line 318

def evaluate_handle(page_function, *args)
  context = main_frame.execution_context
  context.evaluate_handle(page_function, *args)
end

#extra_http_headers=(headers) ⇒ Object

Parameters:

  • headers (Hash)


483
484
485
# File 'lib/puppeteer/page.rb', line 483

def extra_http_headers=(headers)
  @frame_manager.network_manager.extra_http_headers = headers
end

#focus(selector) ⇒ Object

Parameters:

  • selector (string)


1022
1023
1024
# File 'lib/puppeteer/page.rb', line 1022

def focus(selector)
  main_frame.focus(selector)
end

#framesObject



274
275
276
# File 'lib/puppeteer/page.rb', line 274

def frames
  @frame_manager.frames
end

#go_back(timeout: nil, wait_until: nil) ⇒ Object

Parameters:

  • timeout (number|nil) (defaults to: nil)
  • wait_until (string|nil) (defaults to: nil)

    'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'



741
742
743
# File 'lib/puppeteer/page.rb', line 741

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

Parameters:

  • timeout (number|nil) (defaults to: nil)
  • wait_until (string|nil) (defaults to: nil)

    'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'



747
748
749
# File 'lib/puppeteer/page.rb', line 747

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

Parameters:

  • url (String)
  • rederer (String)
  • timeout (number|nil) (defaults to: nil)
  • wait_until (string|nil) (defaults to: nil)

    'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'



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



166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/puppeteer/page.rb', line 166

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

Parameters:

  • selector (string)


1027
1028
1029
# File 'lib/puppeteer/page.rb', line 1027

def hover(selector)
  main_frame.hover(selector)
end

#initObject



118
119
120
121
122
123
124
125
# File 'lib/puppeteer/page.rb', line 118

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

#main_frameObject



268
269
270
# File 'lib/puppeteer/page.rb', line 268

def main_frame
  @frame_manager.main_frame
end

#offline_mode=(enabled) ⇒ Object



287
288
289
# File 'lib/puppeteer/page.rb', line 287

def offline_mode=(enabled)
  @frame_manager.network_manager.offline_mode = enabled
end

#on(event_name, &block) ⇒ Object

Parameters:

  • event_name (Symbol)


149
150
151
152
153
154
155
# File 'lib/puppeteer/page.rb', line 149

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

Parameters:

  • event_name (Symbol)


158
159
160
161
162
163
164
# File 'lib/puppeteer/page.rb', line 158

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

#query_objects(prototype_handle) ⇒ !Promise<!Puppeteer.JSHandle>

Parameters:

Returns:



325
326
327
328
# File 'lib/puppeteer/page.rb', line 325

def query_objects(prototype_handle)
  context = main_frame.execution_context
  context.query_objects(prototype_handle)
end

#reload(timeout: nil, wait_until: nil) ⇒ Puppeteer::Response

Parameters:

  • timeout (number|nil) (defaults to: nil)
  • wait_until (string|nil) (defaults to: nil)

    'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'

Returns:

  • (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

Parameters:

  • value (Bool)


283
284
285
# File 'lib/puppeteer/page.rb', line 283

def request_interception=(value)
  @frame_manager.network_manager.request_interception = value
end

#S(selector) ⇒ !Promise<?Puppeteer.ElementHandle>

`$()` in JavaScript. $ is not allowed to use as a method name in Ruby.

Parameters:

  • selector (string)

Returns:



304
305
306
# File 'lib/puppeteer/page.rb', line 304

def S(selector)
  main_frame.S(selector)
end

#screenshot(options = {}) ⇒ Object

/**

* @param {!ScreenshotOptions=} options
* @return {!Promise<!Buffer|!String>}
*/


857
858
859
860
861
862
# File 'lib/puppeteer/page.rb', line 857

def screenshot(options = {})
  screenshot_options = ScreenshotOptions.new(options)

  # @screenshot_task_queue.post_task(-> { screenshot_task(screenshot_options.type, screenshot_options) })
  screenshot_task(screenshot_options.type, screenshot_options)
end

#select(selector, *values) ⇒ !Promise<!Array<string>>

Parameters:

  • selector (string)
  • values (!Array<string>)

Returns:

  • (!Promise<!Array<string>>)


1034
1035
1036
# File 'lib/puppeteer/page.rb', line 1034

def select(selector, *values)
  main_frame.select(selector, *values)
end

#set_content(html, timeout: nil, wait_until: nil) ⇒ Object

Parameters:

  • html (string)
  • options (!{timeout?: number, waitUntil?: string|!Array<string>}=)


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.

Parameters:

  • selector (String)
  • page_function (String)

Returns:

  • (Object)


334
335
336
# File 'lib/puppeteer/page.rb', line 334

def Seval(selector, page_function, *args)
  main_frame.Seval(selector, page_function, *args)
end

#SS(selector) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>

`$$()` in JavaScript. $ is not allowed to use as a method name in Ruby.

Parameters:

  • selector (string)

Returns:



311
312
313
# File 'lib/puppeteer/page.rb', line 311

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.

Parameters:

  • selector (String)
  • page_function (String)

Returns:

  • (Object)


350
351
352
# File 'lib/puppeteer/page.rb', line 350

def SSeval(selector, page_function, *args)
  main_frame.SSeval(selector, page_function, *args)
end

#Sx(expression) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>

`$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.

Parameters:

  • expression (string)

Returns:



365
366
367
# File 'lib/puppeteer/page.rb', line 365

def Sx(expression)
  main_frame.Sx(expression)
end

#tap(selector) ⇒ Object

Parameters:

  • selector (String)


1039
1040
1041
# File 'lib/puppeteer/page.rb', line 1039

def tap(selector)
  main_frame.tap(selector)
end

#title!Promise<string>

Returns:

  • (!Promise<string>)


849
850
851
# File 'lib/puppeteer/page.rb', line 849

def title
  @title
end

#type_text(selector, text, delay: nil) ⇒ Object

Parameters:

  • selector (String)
  • text (String)
  • delay (Number) (defaults to: nil)


1051
1052
1053
# File 'lib/puppeteer/page.rb', line 1051

def type_text(selector, text, delay: nil)
  main_frame.type_text(selector, text, delay: delay)
end

#urlString

Returns:

  • (String)


652
653
654
# File 'lib/puppeteer/page.rb', line 652

def url
  main_frame.url
end

#user_agent=(user_agent) ⇒ Object

Parameters:

  • user_agent (String)


488
489
490
# File 'lib/puppeteer/page.rb', line 488

def user_agent=(user_agent)
  @frame_manager.network_manager.user_agent = user_agent
end

#wait_for_file_chooser(timeout: nil) ⇒ Puppeteer::FileChooser

Parameters:

  • timeout (Integer) (defaults to: nil)

Returns:



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/puppeteer/page.rb', line 188

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, options = {}, *args) ⇒ !Promise<!Puppeteer.JSHandle>

Parameters:

  • pageFunction (Function|string)
  • options (!{polling?: string|number, timeout?: number}=) (defaults to: {})
  • args (!Array<*>)

Returns:



1101
1102
1103
# File 'lib/puppeteer/page.rb', line 1101

def wait_for_function(page_function, options = {}, *args)
  main_frame.wait_for_function(page_function, options, *args)
end

#wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) ⇒ Object

Parameters:

  • selector (String)
  • visible (Boolean) (defaults to: nil)

    Wait for element visible (not 'display: none' nor 'visibility: hidden') on true. default to false.

  • hidden (Boolean) (defaults to: nil)

    Wait for element invisible ('display: none' nor 'visibility: hidden') on true. default to false.

  • timeout (Integer) (defaults to: nil)


1069
1070
1071
# File 'lib/puppeteer/page.rb', line 1069

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_xpath(xpath, visible: nil, hidden: nil, timeout: nil) ⇒ Object

Parameters:

  • xpath (String)
  • visible (Boolean) (defaults to: nil)

    Wait for element visible (not 'display: none' nor 'visibility: hidden') on true. default to false.

  • hidden (Boolean) (defaults to: nil)

    Wait for element invisible ('display: none' nor 'visibility: hidden') on true. default to false.

  • timeout (Integer) (defaults to: nil)


1085
1086
1087
# File 'lib/puppeteer/page.rb', line 1085

def wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil)
  main_frame.wait_for_xpath(xpath, visible: visible, hidden: hidden, timeout: timeout)
end

#workersObject



278
279
280
# File 'lib/puppeteer/page.rb', line 278

def workers
  @workers.values
end