Class: Puppeteer::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/target.rb

Overview

Defined Under Namespace

Classes: InitializeFailure, TargetInfo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_info:, browser_context:, session_factory:, ignore_https_errors:, default_viewport:) ⇒ Target

Returns a new instance of Target.

Parameters:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/puppeteer/target.rb', line 21

def initialize(target_info:, browser_context:, session_factory:, ignore_https_errors:, default_viewport:)
  @target_info = target_info
  @browser_context = browser_context
  @target_id = target_info.target_id
  @session_factory = session_factory
  @ignore_https_errors = ignore_https_errors
  @default_viewport = default_viewport


  #    /** @type {?Promise<!Puppeteer.Page>} */
  #    this._pagePromise = null;
  #    /** @type {?Promise<!Worker>} */
  #    this._workerPromise = null;
  @initialize_callback_promise = resolvable_future
  @initialized_promise = @initialize_callback_promise.then do |success|
    handle_initialized(success)
  end
  @is_closed_promise = resolvable_future

  @is_initialized = @target_info.type != 'page' || !@target_info.url.empty?

  if @is_initialized
    @initialize_callback_promise.fulfill(true)
  end
end

Instance Attribute Details

#initialized_promiseObject (readonly)

Returns the value of attribute initialized_promise.



47
48
49
# File 'lib/puppeteer/target.rb', line 47

def initialized_promise
  @initialized_promise
end

#is_closed_promiseObject (readonly)

Returns the value of attribute is_closed_promise.



47
48
49
# File 'lib/puppeteer/target.rb', line 47

def is_closed_promise
  @is_closed_promise
end

#target_idObject (readonly)

Returns the value of attribute target_id.



47
48
49
# File 'lib/puppeteer/target.rb', line 47

def target_id
  @target_id
end

Instance Method Details

#browser!Puppeteer.Browser

Returns:



123
124
125
# File 'lib/puppeteer/target.rb', line 123

def browser
  @browser_context.browser
end

#browser_context!Puppeteer.BrowserContext



128
129
130
# File 'lib/puppeteer/target.rb', line 128

def browser_context
  @browser_context
end

#closed_callbackObject



49
50
51
# File 'lib/puppeteer/target.rb', line 49

def closed_callback
  @is_closed_promise.fulfill(true)
end

#create_cdp_sessionObject



81
82
83
# File 'lib/puppeteer/target.rb', line 81

def create_cdp_session
  @session_factory.call
end

#handle_target_info_changed(target_info) ⇒ Object

Parameters:



140
141
142
143
144
145
146
147
# File 'lib/puppeteer/target.rb', line 140

def handle_target_info_changed(target_info)
  @target_info = target_info

  if !@is_initialized && (@target_info.type != 'page' || !@target_info.url.empty?)
    @is_initialized = true
    @initialize_callback_promise.fulfill(true)
  end
end

#ignore_initialize_callback_promiseObject



55
56
57
58
59
# File 'lib/puppeteer/target.rb', line 55

def ignore_initialize_callback_promise
  unless @initialize_callback_promise.fulfilled?
    @initialize_callback_promise.fulfill(false)
  end
end

#initialized?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/puppeteer/target.rb', line 77

def initialized?
  @is_initialized
end

#opener?Puppeteer.Target

Returns:



133
134
135
136
137
# File 'lib/puppeteer/target.rb', line 133

def opener
  opener_id = @target_info.opener_id
  return nil if opener_id.nil?
  browser.send(:find_target_by_id, opener_id)
end

#pageObject



85
86
87
88
89
90
91
# File 'lib/puppeteer/target.rb', line 85

def page
  if ['page', 'background_page', 'webview'].include?(@target_info.type) && @page.nil?
    client = @session_factory.call
    @page = Puppeteer::Page.create(client, self, @ignore_https_errors, @default_viewport)
  end
  @page
end

#type"page"|"background_page"|"service_worker"|"shared_worker"|"other"|"browser"

Returns:

  • ("page"|"background_page"|"service_worker"|"shared_worker"|"other"|"browser")


113
114
115
116
117
118
119
120
# File 'lib/puppeteer/target.rb', line 113

def type
  type = @target_info.type
  if ['page', 'background_page', 'service_worker', 'shared_worker', 'browser'].include?(type)
    type
  else
    'other'
  end
end

#urlstring

Returns:

  • (string)


108
109
110
# File 'lib/puppeteer/target.rb', line 108

def url
  @target_info.url
end