Class: Capybara::Apparition::Browser::PageManager
- Inherits:
-
Object
- Object
- Capybara::Apparition::Browser::PageManager
- Defined in:
- lib/capybara/apparition/browser/page_manager.rb
Instance Method Summary collapse
- #[](id) ⇒ Object
- #blacklist=(list) ⇒ Object
- #create(id, session, ctx_id, **options) ⇒ Object
- #delete(id) ⇒ Object
- #each(&block) ⇒ Object
- #ids ⇒ Object
-
#initialize(browser) ⇒ PageManager
constructor
A new instance of PageManager.
- #refresh(opener:, **page_options) ⇒ Object
- #reset ⇒ Object
- #whitelist=(list) ⇒ Object
Constructor Details
#initialize(browser) ⇒ PageManager
Returns a new instance of PageManager.
6 7 8 9 |
# File 'lib/capybara/apparition/browser/page_manager.rb', line 6 def initialize(browser) @browser = browser @pages = {} end |
Instance Method Details
#[](id) ⇒ Object
15 16 17 |
# File 'lib/capybara/apparition/browser/page_manager.rb', line 15 def [](id) @pages[id] end |
#blacklist=(list) ⇒ Object
85 86 87 |
# File 'lib/capybara/apparition/browser/page_manager.rb', line 85 def blacklist=(list) @pages.each_value { |page| page.url_blacklist = list } end |
#create(id, session, ctx_id, **options) ⇒ Object
37 38 39 |
# File 'lib/capybara/apparition/browser/page_manager.rb', line 37 def create(id, session, ctx_id, **) @pages[id] = Page.create(@browser, session, id, ctx_id, **) end |
#delete(id) ⇒ Object
41 42 43 |
# File 'lib/capybara/apparition/browser/page_manager.rb', line 41 def delete(id) @pages.delete(id) end |
#each(&block) ⇒ Object
19 20 21 |
# File 'lib/capybara/apparition/browser/page_manager.rb', line 19 def each(&block) @pages.each_value(&block) end |
#ids ⇒ Object
11 12 13 |
# File 'lib/capybara/apparition/browser/page_manager.rb', line 11 def ids @pages.keys end |
#refresh(opener:, **page_options) ⇒ Object
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 |
# File 'lib/capybara/apparition/browser/page_manager.rb', line 45 def refresh(opener:, **) new_pages = @browser.command('Target.getTargets')['targetInfos'].select do |ti| (ti['openerId'] == opener.target_id) && (ti['type'] == 'page') && (ti['attached'] == false) end sessions = new_pages.map do |page| target_id = page['targetId'] session_result = @browser.client.send_cmd('Target.attachToTarget', targetId: target_id) [target_id, session_result] end sessions = sessions.map do |(target_id, session_result)| session = Capybara::Apparition::DevToolsProtocol::Session.new( @browser, @browser.client, session_result.result['sessionId'] ) [target_id, session] end sessions.each do |(_id, session)| session.async_commands 'Page.enable', 'Network.enable', 'Runtime.enable', 'Security.enable', 'DOM.enable' end sessions.each do |(target_id, session)| new_page = Page.create( @browser, session, target_id, opener.browser_context_id, ** ).inherit(opener) @pages[target_id] = new_page end end |
#reset ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/capybara/apparition/browser/page_manager.rb', line 23 def reset @pages.each do |id, page| begin @browser.client.send_cmd( 'Target.disposeBrowserContext', browserContextId: page.browser_context_id ).discard_result rescue WrongWorld puts 'Unknown browserContextId' end @pages.delete(id) end end |
#whitelist=(list) ⇒ Object
81 82 83 |
# File 'lib/capybara/apparition/browser/page_manager.rb', line 81 def whitelist=(list) @pages.each_value { |page| page.url_whitelist = list } end |