Class: Puppeteer::BrowserContext

Inherits:
Object
  • Object
show all
Includes:
EventCallbackable
Defined in:
lib/puppeteer/browser_context.rb

Instance Method Summary collapse

Methods included from EventCallbackable

#add_event_listener, #emit_event, #observe_first, #on_event, #remove_event_listener

Constructor Details

#initialize(connection, browser, context_id) ⇒ BrowserContext

Returns a new instance of BrowserContext.

Parameters:



7
8
9
10
11
# File 'lib/puppeteer/browser_context.rb', line 7

def initialize(connection, browser, context_id)
  @connection = connection
  @browser = browser
  @id = context_id
end

Instance Method Details

#browserBrowser

Returns:



80
81
82
# File 'lib/puppeteer/browser_context.rb', line 80

def browser
  @browser
end

#closeObject



84
85
86
87
88
89
# File 'lib/puppeteer/browser_context.rb', line 84

def close
  if !@id
    raise 'Non-incognito profiles cannot be closed!'
  end
  @browser.dispose_context(@id)
end

#incognito?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/puppeteer/browser_context.rb', line 33

def incognito?
  !@id
end

#new_pageFuture<Puppeteer::Page>

Returns:



75
76
77
# File 'lib/puppeteer/browser_context.rb', line 75

def new_page
  @browser.create_page_in_context(@id)
end

#pages!Promise<!Array<!Puppeteer.Page>>

Returns:



29
30
31
# File 'lib/puppeteer/browser_context.rb', line 29

def pages
  targets.select { |target| target.type == 'page' }.map(&:page).reject { |page| !page }
end

#targets!Array<!Target>

Returns target.

Returns:

  • (!Array<!Target>)

    target



14
15
16
# File 'lib/puppeteer/browser_context.rb', line 14

def targets
  @browser.targets.select { |target| target.browser_context == self }
end

#wait_for_target(predicate:, timeout: nil) ⇒ !Promise<!Target>

Parameters:

  • predicate (function(!Target):boolean)
  • options ({timeout?: number}=)

Returns:



21
22
23
24
25
26
# File 'lib/puppeteer/browser_context.rb', line 21

def wait_for_target(predicate:, timeout: nil)
  @browser.wait_for_target(
    predicate: ->(target) { target.browser_context == self && predicate.call(target) },
    timeout: timeout,
  )
end