Class: Puppeteer::Extension

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

Overview

rbs_inline: enabled

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, version:, name:, path:, enabled:, browser:) ⇒ Extension

Returns a new instance of Extension.



11
12
13
14
15
16
17
18
# File 'lib/puppeteer/extension.rb', line 11

def initialize(id:, version:, name:, path:, enabled:, browser:)
  @id = id
  @version = version
  @name = name
  @path = path
  @enabled = enabled
  @browser = browser
end

Instance Attribute Details

#enabledObject (readonly)

Returns the value of attribute enabled.



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

def enabled
  @enabled
end

#idObject (readonly)

Returns the value of attribute id.



21
22
23
# File 'lib/puppeteer/extension.rb', line 21

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/puppeteer/extension.rb', line 27

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



30
31
32
# File 'lib/puppeteer/extension.rb', line 30

def path
  @path
end

#versionObject (readonly)

Returns the value of attribute version.



24
25
26
# File 'lib/puppeteer/extension.rb', line 24

def version
  @version
end

Instance Method Details

#pagesObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/puppeteer/extension.rb', line 49

def pages
  extension_prefix = "chrome-extension://#{@id}"
  extension_targets = @browser.targets.select do |target|
    target_url = target.url
    ['page', 'background_page'].include?(target.type) && target_url.start_with?(extension_prefix)
  end
  extension_targets.filter_map do |target|
    target.as_page
  rescue
    nil
  end
end

#trigger_action(page) ⇒ Object



64
65
66
67
68
69
# File 'lib/puppeteer/extension.rb', line 64

def trigger_action(page)
  page.browser.send(:connection).send_message('Extensions.triggerAction', {
    id: @id,
    targetId: page._tab_id,
  })
end

#workersObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/puppeteer/extension.rb', line 36

def workers
  extension_prefix = "chrome-extension://#{@id}"
  extension_targets = @browser.targets.select do |target|
    target.type == 'service_worker' && target.url.start_with?(extension_prefix)
  end
  extension_targets.filter_map do |target|
    target.worker
  rescue
    nil
  end
end