Module: Obxcura::Frame::DOM
- Included in:
- Obxcura::Frame
- Defined in:
- lib/obxcura/frame/dom.rb
Overview
DOM: high-level reads of the rendered page, all built on Runtime.
Selector queries return live Nodes. Obscura serializes a DOM node over
returnByValue as an internal stub carrying an _nid — useless on its own,
but the _nid resolves (DOM.resolveNode) to a real remote object handle we
wrap in a Node and drive with Runtime#call_on.
Instance Method Summary collapse
-
#at_css(selector) ⇒ Obxcura::Node?
First element matching a CSS selector.
-
#body ⇒ String
(also: #html)
The live, post-JS HTML.
-
#css(selector) ⇒ Array<Obxcura::Node>
All elements matching a CSS selector.
-
#current_url ⇒ String
The current top-window URL.
-
#title ⇒ String
The current document title.
Instance Method Details
#at_css(selector) ⇒ Obxcura::Node?
First element matching a CSS selector.
36 37 38 |
# File 'lib/obxcura/frame/dom.rb', line 36 def at_css(selector) to_node(evaluate_func("function(s) { return document.querySelector(s); }", selector)) end |
#body ⇒ String Also known as: html
The live, post-JS HTML. Retrieved in chunks (see Runtime#read_string)
because a full page's outerHTML routinely exceeds Obscura's message limit.
Aliased as html.
27 28 29 |
# File 'lib/obxcura/frame/dom.rb', line 27 def body read_string("document.documentElement.outerHTML") end |
#css(selector) ⇒ Array<Obxcura::Node>
All elements matching a CSS selector.
44 45 46 47 |
# File 'lib/obxcura/frame/dom.rb', line 44 def css(selector) Array(evaluate_func("function(s) { return Array.from(document.querySelectorAll(s)); }", selector)) .filter_map { |stub| to_node(stub) } end |
#current_url ⇒ String
Returns the current top-window URL.
13 14 15 |
# File 'lib/obxcura/frame/dom.rb', line 13 def current_url evaluate("window.location.href") end |
#title ⇒ String
Returns the current document title.
18 19 20 |
# File 'lib/obxcura/frame/dom.rb', line 18 def title evaluate("document.title") end |