Class: Puppeteer::Bidi::Core::Navigation
- Inherits:
-
EventEmitter
- Object
- EventEmitter
- Puppeteer::Bidi::Core::Navigation
- Includes:
- Disposable::DisposableMixin
- Defined in:
- lib/puppeteer/bidi/core/navigation.rb,
sig/puppeteer/bidi/core/navigation.rbs
Overview
Navigation represents a single navigation operation
Instance Attribute Summary collapse
-
#browsing_context ⇒ Object
readonly
Returns the value of attribute browsing_context.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Class Method Summary collapse
-
.from(browsing_context) ⇒ Navigation
Create a navigation instance.
Instance Method Summary collapse
-
#initialize(browsing_context) ⇒ Navigation
constructor
A new instance of Navigation.
- #initialize_navigation ⇒ Object
- #matches?(navigation_id) ⇒ Boolean
-
#navigation ⇒ Navigation?
Get the nested navigation if any.
- #perform_dispose ⇒ Object
- #session ⇒ Object
Methods included from Disposable::DisposableMixin
Methods inherited from EventEmitter
#dispose, #disposed?, #emit, #off, #on, #once, #remove_all_listeners
Constructor Details
#initialize(browsing_context) ⇒ Navigation
Returns a new instance of Navigation.
22 23 24 25 26 27 28 29 |
# File 'lib/puppeteer/bidi/core/navigation.rb', line 22 def initialize(browsing_context) super() @browsing_context = browsing_context @request = nil @navigation = nil @id = nil @disposables = Disposable::DisposableStack.new end |
Instance Attribute Details
#browsing_context ⇒ Object (readonly)
Returns the value of attribute browsing_context.
20 21 22 |
# File 'lib/puppeteer/bidi/core/navigation.rb', line 20 def browsing_context @browsing_context end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
20 21 22 |
# File 'lib/puppeteer/bidi/core/navigation.rb', line 20 def request @request end |
Class Method Details
.from(browsing_context) ⇒ Navigation
Create a navigation instance
14 15 16 17 18 |
# File 'lib/puppeteer/bidi/core/navigation.rb', line 14 def self.from(browsing_context) = new(browsing_context) .send(:initialize_navigation) end |
Instance Method Details
#initialize_navigation ⇒ Object
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 |
# File 'lib/puppeteer/bidi/core/navigation.rb', line 50 def # Listen for browsing context closure @browsing_context.once(:closed) do emit(:failed, { url: @browsing_context.url, timestamp: Time.now }) dispose end # Listen for requests with navigation ID @browsing_context.on(:request) do |request| next unless request. next unless matches?(request.) @request = request emit(:request, request) # Listen for redirects request.on(:redirect) do |redirect_request| @request = redirect_request end end # Listen for nested navigation session.on('browsingContext.navigationStarted') do |info| next unless info['context'] == @browsing_context.id next if @navigation && !@navigation.disposed? @navigation = Navigation.from(@browsing_context) end # Listen for navigation completion events %w[ browsingContext.domContentLoaded browsingContext.load browsingContext.navigationCommitted ].each do |event_name| session.on(event_name) do |info| next unless info['context'] == @browsing_context.id next if info['navigation'].nil? next unless matches?(info['navigation']) dispose end end # Listen for navigation end events { 'browsingContext.fragmentNavigated' => :fragment, 'browsingContext.navigationFailed' => :failed, 'browsingContext.navigationAborted' => :aborted }.each do |event_name, emit_event| session.on(event_name) do |info| next unless info['context'] == @browsing_context.id next unless matches?(info['navigation']) emit(emit_event, { url: info['url'], timestamp: Time.at(info['timestamp'] / 1000.0) }) dispose end end end |
#matches?(navigation_id) ⇒ Boolean
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/puppeteer/bidi/core/navigation.rb', line 116 def matches?() # If nested navigation exists and is not disposed, this navigation doesn't match return false if @navigation && !@navigation.disposed? # First navigation event sets the ID if @id.nil? @id = return true end # Check if the navigation ID matches @id == end |
#navigation ⇒ Navigation?
Get the nested navigation if any
33 34 35 |
# File 'lib/puppeteer/bidi/core/navigation.rb', line 33 def @navigation end |
#perform_dispose ⇒ Object
39 40 41 42 |
# File 'lib/puppeteer/bidi/core/navigation.rb', line 39 def perform_dispose @disposables.dispose super end |
#session ⇒ Object
46 47 48 |
# File 'lib/puppeteer/bidi/core/navigation.rb', line 46 def session @browsing_context.user_context.browser.session end |