Class: Camoufox::SyncAPI::Page
- Inherits:
-
Object
- Object
- Camoufox::SyncAPI::Page
- Defined in:
- lib/camoufox/sync_api.rb
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #content ⇒ Object
- #goto(url) ⇒ Object
-
#initialize(launch_options) ⇒ Page
constructor
A new instance of Page.
- #on_close(&block) ⇒ Object
- #title ⇒ Object
- #wait_for_selector(selector, **options) ⇒ Object
Constructor Details
#initialize(launch_options) ⇒ Page
Returns a new instance of Page.
41 42 43 44 45 46 47 48 |
# File 'lib/camoufox/sync_api.rb', line 41 def initialize() @launch_options = @session = NodeRunner::Session.new(@launch_options) @title = nil @content = nil @closed = false @on_close = nil end |
Instance Method Details
#close ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/camoufox/sync_api.rb', line 92 def close return if closed? @session.close @closed = true @on_close&.call(self) nil end |
#closed? ⇒ Boolean
101 102 103 |
# File 'lib/camoufox/sync_api.rb', line 101 def closed? @closed end |
#content ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/camoufox/sync_api.rb', line 76 def content ensure_open! @content ||= begin result = @session.request('content') result['content']&.to_s end end |
#goto(url) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/camoufox/sync_api.rb', line 54 def goto(url) ensure_open! result = @session.request('goto', 'url' => url) @title = result['title'] @content = result['content']&.to_s self end |
#on_close(&block) ⇒ Object
50 51 52 |
# File 'lib/camoufox/sync_api.rb', line 50 def on_close(&block) @on_close = block end |
#title ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/camoufox/sync_api.rb', line 84 def title ensure_open! @title ||= begin result = @session.request('title') result['title'] end end |
#wait_for_selector(selector, **options) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/camoufox/sync_api.rb', line 62 def wait_for_selector(selector, **) ensure_open! raise ArgumentError, "selector must be provided" if selector.to_s.empty? = .compact params = { 'selector' => selector } params['options'] = Utils.camelize_hash() unless .empty? @session.request('wait_for_selector', params) @title = nil @content = nil self end |